From 0eb4b0d214c9f3c388be622094cf3b2842f73102 Mon Sep 17 00:00:00 2001 From: Eric Bruneton Date: Tue, 7 Nov 2017 20:50:30 +0100 Subject: [PATCH] Small code improvements related to last pull request merge. - update Code::Blocks project - small Makefile tweaks (sort things alphabetically, 80 columns max) - small code style fixes (sort imports, always use {} in if, field declarations after method declarations, variable declaration as close to variable use as possible, indentation, etc) - improve code style and small optimizations in TextRenderer --- Makefile | 14 +- atmosphere/demo/demo.cc | 24 +- atmosphere/model.cc | 14 +- atmosphere/reference/model_test.cc | 57 ++--- .../{regenerate-glad.sh => regenerate.sh} | 0 precomputed_atmopheric_scattering.cbp | 25 +- text/font.inc | 15 +- text/text_renderer.cc | 232 ++++++++++-------- text/text_renderer.h | 18 +- 9 files changed, 224 insertions(+), 175 deletions(-) rename external/glad/{regenerate-glad.sh => regenerate.sh} (100%) diff --git a/Makefile b/Makefile index c540b4b..bffccbe 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,12 @@ GPP := g++ GPP_FLAGS := -Wall -Wmain -pedantic -pedantic-errors -std=c++11 INCLUDE_FLAGS := \ - -I. -Iexternal/glad/include -Iexternal -Iexternal/dimensional_types -Iexternal/progress_bar + -I. -Iexternal -Iexternal/dimensional_types -Iexternal/glad/include \ + -Iexternal/progress_bar DEBUG_FLAGS := -g RELEASE_FLAGS := -DNDEBUG -O3 -fexpensive-optimizations -DIRS := atmosphere tools text external/glad/src +DIRS := atmosphere text tools HEADERS := $(shell find $(DIRS) -name "*.h") SOURCES := $(shell find $(DIRS) -name "*.cc") GLSL_SOURCES := $(shell find $(DIRS) -name "*.glsl") @@ -49,7 +50,6 @@ all: lint doc test integration_test demo # . lint: $(HEADERS) $(SOURCES) cpplint --exclude=tools/docgen_main.cc \ - --exclude=external/glad/src/glad.cc \ --exclude=atmosphere/reference/functions.h \ --exclude=atmosphere/reference/model_test.cc --root=$(PWD) $^ cpplint --filter=-runtime/references --root=$(PWD) \ @@ -87,21 +87,21 @@ output/Debug/atmosphere_test: \ $(GPP) $^ -o $@ output/Release/atmosphere_integration_test: \ - output/Release/external/glad/src/glad.o \ output/Release/atmosphere/model.o \ output/Release/atmosphere/reference/functions.o \ output/Release/atmosphere/reference/model.o \ output/Release/atmosphere/reference/model_test.o \ output/Release/external/dimensional_types/test/test_main.o \ + output/Release/external/glad/src/glad.o \ output/Release/external/progress_bar/util/progress_bar.o $(GPP) $^ -pthread -ldl -lglut -lGL -o $@ output/Debug/atmosphere_demo: \ - output/Debug/external/glad/src/glad.o \ - output/Debug/text/text_renderer.o \ output/Debug/atmosphere/demo/demo.o \ output/Debug/atmosphere/demo/demo_main.o \ - output/Debug/atmosphere/model.o + output/Debug/atmosphere/model.o \ + output/Debug/text/text_renderer.o \ + output/Debug/external/glad/src/glad.o $(GPP) $^ -pthread -ldl -lglut -lGL -o $@ output/Debug/%.o: %.cc diff --git a/atmosphere/demo/demo.cc b/atmosphere/demo/demo.cc index d63b4e3..afa3204 100644 --- a/atmosphere/demo/demo.cc +++ b/atmosphere/demo/demo.cc @@ -45,10 +45,10 @@ independent of our atmosphere model. The only part which is related to it is the #include #include #include +#include #include #include #include -#include namespace atmosphere { namespace demo { @@ -116,10 +116,12 @@ Demo::Demo(int viewport_width, int viewport_height) : glutInitWindowSize(viewport_width, viewport_height); window_id_ = glutCreateWindow("Atmosphere Demo"); INSTANCES[window_id_] = this; - if (!gladLoadGL()) - throw std::runtime_error("GLAD initialization failed"); - if (!GLAD_GL_VERSION_3_3) - throw std::runtime_error("OpenGL 3.3 or higher is required"); + if (!gladLoadGL()) { + throw std::runtime_error("GLAD initialization failed"); + } + if (!GLAD_GL_VERSION_3_3) { + throw std::runtime_error("OpenGL 3.3 or higher is required"); + } glutDisplayFunc([]() { INSTANCES[glutGetWindow()]->HandleRedisplayEvent(); @@ -145,14 +147,14 @@ Demo::Demo(int viewport_width, int viewport_height) : glGenBuffers(1, &full_screen_quad_vbo_); glBindBuffer(GL_ARRAY_BUFFER, full_screen_quad_vbo_); const GLfloat vertices[] = { - -1.0, -1.0, 0.0, 1.0, - +1.0, -1.0, 0.0, 1.0, - -1.0, +1.0, 0.0, 1.0, - +1.0, +1.0, 0.0, 1.0, + -1.0, -1.0, 0.0, 1.0, + +1.0, -1.0, 0.0, 1.0, + -1.0, +1.0, 0.0, 1.0, + +1.0, +1.0, 0.0, 1.0, }; - constexpr int kCoordsPerVertex = 4; glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); constexpr GLuint kAttribIndex = 0; + constexpr int kCoordsPerVertex = 4; glVertexAttribPointer(kAttribIndex, kCoordsPerVertex, GL_FLOAT, false, 0, 0); glEnableVertexAttribArray(kAttribIndex); glBindVertexArray(0); @@ -407,7 +409,7 @@ void Demo::HandleRedisplayEvent() const { << " +/-: increase/decrease exposure (" << exposure_ << ")\n" << " 1-9: predefined views\n"; text_renderer_->SetColor(1.0, 0.0, 0.0); - text_renderer_->DrawText(help.str().c_str(), 5, 4); + text_renderer_->DrawText(help.str(), 5, 4); } glutSwapBuffers(); diff --git a/atmosphere/model.cc b/atmosphere/model.cc index 17c5f5e..fc8bc94 100644 --- a/atmosphere/model.cc +++ b/atmosphere/model.cc @@ -431,7 +431,7 @@ GLuint NewTexture2d(int width, int height) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); // 16F precision for the transmittance gives artifacts. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, - GL_RGB, GL_FLOAT, NULL); + GL_RGBA, GL_FLOAT, NULL); return texture; } @@ -451,10 +451,10 @@ GLuint NewTexture3d(int width, int height, int depth, GLenum format, (half_precision ? GL_RGBA16F : GL_RGBA32F) : (half_precision ? GL_RGB16F : GL_RGB32F); if (!rgb32f_supported && internal_format == GL_RGB32F) { - internal_format = GL_RGBA32F; + internal_format = GL_RGBA32F; } if (!rgb16f_supported && internal_format == GL_RGB16F) { - internal_format = GL_RGBA16F; + internal_format = GL_RGBA16F; } glTexImage3D(GL_TEXTURE_3D, 0, internal_format, width, height, depth, 0, format, GL_FLOAT, NULL); @@ -763,10 +763,10 @@ Model::Model( glGenBuffers(1, &full_screen_quad_vbo_); glBindBuffer(GL_ARRAY_BUFFER, full_screen_quad_vbo_); const GLfloat vertices[] = { - -1.0, -1.0, - +1.0, -1.0, - -1.0, +1.0, - +1.0, +1.0, + -1.0, -1.0, + +1.0, -1.0, + -1.0, +1.0, + +1.0, +1.0, }; constexpr int kCoordsPerVertex = 2; glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); diff --git a/atmosphere/reference/model_test.cc b/atmosphere/reference/model_test.cc index 92f6e21..4e1a953 100644 --- a/atmosphere/reference/model_test.cc +++ b/atmosphere/reference/model_test.cc @@ -371,10 +371,12 @@ provide a separate method to initialize it: glutInitWindowSize(kWidth, kHeight); glutCreateWindow("ModelTest"); glutHideWindow(); - if (!gladLoadGL()) - throw std::runtime_error("GLAD initialization failed"); - if (!GLAD_GL_VERSION_3_3) - throw std::runtime_error("OpenGL 3.3 or higher is required"); + if (!gladLoadGL()) { + throw std::runtime_error("GLAD initialization failed"); + } + if (!GLAD_GL_VERSION_3_3) { + throw std::runtime_error("OpenGL 3.3 or higher is required"); + } } std::vector wavelengths; @@ -572,30 +574,29 @@ with the GPU program, and then read back the framebuffer pixels. glViewport(0, 0, kWidth, kHeight); { - GLuint full_screen_quad_vao; - glGenVertexArrays(1, &full_screen_quad_vao); - glBindVertexArray(full_screen_quad_vao); - GLuint full_screen_quad_vbo; - glGenBuffers(1, &full_screen_quad_vbo); - glBindBuffer(GL_ARRAY_BUFFER, full_screen_quad_vbo); - const GLfloat vertices[] = { - -1.0, -1.0, 0.0, 1.0, - +1.0, -1.0, 0.0, 1.0, - -1.0, +1.0, 0.0, 1.0, - +1.0, +1.0, 0.0, 1.0, - }; - constexpr int kCoordsPerVertex = 4; - glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, - GL_STATIC_DRAW); - constexpr GLuint kAttribIndex = 0; - glVertexAttribPointer(kAttribIndex, kCoordsPerVertex, GL_FLOAT, - false, 0, 0); - glEnableVertexAttribArray(kAttribIndex); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glDeleteBuffers(1, &full_screen_quad_vbo); - glBindVertexArray(0); - glDeleteVertexArrays(1, &full_screen_quad_vao); + GLuint full_screen_quad_vao; + glGenVertexArrays(1, &full_screen_quad_vao); + glBindVertexArray(full_screen_quad_vao); + GLuint full_screen_quad_vbo; + glGenBuffers(1, &full_screen_quad_vbo); + glBindBuffer(GL_ARRAY_BUFFER, full_screen_quad_vbo); + const GLfloat vertices[] = { + -1.0, -1.0, 0.0, 1.0, + +1.0, -1.0, 0.0, 1.0, + -1.0, +1.0, 0.0, 1.0, + +1.0, +1.0, 0.0, 1.0, + }; + glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); + constexpr GLuint kAttribIndex = 0; + constexpr int kCoordsPerVertex = 4; + glVertexAttribPointer(kAttribIndex, kCoordsPerVertex, GL_FLOAT, + false, 0, 0); + glEnableVertexAttribArray(kAttribIndex); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &full_screen_quad_vbo); + glBindVertexArray(0); + glDeleteVertexArrays(1, &full_screen_quad_vao); } glutSwapBuffers(); diff --git a/external/glad/regenerate-glad.sh b/external/glad/regenerate.sh similarity index 100% rename from external/glad/regenerate-glad.sh rename to external/glad/regenerate.sh diff --git a/precomputed_atmopheric_scattering.cbp b/precomputed_atmopheric_scattering.cbp index 33b60cb..d8ce904 100644 --- a/precomputed_atmopheric_scattering.cbp +++ b/precomputed_atmopheric_scattering.cbp @@ -64,11 +64,12 @@ + - + @@ -184,6 +185,16 @@