Skip to content

Commit

Permalink
Small code improvements related to last pull request merge.
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ebruneton committed Nov 7, 2017
1 parent abf6c79 commit 0eb4b0d
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 175 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -49,7 +50,6 @@ all: lint doc test integration_test demo
# <regex>.
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) \
Expand Down Expand Up @@ -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
Expand Down
24 changes: 13 additions & 11 deletions atmosphere/demo/demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ independent of our atmosphere model. The only part which is related to it is the
#include <algorithm>
#include <cmath>
#include <map>
#include <stdexcept>
#include <sstream>
#include <string>
#include <vector>
#include <stdexcept>

namespace atmosphere {
namespace demo {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions atmosphere/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
57 changes: 29 additions & 28 deletions atmosphere/reference/model_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> wavelengths;
Expand Down Expand Up @@ -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();

Expand Down
File renamed without changes.
25 changes: 24 additions & 1 deletion precomputed_atmopheric_scattering.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@
<Add option="-std=c++11" />
<Add directory="external" />
<Add directory="external/dimensional_types" />
<Add directory="external/glad/include" />
<Add directory="external/progress_bar" />
</Compiler>
<Linker>
<Add option="-pthread" />
<Add library="GLEW" />
<Add library="dl" />
<Add library="glut" />
<Add library="GL" />
</Linker>
Expand Down Expand Up @@ -184,6 +185,16 @@
<Option target="Test" />
<Option target="IntegrationTest" />
</Unit>
<Unit filename="external/glad/include/glad/glad.h">
<Option target="Debug" />
<Option target="Release" />
<Option target="IntegrationTest" />
</Unit>
<Unit filename="external/glad/src/glad.cc">
<Option target="Debug" />
<Option target="Release" />
<Option target="IntegrationTest" />
</Unit>
<Unit filename="external/minpng/minpng.h">
<Option target="IntegrationTest" />
</Unit>
Expand All @@ -194,6 +205,18 @@
<Option target="IntegrationTest" />
</Unit>
<Unit filename="index" />
<Unit filename="text/font.inc">
<Option target="Debug" />
<Option target="Release" />
</Unit>
<Unit filename="text/text_renderer.cc">
<Option target="Debug" />
<Option target="Release" />
</Unit>
<Unit filename="text/text_renderer.h">
<Option target="Debug" />
<Option target="Release" />
</Unit>
<Unit filename="tools/docgen_main.cc">
<Option target="Docgen" />
</Unit>
Expand Down
15 changes: 7 additions & 8 deletions text/font.inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

#include <vector>
static struct Font
{
int charWidth;
int charHeight;
int atlasWidth;
int atlasHeight;

static struct Font {
int char_width;
int char_height;
int atlas_width;
int atlas_height;
std::vector<GLubyte> data;
} font={9, 15, 144, 90, {
} font = {9, 15, 144, 90, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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