Skip to content

Commit 40ae509

Browse files
committed
Hackily implement oit
1 parent 178c9c7 commit 40ae509

File tree

10 files changed

+321
-151
lines changed

10 files changed

+321
-151
lines changed

libopensimcreator/Graphics/OpenSimGraphicsHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SceneRendererParams osc::CalcSceneRendererParams(
6060
rv.dimensions = viewportDims;
6161
}
6262
rv.device_pixel_ratio = viewportDevicePixelRatio;
63-
rv.antialiasing_level = antiAliasingLevel;
63+
rv.anti_aliasing_level = antiAliasingLevel;
6464
rv.light_direction = recommended_light_direction(renderParams.camera);
6565
renderParams.renderingOptions.applyTo(rv);
6666
rv.view_matrix = renderParams.camera.view_matrix();

libopensimcreator/UI/MeshImporter/MeshImporterSharedState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ namespace osc::mi
444444
SceneRendererParams p;
445445
p.dimensions = get3DSceneDims();
446446
p.device_pixel_ratio = app.settings().get_value<float>("graphics/render_scale", 1.0f) * app.main_window_device_pixel_ratio();
447-
p.antialiasing_level = app.anti_aliasing_level();
447+
p.anti_aliasing_level = app.anti_aliasing_level();
448448
p.draw_rims = true;
449449
p.draw_floor = false;
450450
p.near_clipping_plane = m_3DSceneCamera.znear;

