Quick (and dirty) change to be able to use OpenMP for rendering.
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
# To simplify testing, the app is build in two passes,
|
# To simplify testing, the app is build in two passes,
|
||||||
|
option(USE_OPENMP "Build using OpenMP" OFF)
|
||||||
|
|
||||||
|
if (USE_OPENMP)
|
||||||
|
find_package(OpenMP REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
# First most is build as a library
|
# First most is build as a library
|
||||||
add_library(rayonnement STATIC)
|
add_library(rayonnement STATIC)
|
||||||
@@ -11,7 +16,9 @@ file(GLOB RAY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_D
|
|||||||
target_include_directories(rayonnement PUBLIC include pattern)
|
target_include_directories(rayonnement PUBLIC include pattern)
|
||||||
target_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES})
|
target_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES})
|
||||||
target_link_libraries(rayonnement LodePNG)
|
target_link_libraries(rayonnement LodePNG)
|
||||||
|
if (USE_OPENMP)
|
||||||
|
target_link_libraries(rayonnement OpenMP::OpenMP_CXX)
|
||||||
|
endif()
|
||||||
# Second we build the main executable
|
# Second we build the main executable
|
||||||
add_executable(dorayme main.cpp)
|
add_executable(dorayme main.cpp)
|
||||||
target_include_directories(rayonnement PUBLIC include ${LODEPNG_INCLUDE_FOLDER})
|
target_include_directories(rayonnement PUBLIC include ${LODEPNG_INCLUDE_FOLDER})
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
#include <camera.h>
|
#include <camera.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
Camera::Camera(uint32_t hsize, uint32_t vsize, double fov) : verticalSize(vsize), horizontalSize(hsize), fieldOfView(fov)
|
Camera::Camera(uint32_t hsize, uint32_t vsize, double fov) : verticalSize(vsize), horizontalSize(hsize), fieldOfView(fov)
|
||||||
{
|
{
|
||||||
double aspectRatio = (double)hsize / (double)vsize;
|
double aspectRatio = (double)hsize / (double)vsize;
|
||||||
@@ -62,6 +64,7 @@ Canvas Camera::render(World world, uint32_t depth)
|
|||||||
|
|
||||||
for(y = 0; y < this->verticalSize; y++)
|
for(y = 0; y < this->verticalSize; y++)
|
||||||
{
|
{
|
||||||
|
#pragma omp parallel for
|
||||||
for(x = 0; x < this->horizontalSize; x++)
|
for(x = 0; x < this->horizontalSize; x++)
|
||||||
{
|
{
|
||||||
Ray r = this->rayForPixel(x, y);
|
Ray r = this->rayForPixel(x, y);
|
||||||
|
|||||||
Reference in New Issue
Block a user