Skip to content

Commit

Permalink
More OpenGL cleanup (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Aug 27, 2020
1 parent 1880578 commit 1402da6
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 397 deletions.
25 changes: 12 additions & 13 deletions apps/ysceneview/ysceneview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ struct app_state {
string name = "";

// options
gui_scene_params drawgl_prms = {};
shade_params drawgl_prms = {};

// scene
sceneio_scene* ioscene = new sceneio_scene{};
sceneio_camera* iocamera = nullptr;

// rendering state
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;
shade_scene* glscene = new shade_scene{};
shade_camera* glcamera = nullptr;

// editing
sceneio_camera* selected_camera = nullptr;
Expand Down Expand Up @@ -97,7 +97,7 @@ struct app_states {
std::deque<app_state*> loading = {};

// default options
gui_scene_params drawgl_prms = {};
shade_params drawgl_prms = {};

// cleanup
~app_states() {
Expand Down Expand Up @@ -129,8 +129,8 @@ void load_scene_async(
if (!apps->selected) apps->selected = app;
}

void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
gui_camera*& glcamera, sceneio_camera* iocamera,
void init_glscene(shade_scene* glscene, sceneio_scene* ioscene,
shade_camera*& glcamera, sceneio_camera* iocamera,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{
Expand All @@ -142,7 +142,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
init_scene(glscene);

// camera
auto camera_map = unordered_map<sceneio_camera*, gui_camera*>{};
auto camera_map = unordered_map<sceneio_camera*, shade_camera*>{};
camera_map[nullptr] = nullptr;
for (auto iocamera : ioscene->cameras) {
if (progress_cb) progress_cb("convert camera", progress.x++, progress.y);
Expand All @@ -154,7 +154,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// textures
auto texture_map = unordered_map<sceneio_texture*, gui_texture*>{};
auto texture_map = unordered_map<sceneio_texture*, shade_texture*>{};
texture_map[nullptr] = nullptr;
for (auto iotexture : ioscene->textures) {
if (progress_cb) progress_cb("convert texture", progress.x++, progress.y);
Expand All @@ -168,7 +168,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// material
auto material_map = unordered_map<sceneio_material*, gui_material*>{};
auto material_map = unordered_map<sceneio_material*, shade_material*>{};
material_map[nullptr] = nullptr;
for (auto iomaterial : ioscene->materials) {
if (progress_cb) progress_cb("convert material", progress.x++, progress.y);
Expand All @@ -192,7 +192,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// shapes
auto shape_map = unordered_map<sceneio_shape*, gui_shape*>{};
auto shape_map = unordered_map<sceneio_shape*, shade_shape*>{};
shape_map[nullptr] = nullptr;
for (auto ioshape : ioscene->shapes) {
if (progress_cb) progress_cb("convert shape", progress.x++, progress.y);
Expand Down Expand Up @@ -425,11 +425,10 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
}
auto& params = app->drawgl_prms;
draw_slider(win, "resolution", params.resolution, 0, 4096);
draw_combobox(win, "lighting", (int&)params.lighting, gui_lighting_names);
draw_combobox(win, "lighting", (int&)params.lighting, shade_lighting_names);
draw_checkbox(win, "wireframe", params.wireframe);
continue_line(win);
draw_checkbox(win, "faceted", params.faceted);
// draw_checkbox(win, "edges", params.edges);
continue_line(win);
draw_checkbox(win, "double sided", params.double_sided);
draw_slider(win, "exposure", params.exposure, -10, 10);
Expand Down Expand Up @@ -604,7 +603,7 @@ int main(int argc, const char* argv[]) {
add_option(cli, "--resolution,-r", apps->drawgl_prms.resolution,
"Image resolution.");
add_option(cli, "--lighting", apps->drawgl_prms.lighting, "Lighting type.",
gui_lighting_names);
shade_lighting_names);
add_option(cli, "scenes", filenames, "Scene filenames", true);
parse_cli(cli, argc, argv);

Expand Down
22 changes: 11 additions & 11 deletions apps/ysceneviews/ysceneviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ struct app_state {
string name = "";

// options
gui_scene_params drawgl_prms = {};
shade_params drawgl_prms = {};

// scene
sceneio_scene* ioscene = new sceneio_scene{};
sceneio_camera* iocamera = nullptr;

// rendering state
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;
shade_scene* glscene = new shade_scene{};
shade_camera* glcamera = nullptr;

// editing
sceneio_camera* selected_camera = nullptr;
Expand All @@ -90,8 +90,8 @@ struct app_state {
}
};

void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
gui_camera*& glcamera, sceneio_camera* iocamera,
void init_glscene(shade_scene* glscene, sceneio_scene* ioscene,
shade_camera*& glcamera, sceneio_camera* iocamera,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{
Expand All @@ -103,7 +103,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
init_scene(glscene);

// camera
auto camera_map = unordered_map<sceneio_camera*, gui_camera*>{};
auto camera_map = unordered_map<sceneio_camera*, shade_camera*>{};
camera_map[nullptr] = nullptr;
for (auto iocamera : ioscene->cameras) {
if (progress_cb) progress_cb("convert camera", progress.x++, progress.y);
Expand All @@ -115,7 +115,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// textures
auto texture_map = unordered_map<sceneio_texture*, gui_texture*>{};
auto texture_map = unordered_map<sceneio_texture*, shade_texture*>{};
texture_map[nullptr] = nullptr;
for (auto iotexture : ioscene->textures) {
if (progress_cb) progress_cb("convert texture", progress.x++, progress.y);
Expand All @@ -129,7 +129,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// material
auto material_map = unordered_map<sceneio_material*, gui_material*>{};
auto material_map = unordered_map<sceneio_material*, shade_material*>{};
material_map[nullptr] = nullptr;
for (auto iomaterial : ioscene->materials) {
if (progress_cb) progress_cb("convert material", progress.x++, progress.y);
Expand All @@ -153,7 +153,7 @@ void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
}

// shapes
auto shape_map = unordered_map<sceneio_shape*, gui_shape*>{};
auto shape_map = unordered_map<sceneio_shape*, shade_shape*>{};
shape_map[nullptr] = nullptr;
for (auto ioshape : ioscene->shapes) {
if (progress_cb) progress_cb("convert shape", progress.x++, progress.y);
Expand Down Expand Up @@ -202,7 +202,7 @@ int main(int argc, const char* argv[]) {
add_option(
cli, "--resolution,-r", app->drawgl_prms.resolution, "Image resolution.");
add_option(cli, "--lighting", app->drawgl_prms.lighting, "Lighting type.",
gui_lighting_names);
shade_lighting_names);
add_option(cli, "scene", app->filename, "Scene filename", true);
parse_cli(cli, argc, argv);

Expand Down Expand Up @@ -249,7 +249,7 @@ int main(int argc, const char* argv[]) {
draw_checkbox(win, "faceted", params.faceted);
continue_line(win);
draw_checkbox(win, "double sided", params.double_sided);
draw_combobox(win, "lighting", (int&)params.lighting, gui_lighting_names);
draw_combobox(win, "lighting", (int&)params.lighting, shade_lighting_names);
// draw_checkbox(win, "edges", params.edges);
draw_slider(win, "exposure", params.exposure, -10, 10);
draw_slider(win, "gamma", params.gamma, 0.1f, 4);
Expand Down
41 changes: 13 additions & 28 deletions apps/yshapeview/yshapeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ struct app_state {
string name = "";

// options
gui_scene_params drawgl_prms = {};
shade_params drawgl_prms = {};

// scene
generic_shape* ioshape = new generic_shape{};

// rendering state
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;
shade_scene* glscene = new shade_scene{};
shade_camera* glcamera = nullptr;

// loading status
std::atomic<bool> ok = false;
Expand All @@ -88,7 +88,7 @@ struct app_states {
std::deque<app_state*> loading = {};

// default options
gui_scene_params drawgl_prms = {};
shade_params drawgl_prms = {};

// cleanup
~app_states() {
Expand Down Expand Up @@ -169,7 +169,7 @@ quads_shape make_cylinders(const vector<vec2i>& lines,

const char* draw_instanced_vertex_code();

void init_glscene(app_state* app, gui_scene* glscene, generic_shape* ioshape,
void init_glscene(app_state* app, shade_scene* glscene, generic_shape* ioshape,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{0, 4};
Expand All @@ -195,6 +195,8 @@ void init_glscene(app_state* app, gui_scene* glscene, generic_shape* ioshape,
auto glmaterial = add_material(glscene, {0, 0, 0}, {0.5, 1, 0.5}, 1, 0, 0.2);
auto glmateriale = add_material(glscene, {0, 0, 0}, {0, 0, 0}, 0, 0, 1);
auto glmaterialv = add_material(glscene, {0, 0, 0}, {0, 0, 0}, 0, 0, 1);
set_unlit(glmateriale, true);
set_unlit(glmaterialv, true);

// shapes
if (progress_cb) progress_cb("convert shape", progress.x++, progress.y);
Expand Down Expand Up @@ -240,33 +242,16 @@ void init_glscene(app_state* app, gui_scene* glscene, generic_shape* ioshape,

// shapes
if (progress_cb) progress_cb("convert instance", progress.x++, progress.y);

add_instance(glscene, identity3x4f, model_shape, glmaterial);

auto edges_instance = add_instance(
glscene, identity3x4f, edges_shape, glmateriale, true);
edges_instance->shading = gui_shading_type::constant;

auto points_instance = add_instance(
glscene, identity3x4f, vertices_shape, glmaterialv, true);
points_instance->shading = gui_shading_type::constant;
add_instance(glscene, identity3x4f, edges_shape, glmateriale, true);
add_instance(glscene, identity3x4f, vertices_shape, glmaterialv, true);

// override eyelight vertex shader
auto vert = draw_instanced_vertex_code();
auto frag = draw_instances_eyelight_fragment_code();
init_program(glscene->camlight_program, vert, frag);
set_program(glscene->camlight_program, draw_instanced_vertex_code(),
draw_instances_eyelight_fragment_code());

// done
if (progress_cb) progress_cb("convert done", progress.x++, progress.y);

// init_program(glscene->ibl_program, vertex_source,
// draw_instances_ibl_fragment_code(), error, errorb);

// auto img = image<vec4f>{};
// load_image("apps/yshapeview/env.hdr", img, error);
// auto texture = new ogl_texture{};
// set_texture(texture, img, true, true, true);
// init_ibl_data(glscene, texture, {1, 1, 1});
}

// draw with shading
Expand Down Expand Up @@ -319,7 +304,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
draw_checkbox(win, "points", app->glscene->instances[2]->hidden, true);
draw_coloredit(win, "color", glmaterial->color);
draw_slider(win, "resolution", params.resolution, 0, 4096);
draw_combobox(win, "lighting", (int&)params.lighting, gui_lighting_names);
draw_combobox(win, "lighting", (int&)params.lighting, shade_lighting_names);
draw_checkbox(win, "wireframe", params.wireframe);
continue_line(win);
draw_checkbox(win, "double sided", params.double_sided);
Expand Down Expand Up @@ -401,7 +386,7 @@ int main(int argc, const char* argv[]) {
add_option(cli, "--resolution,-r", apps->drawgl_prms.resolution,
"Image resolution.");
add_option(cli, "--lighting", apps->drawgl_prms.lighting, "Lighting type.",
gui_lighting_names);
shade_lighting_names);
add_option(cli, "shapes", filenames, "Shape filenames", true);
parse_cli(cli, argc, argv);

Expand Down
Loading

0 comments on commit 1402da6

Please sign in to comment.