libopensimcreator/UI/SplashTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class osc::SplashTab::Impl final : public TabPrivate {
197197
SceneRendererParams params{m_LastSceneRendererParams};
198198
params.dimensions = workspaceUIRect.dimensions();
199199
params.device_pixel_ratio = App::settings().get_value<float>("graphics/render_scale", 1.0f) * App::get().main_window_device_pixel_ratio(),
200-
params.antialiasing_level = App::get().anti_aliasing_level();
200+
params.anti_aliasing_level = App::get().anti_aliasing_level();
201201
params.projection_matrix = m_Camera.projection_matrix(aspect_ratio_of(workspaceUIRect));
202202

203203
if (params != m_LastSceneRendererParams) {

liboscar-demos/MeshGenTestTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class osc::MeshGenTestTab::Impl final : public TabPrivate {
104104
const Vector2 viewport_dimensions = viewport_ui_rect.dimensions();
105105
render_params_.dimensions = elementwise_max(viewport_dimensions, {0.0f, 0.0f});
106106
render_params_.device_pixel_ratio = App::settings().get_value<float>("graphics/render_scale", 1.0f) * App::get().main_window_device_pixel_ratio(),
107-
render_params_.antialiasing_level = App::get().anti_aliasing_level();
107+
render_params_.anti_aliasing_level = App::get().anti_aliasing_level();
108108
render_params_.light_direction = recommended_light_direction(camera_);
109109
render_params_.projection_matrix = camera_.projection_matrix(aspect_ratio_of(render_params_.dimensions));
110110
render_params_.view_matrix = camera_.view_matrix();

liboscar/Graphics/GraphicsImplementation.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ std::ostream& osc::operator<<(std::ostream& o, const RenderTextureParams& params
20232023
"RenderTextureParams(width = " << params.pixel_dimensions.x
20242024
<< ", height = " << params.pixel_dimensions.y
20252025
<< ", device_pixel_ratio = " << params.device_pixel_ratio
2026-
<< ", antialiasing_level = " << params.anti_aliasing_level
2026+
<< ", anti_aliasing_level = " << params.anti_aliasing_level
20272027
<< ", color_format = " << params.color_format
20282028
<< ", depth_stencil_format = " << params.depth_stencil_format
20292029
<< ")";
@@ -3428,6 +3428,9 @@ class osc::Material::Impl final {
34283428
DepthFunction depth_function() const { return depth_function_; }
34293429
void set_depth_function(DepthFunction depth_function) { depth_function_ = depth_function; }
34303430

3431+
bool writes_to_depth_buffer() const { return writes_to_depth_buffer_; }
3432+
void set_writes_to_depth_buffer(bool value) { writes_to_depth_buffer_ = value; }
3433+
34313434
bool is_wireframe() const { return is_wireframe_mode_; }
34323435
void set_wireframe(bool value) { is_wireframe_mode_ = value; }
34333436

@@ -3446,6 +3449,7 @@ class osc::Material::Impl final {
34463449
BlendingEquation blending_equation_ = BlendingEquation::Default;
34473450
bool is_transparent_ = false;
34483451
bool is_depth_tested_ = true;
3452+
bool writes_to_depth_buffer_ = true;
34493453
bool is_wireframe_mode_ = false;
34503454
};
34513455

@@ -3518,6 +3522,16 @@ void osc::Material::set_depth_function(DepthFunction depth_function)
35183522
impl_.upd()->set_depth_function(depth_function);
35193523
}
35203524

3525+
bool osc::Material::writes_to_depth_buffer() const
3526+
{
3527+
return impl_->writes_to_depth_buffer();
3528+
}
3529+
3530+
void osc::Material::set_writes_to_depth_buffer(bool value)
3531+
{
3532+
impl_.upd()->set_writes_to_depth_buffer(value);
3533+
}
3534+
35213535
bool osc::Material::is_wireframe() const
35223536
{
35233537
return impl_->is_wireframe();
@@ -7346,6 +7360,10 @@ void osc::GraphicsBackend::handle_batch_with_same_material(
73467360
glDepthFunc(to_opengl_depth_function_enum(material_impl.depth_function()));
73477361
}
73487362

7363+
if (not material_impl.writes_to_depth_buffer()) {
7364+
glDepthMask(GL_FALSE);
7365+
}
7366+
73497367
if (material_impl.cull_mode() != CullMode::Off) {
73507368
glEnable(GL_CULL_FACE);
73517369
glCullFace(to_opengl_cull_face_enum(material_impl.cull_mode()));
@@ -7403,6 +7421,10 @@ void osc::GraphicsBackend::handle_batch_with_same_material(
74037421
glDisable(GL_CULL_FACE);
74047422
}
74057423

7424+
if (not material_impl.writes_to_depth_buffer()) {
7425+
glDepthMask(GL_TRUE); // Khronos: "Initially, depth buffer writing is enabled"
7426+
}
7427+
74067428
if (material_impl.depth_function() != DepthFunction::Default) {
74077429
glDepthFunc(to_opengl_depth_function_enum(DepthFunction::Default));
74087430
}

liboscar/Graphics/Material.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ namespace osc
8080
DepthFunction depth_function() const;
8181
void set_depth_function(DepthFunction);
8282

83+
bool writes_to_depth_buffer() const;
84+
void set_writes_to_depth_buffer(bool);
85+
8386
bool is_wireframe() const;
8487
void set_wireframe(bool);
8588

liboscar/Graphics/Material.tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ TEST_F(MaterialTest, MaterialGetDepthFunctionIsInitiallyDefault)
730730
ASSERT_EQ(material.depth_function(), DepthFunction::Default);
731731
}
732732

733+
TEST_F(MaterialTest, MaterialWritesToDepthBufferIsInitiallyTrue)
734+
{
735+
const Material material = generate_material();
736+
ASSERT_TRUE(material.writes_to_depth_buffer());
737+
}
738+
739+
TEST_F(MaterialTest, MaterialSetWritesToDepthBufferChangesWritesToDepthBuffer)
740+
{
741+
Material material = generate_material();
742+
ASSERT_TRUE(material.writes_to_depth_buffer());
743+
material.set_writes_to_depth_buffer(false);
744+
ASSERT_FALSE(material.writes_to_depth_buffer());
745+
material.set_writes_to_depth_buffer(true);
746+
ASSERT_TRUE(material.writes_to_depth_buffer());
747+
}
748+
733749
TEST_F(MaterialTest, MaterialSetDepthFunctionBehavesAsExpected)
734750
{
735751
Material material = generate_material();

liboscar/Graphics/Scene/SceneHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ SceneRendererParams osc::calc_standard_dark_scene_render_params(
336336
return SceneRendererParams{
337337
.dimensions = dimensions,
338338
.device_pixel_ratio = device_pixel_ratio,
339-
.antialiasing_level = aa_level,
339+
.anti_aliasing_level = aa_level,
340340
.draw_mesh_normals = false,
341341
.draw_floor = false,
342342
.near_clipping_plane = camera.znear,

0 commit comments

Comments
 (0)