Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint fixes to OpenGL #1046

Merged
merged 3 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions libs/yocto_gui/yocto_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include <yocto/yocto_commonio.h>

#include <array>

#include "ext/glad/glad.h"

#ifdef _WIN32
Expand All @@ -44,6 +46,7 @@
namespace yocto {

// using directives
using std::array;
using namespace std::string_literals;

} // namespace yocto
Expand Down Expand Up @@ -145,13 +148,13 @@ gui_scene::~gui_scene() {
delete brdf_lut;
}

const char* bake_brdf_vertex_code();
const char* bake_brdf_fragment_code();
static const char* bake_brdf_vertex_code();
static const char* bake_brdf_fragment_code();

const char* bake_cubemap_vertex_code();
const char* bake_environment_fragment_code();
const char* bake_irradiance_fragment_code();
const char* bake_reflections_fragment_code();
static const char* bake_cubemap_vertex_code();
static const char* bake_environment_fragment_code();
static const char* bake_irradiance_fragment_code();
static const char* bake_reflections_fragment_code();

// Initialize an OpenGL scene
void init_scene(gui_scene* scene) {
Expand Down Expand Up @@ -507,21 +510,19 @@ inline void bake_cubemap(ogl_cubemap* cubemap, const Sampler* environment,
const vec3f& emission = {1, 1, 1}) {
// init cubemap with no data
set_cubemap<float>(cubemap, size, 3, true, true, true);
auto cube = cube_shape();
auto cube = cube_shape(); // TODO(fabio): this is dangerous

auto framebuffer = ogl_framebuffer{};
set_framebuffer(&framebuffer, {size, size});

// clang-format off
frame3f cameras[6] = {
lookat_frame({0, 0, 0}, { 1, 0, 0}, {0, 1, 0}),
lookat_frame({0, 0, 0}, {-1, 0, 0}, {0, 1, 0}),
lookat_frame({0, 0, 0}, { 0,-1, 0}, {0, 0,-1}),
lookat_frame({0, 0, 0}, { 0, 1, 0}, {0, 0, 1}),
lookat_frame({0, 0, 0}, { 0, 0,-1}, {0, 1, 0}),
lookat_frame({0, 0, 0}, { 0, 0, 1}, {0, 1, 0})
auto cameras = array<frame3f, 6>{
lookat_frame({0, 0, 0}, {1, 0, 0}, {0, 1, 0}),
lookat_frame({0, 0, 0}, {-1, 0, 0}, {0, 1, 0}),
lookat_frame({0, 0, 0}, {0, -1, 0}, {0, 0, -1}),
lookat_frame({0, 0, 0}, {0, 1, 0}, {0, 0, 1}),
lookat_frame({0, 0, 0}, {0, 0, -1}, {0, 1, 0}),
lookat_frame({0, 0, 0}, {0, 0, 1}, {0, 1, 0}),
};
// clang-format on

bind_framebuffer(&framebuffer);
bind_program(program);
Expand Down Expand Up @@ -551,12 +552,13 @@ inline void bake_cubemap(ogl_cubemap* cubemap, const Sampler* environment,
}
unbind_program();
unbind_framebuffer();
// TODO:(fabio): shoudl we clear the framebuffer here?
}

inline void bake_specular_brdf_texture(gui_texture* texture) {
auto size = 512;
auto framebuffer = ogl_framebuffer{};
auto screen_quad = quad_shape();
auto screen_quad = quad_shape(); // THIS is DANGEROUS

auto program = ogl_program{};
auto error = ""s, errorlog = ""s;
Expand Down Expand Up @@ -608,6 +610,7 @@ void init_ibl_data(gui_scene* scene, const gui_texture* environment_texture,
if (!init_program(program, vertex, fragment, error, errorlog)) {
printf("error: %s\n", error.c_str());
printf("errorlog: %s\n", errorlog.c_str());
// TODO(fabio): this shoudl return an error
}
};

Expand Down Expand Up @@ -1115,7 +1118,7 @@ void main() {
return code;
}

const char* bake_brdf_vertex_code() {
static const char* bake_brdf_vertex_code() {
static const char* code = R"(
#version 330
Expand All @@ -1133,7 +1136,7 @@ void main() {
return code;
}

const char* bake_brdf_fragment_code() {
static const char* bake_brdf_fragment_code() {
static const char* code = R"(
#version 330
Expand Down Expand Up @@ -1241,7 +1244,7 @@ void main() {
return code;
}

const char* bake_cubemap_vertex_code() {
static const char* bake_cubemap_vertex_code() {
static const char* code = R"(
#version 330
Expand All @@ -1266,7 +1269,7 @@ void main() {
return code;
}

const char* bake_environment_fragment_code() {
static const char* bake_environment_fragment_code() {
static const char* code = R"(
#version 330
Expand Down Expand Up @@ -1302,7 +1305,7 @@ void main() {
return code;
}

const char* bake_irradiance_fragment_code() {
static const char* bake_irradiance_fragment_code() {
static const char* code = R"(
#version 330
Expand Down Expand Up @@ -1354,7 +1357,7 @@ void main() {
return code;
}

const char* bake_reflections_fragment_code() {
static const char* bake_reflections_fragment_code() {
static const char* code = R"(
#version 330
Expand Down
3 changes: 3 additions & 0 deletions libs/yocto_gui/yocto_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
// INCLUDES
// -----------------------------------------------------------------------------

#include <string>
#include <vector>

#include "yocto_opengl.h"

// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libs/yocto_gui/yocto_opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ inline void set_index_buffer(ogl_shape* shape, const vector<vec3i>& indices) {

void draw_shape(const ogl_shape* shape);

// TODO(fabio) these should chanhe to initialization and avoid static GL data
ogl_shape* cube_shape();
ogl_shape* quad_shape();

Expand Down