added shader
This commit is contained in:
parent
126ef4ace8
commit
edf4d9fd60
|
|
@ -5,6 +5,8 @@ project ("cuda-raytracer" LANGUAGES CUDA CXX C)
|
|||
# get the shader files in the build directory
|
||||
file(COPY ${CMAKE_SOURCE_DIR}/src/gui/shaders DESTINATION .)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# source files
|
||||
file(GLOB_RECURSE SOURCE_FILES
|
||||
${CMAKE_SOURCE_DIR}/src/*.c
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "Shader.h"
|
||||
|
||||
Window::Window(unsigned int w, unsigned int h) {
|
||||
Window::w = w;
|
||||
Window::h = h;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int w, int h) {
|
||||
|
|
@ -16,7 +18,7 @@ void framebuffer_size_callback(GLFWwindow* window, int w, int h) {
|
|||
|
||||
}
|
||||
|
||||
int Window::init() {
|
||||
int Window::init(float* data) {
|
||||
// init glfw
|
||||
glfwInit();
|
||||
// requesting context version 1.0 makes glfw try to provide the latest version if possible
|
||||
|
|
@ -25,7 +27,7 @@ int Window::init() {
|
|||
|
||||
this->window = glfwCreateWindow(this->w, this->h, "CUDA ray tracing", NULL, NULL);
|
||||
|
||||
//hide cursor
|
||||
//hide cursor // TODO: switch from this style input to something more resembling an actual gui
|
||||
glfwSetInputMode(this->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
glfwSetWindowUserPointer(this->window, reinterpret_cast<void*>(this));
|
||||
|
||||
|
|
@ -37,20 +39,17 @@ int Window::init() {
|
|||
|
||||
glfwMakeContextCurrent(this->window);
|
||||
|
||||
|
||||
// init glad(opengl)
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
std::cout << "Failed to initialize GLAD\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// init framebuffer
|
||||
glViewport(0, 0, this->w, this->h);
|
||||
if (glfwSetFramebufferSizeCallback(this->window, framebuffer_size_callback) != 0) return -1;
|
||||
|
||||
|
||||
if (init_quad()) return -1;
|
||||
if (init_quad(data)) return -1;
|
||||
this->last_frame = std::chrono::steady_clock::now();
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
|
|
@ -62,11 +61,14 @@ int Window::init() {
|
|||
}
|
||||
|
||||
|
||||
int Window::init_quad() {
|
||||
int Window::init_quad(float* data) {
|
||||
this->current_quad = std::make_unique<Quad>(this->w, this->h);
|
||||
this->current_quad->cuda_init();
|
||||
this->current_quad->cuda_init(data);
|
||||
this->current_quad->make_fbo();
|
||||
|
||||
this->shader = std::make_unique<Shader>("./shaders/vertshader.glsl", "./shaders/fragshader.glsl");
|
||||
this->shader->use();
|
||||
|
||||
// TODO: default shaders
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +109,7 @@ void Window::tick() {
|
|||
// render frame
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, this->current_quad->fb);
|
||||
this->current_quad->render();
|
||||
this->shader->use();
|
||||
glBindVertexArray(this->current_quad->VAO);
|
||||
glBindTexture(GL_TEXTURE_2D, this->current_quad->tex);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6); // draw current frame to texture
|
||||
|
|
@ -116,6 +119,8 @@ void Window::tick() {
|
|||
glfwSwapBuffers(this->window);
|
||||
glfwPollEvents();
|
||||
|
||||
std::cout << "done ticking";
|
||||
|
||||
}
|
||||
|
||||
void Window::resize(unsigned int w, unsigned int h) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include "Quad.h"
|
||||
#include "Shader.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <chrono>
|
||||
|
|
@ -11,10 +12,11 @@ class Window {
|
|||
public:
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
float* data; //TODO: dynamic data loading
|
||||
|
||||
Window(unsigned int w, unsigned int h);
|
||||
|
||||
int init();
|
||||
int init(float* data);
|
||||
void free();
|
||||
void resize(unsigned int w, unsigned int h);
|
||||
|
||||
|
|
@ -25,8 +27,8 @@ private:
|
|||
std::chrono::steady_clock::time_point last_frame;
|
||||
|
||||
void tick();
|
||||
int init_quad();
|
||||
int init_quad(float* data);
|
||||
|
||||
// std::unique_ptr<Shader> shader;
|
||||
std::unique_ptr<Shader> shader;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -61,13 +61,14 @@ Quad::Quad(unsigned int w, unsigned int h) {
|
|||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
// register the FBO
|
||||
};
|
||||
|
||||
void Quad::make_fbo(){
|
||||
glGenFramebuffers(1, &fb);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->tex, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Quad::~Quad() {
|
||||
int res = cudaGraphicsUnregisterResource(CGR);
|
||||
|
|
@ -79,14 +80,14 @@ Quad::~Quad() {
|
|||
};
|
||||
|
||||
|
||||
void Quad::cuda_init() {
|
||||
void Quad::cuda_init(float* data) {
|
||||
int res = cudaGraphicsGLRegisterBuffer(&this->CGR, this->PBO, cudaGraphicsRegisterFlagsNone);
|
||||
if (res) {
|
||||
std::cout << "CUDA error while registering the graphics resource: " << res;
|
||||
cudaDeviceReset();
|
||||
exit(1);
|
||||
}
|
||||
this->renderer = std::make_unique<Raycaster>(this->CGR, this->w, this->h);
|
||||
this->renderer = std::make_unique<Raycaster>(this->CGR, this->w, this->h, data);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ public:
|
|||
|
||||
void render();
|
||||
void resize(unsigned int w, unsigned int h);
|
||||
void cuda_init();
|
||||
void cuda_init(float* data);
|
||||
void make_fbo();
|
||||
|
||||
};
|
||||
#endif // QUAD_H
|
||||
|
|
|
|||
|
|
@ -0,0 +1,126 @@
|
|||
// Shader class nicked from learnOpengl here: https://learnopengl.com/Getting-started/Shaders
|
||||
// which is published under the CC BY-NC 4.0 license (and thus fine to use here)
|
||||
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
unsigned int ID;
|
||||
// constructor generates the shader on the fly
|
||||
// ------------------------------------------------------------------------
|
||||
Shader(const char* vertexPath, const char* fragmentPath)
|
||||
{
|
||||
// 1. retrieve the vertex/fragment source code from filePath
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::ifstream vShaderFile;
|
||||
std::ifstream fShaderFile;
|
||||
// ensure ifstream objects can throw exceptions:
|
||||
vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
|
||||
fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
|
||||
try
|
||||
{
|
||||
// open files
|
||||
vShaderFile.open(vertexPath);
|
||||
fShaderFile.open(fragmentPath);
|
||||
std::stringstream vShaderStream, fShaderStream;
|
||||
// read file's buffer contents into streams
|
||||
vShaderStream << vShaderFile.rdbuf();
|
||||
fShaderStream << fShaderFile.rdbuf();
|
||||
// close file handlers
|
||||
vShaderFile.close();
|
||||
fShaderFile.close();
|
||||
// convert stream into string
|
||||
vertexCode = vShaderStream.str();
|
||||
fragmentCode = fShaderStream.str();
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ: " << e.what() << std::endl;
|
||||
}
|
||||
const char* vShaderCode = vertexCode.c_str();
|
||||
const char * fShaderCode = fragmentCode.c_str();
|
||||
// 2. compile shaders
|
||||
unsigned int vertex, fragment;
|
||||
// vertex shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glCompileShader(vertex);
|
||||
checkCompileErrors(vertex, "VERTEX");
|
||||
// fragment Shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
checkCompileErrors(fragment, "FRAGMENT");
|
||||
// shader Program
|
||||
ID = glCreateProgram();
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
glLinkProgram(ID);
|
||||
checkCompileErrors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and no longer necessary
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
}
|
||||
// activate the shader
|
||||
// ------------------------------------------------------------------------
|
||||
void use()
|
||||
{
|
||||
glUseProgram(ID);
|
||||
}
|
||||
// utility uniform functions
|
||||
// ------------------------------------------------------------------------
|
||||
void setBool(const std::string &name, bool value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setInt(const std::string &name, int value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setFloat(const std::string &name, float value) const
|
||||
{
|
||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
|
||||
private:
|
||||
// utility function for checking shader compilation/linking errors.
|
||||
// ------------------------------------------------------------------------
|
||||
void checkCompileErrors(unsigned int shader, std::string type)
|
||||
{
|
||||
int success;
|
||||
char infoLog[1024];
|
||||
if (type != "PROGRAM")
|
||||
{
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glGetProgramiv(shader, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D currentFrameTex;
|
||||
uniform sampler2D lastFrameTex;
|
||||
uniform int frameCount;
|
||||
|
||||
#define MAX_FRAMES 500.0f
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = texture(currentFrameTex, TexCoords).rgb;
|
||||
vec3 col2 = texture(lastFrameTex, TexCoords).rgb;
|
||||
|
||||
col = mix(col, col2, min(frameCount/MAX_FRAMES,1.0f));
|
||||
FragColor = vec4(col, 1.0);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#version 330 core
|
||||
layout(location = 0) in vec2 aPos;
|
||||
layout(location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
#include "linalg/linalg.h"
|
||||
|
||||
|
||||
__host__ FrameBuffer::FrameBuffer(unsigned int w, unsigned int h) : w(w), h(h) {}
|
||||
__host__ FrameBuffer::FrameBuffer(unsigned int w, unsigned int h) : w(w), h(h) {
|
||||
this->buffer_size = w*h*4;
|
||||
}
|
||||
|
||||
|
||||
__device__ void FrameBuffer::writePixel(int x, int y, float r, float g, float b) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
class FrameBuffer {
|
||||
public:
|
||||
uint32_t* buffer;
|
||||
unsigned int* buffer;
|
||||
std::size_t buffer_size;
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "objs/sphere.h"
|
||||
|
||||
|
||||
// TODO: instead of IMAGEWIDTH and IMAGEHEIGHT this should reflect the windowSize;
|
||||
__global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer) {
|
||||
int px = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int py = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
|
@ -127,12 +128,13 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer) {
|
|||
}
|
||||
|
||||
|
||||
Raycaster::Raycaster(cudaGraphicsResource_t resources, int w, int h) {
|
||||
Raycaster::Raycaster(cudaGraphicsResource_t resources, int w, int h, float* data) {
|
||||
this->resources = resources;
|
||||
this->w = h;
|
||||
this->w = h;
|
||||
|
||||
this->fb = new FrameBuffer(w, h);
|
||||
this->data = data;
|
||||
|
||||
// camera_info = CameraInfo(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), 90.0f, (float) w, (float) h);
|
||||
// d_camera = thrust::device_new<Camera*>();
|
||||
|
|
@ -154,15 +156,14 @@ Raycaster::Raycaster(cudaGraphicsResource_t resources, int w, int h) {
|
|||
|
||||
|
||||
void Raycaster::render() {
|
||||
int res = cudaGraphicsMapresources(1, this->resources);
|
||||
int res = cudaGraphicsMapResources(1, &this->resources);
|
||||
if (res) {
|
||||
std::cout << "CUDA error while mapping graphic resource: " << res;
|
||||
cudaDeviceReset();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// check_cuda_errors(cudaGraphicsResourceGetMappedPointer((void**)&(frame_buffer->device_ptr), &(frame_buffer->buffer_size), resources));
|
||||
res = cudaGraphicsResourceGetMappedPointer((void**)(this->fb->buffer), &this->fb->buffer_size, this->resources);
|
||||
res = cudaGraphicsResourceGetMappedPointer((void**)&(this->fb->buffer), &(this->fb->buffer_size), resources);
|
||||
if (res) {
|
||||
std::cout << "CUDA error while fetching resource pointer: " << res;
|
||||
cudaDeviceReset();
|
||||
|
|
@ -177,13 +178,12 @@ void Raycaster::render() {
|
|||
dim3 threads(tx, ty);
|
||||
|
||||
// TODO: pass camera info at some point
|
||||
// TODO: pass float volume data.
|
||||
// frame buffer is implicitly copied to the device each frame
|
||||
raycastKernel<<<blocks, threads>>> (nullptr, this->fb);
|
||||
raycastKernel<<<blocks, threads>>> (this->data, *this->fb);
|
||||
|
||||
res = cudaGetLastError();
|
||||
if (res) {
|
||||
std::cout << "CUDA error while raycasting: " << res;
|
||||
cudaError_t err = cudaGetLastError();
|
||||
if (err) {
|
||||
std::cout << "CUDA error while raycasting: " << cudaGetErrorString(err);
|
||||
cudaDeviceReset();
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,17 +17,17 @@ struct Raycaster {
|
|||
|
||||
cudaGraphicsResource_t resources;
|
||||
FrameBuffer* fb;
|
||||
float* data;
|
||||
|
||||
int w;
|
||||
int h;
|
||||
|
||||
Raycaster() {};
|
||||
Raycaster(cudaGraphicsResource_t resources, int nx, int ny);
|
||||
|
||||
Raycaster(cudaGraphicsResource_t resources, int nx, int ny, float* data);
|
||||
// ~Raycaster();
|
||||
|
||||
void set_camera(Vec3 position, Vec3 forward, Vec3 up);
|
||||
void render();
|
||||
void resize(int nx, int ny);
|
||||
// void raycastKernel(float* volumeData, unsigned char* framebuffer); // TODO: proper framebuffer class
|
||||
};
|
||||
#endif // RAYCASTER_H
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ __device__ unsigned int packUnorm4x8(float r, float g, float b, float a) {
|
|||
uint out;
|
||||
} u;
|
||||
|
||||
double len = sqrt(r*r + g*g + b*b + a*a);
|
||||
float len = sqrtf(r*r + g*g + b*b + a*a);
|
||||
|
||||
// This is a Vec4 but i can't be bothered to make that its own struct/class; FIXME: maybe do that if we need to?
|
||||
std::vector<float> v{r/len, g/len, b/len, a/len};
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
u.in[i] = round(std::clamp(v[i], 0.0f, 1.0f) * 255.0f);
|
||||
}
|
||||
u.in[0] = round(r/len * 255.0f);
|
||||
u.in[1] = round(g/len * 255.0f);
|
||||
u.in[2] = round(b/len * 255.0f);
|
||||
u.in[3] = round(a/len * 255.0f);
|
||||
|
||||
return u.out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
#include "gui/MainWindow.h"
|
||||
#include "consts.h"
|
||||
|
||||
|
||||
int main() {
|
||||
Window window(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
return window.init();
|
||||
}
|
||||
63
src/main.cu
63
src/main.cu
|
|
@ -1,15 +1,15 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
#include <cuda_runtime.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "hurricanedata/datareader.h"
|
||||
#include "linalg/linalg.h"
|
||||
#include "img/handler.h"
|
||||
#include <cmath>
|
||||
#include "consts.h"
|
||||
#include <cuda_runtime.h>
|
||||
#include <fstream>
|
||||
#include "gui/MainWindow.h"
|
||||
#include "hurricanedata/datareader.h"
|
||||
#include "illumination/illumination.h"
|
||||
#include "img/handler.h"
|
||||
#include <iostream>
|
||||
#include "linalg/linalg.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
static float* d_volume = nullptr;
|
||||
|
|
@ -45,8 +45,8 @@ void getSpeed(std::vector<float>& speedData, int idx = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: incorporate this main into main.cpp
|
||||
int unmain(int argc, char** argv) {
|
||||
|
||||
int main() {
|
||||
std::vector<float> data;
|
||||
// getTemperature(data);
|
||||
getSpeed(data);
|
||||
|
|
@ -75,15 +75,15 @@ int unmain(int argc, char** argv) {
|
|||
cudaMemcpy(d_volume, hostVolume, volumeSize, cudaMemcpyHostToDevice);
|
||||
|
||||
// Allocate framebuffer
|
||||
unsigned char* d_framebuffer;
|
||||
size_t fbSize = IMAGE_WIDTH * IMAGE_HEIGHT * 3 * sizeof(unsigned char);
|
||||
cudaMalloc((void**)&d_framebuffer, fbSize);
|
||||
cudaMemset(d_framebuffer, 0, fbSize);
|
||||
// unsigned char* d_framebuffer;
|
||||
// size_t fbSize = IMAGE_WIDTH * IMAGE_HEIGHT * 3 * sizeof(unsigned char);
|
||||
// cudaMalloc((void**)&d_framebuffer, fbSize);
|
||||
// cudaMemset(d_framebuffer, 0, fbSize);
|
||||
|
||||
// Copy external constants from consts.h to cuda
|
||||
copyConstantsToDevice();
|
||||
|
||||
// NOTE: this shold be done within the rayTracer class
|
||||
// NOTE: this is done within the rayTracer class
|
||||
// // Launch kernel
|
||||
// dim3 blockSize(16, 16);
|
||||
// dim3 gridSize((IMAGE_WIDTH + blockSize.x - 1)/blockSize.x,
|
||||
|
|
@ -95,19 +95,22 @@ int unmain(int argc, char** argv) {
|
|||
// );
|
||||
// cudaDeviceSynchronize();
|
||||
|
||||
// Copy framebuffer back to CPU
|
||||
unsigned char* hostFramebuffer = new unsigned char[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
|
||||
cudaMemcpy(hostFramebuffer, d_framebuffer, fbSize, cudaMemcpyDeviceToHost);
|
||||
Window window(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
return window.init(d_volume);
|
||||
|
||||
// Export image
|
||||
saveImage("output.ppm", hostFramebuffer, IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
|
||||
// Cleanup
|
||||
delete[] hostVolume;
|
||||
delete[] hostFramebuffer;
|
||||
cudaFree(d_volume);
|
||||
cudaFree(d_framebuffer);
|
||||
|
||||
std::cout << "Phong-DVR rendering done. Image saved to output.ppm" << std::endl;
|
||||
return 0;
|
||||
// // Copy framebuffer back to CPU
|
||||
// unsigned char* hostFramebuffer = new unsigned char[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
|
||||
// cudaMemcpy(hostFramebuffer, d_framebuffer, fbSize, cudaMemcpyDeviceToHost);
|
||||
//
|
||||
// // Export image
|
||||
// saveImage("output.ppm", hostFramebuffer, IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
//
|
||||
// // Cleanup //TODO: cleanup properly
|
||||
// delete[] hostVolume;
|
||||
// delete[] hostFramebuffer;
|
||||
// cudaFree(d_volume);
|
||||
// cudaFree(d_framebuffer);
|
||||
//
|
||||
// std::cout << "Phong-DVR rendering done. Image saved to output.ppm" << std::endl;
|
||||
// return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue