Optimize color changing with OpenMP.

This commit is contained in:
Nicolás Ortega Froysa 2018-10-25 23:00:26 +02:00
parent 766a2d597c
commit e1f7cbaa1d
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
3 changed files with 4 additions and 2 deletions

View File

@ -39,6 +39,7 @@ set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED) find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
find_package(OpenMP REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2 REQUIRED sdl2) pkg_search_module(SDL2 REQUIRED sdl2)
@ -54,7 +55,7 @@ set(SRCS
"src/simulation.cpp") "src/simulation.cpp")
# Define C++ compiler flags # Define C++ compiler flags
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wpedantic -Wfatal-errors -Werror -pedantic-errors -fno-elide-constructors") set(CMAKE_CXX_FLAGS "-std=c++11 ${OpenMP_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wfatal-errors -Werror -pedantic-errors -fno-elide-constructors")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3")

View File

@ -84,6 +84,7 @@ void cube::render() {
} }
void cube::shift_colors() { void cube::shift_colors() {
#pragma omp parallel for
for(size_t i = 0; i < colors.size(); ++i) for(size_t i = 0; i < colors.size(); ++i)
{ {
colors[i] += color_ascending[i] ? color_shift : colors[i] += color_ascending[i] ? color_shift :

View File

@ -36,7 +36,7 @@ public:
void render(); void render();
private: private:
const float color_shift = 0.0001; const float color_shift = 0.005;
void shift_colors(); void shift_colors();
// OpenGL buffers // OpenGL buffers