diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-09-01 12:56:52 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-09-01 13:01:08 -0300 |
commit | 8f30c52a3751586edab6d7482425075aef8de6e3 (patch) | |
tree | ce113d16f4e1a6da82e08ac5a9eaaa99c26dae0b /drivers/gles3 | |
parent | 6e9e25b41d33745f65910fa077c9049ddccb3445 (diff) |
Removed ontop property, added a material rendering priority system. Fixes #9935, closes #10135
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 14 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.h | 40 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 15 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 6 |
4 files changed, 53 insertions, 22 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 07b0bac70d..cbb05befb6 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1100,15 +1100,15 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m state.current_line_width = p_material->line_width; } - if (state.current_depth_test != (!p_material->shader->spatial.ontop)) { - if (p_material->shader->spatial.ontop) { + if (state.current_depth_test != (!p_material->shader->spatial.no_depth_test)) { + if (p_material->shader->spatial.no_depth_test) { glDisable(GL_DEPTH_TEST); } else { glEnable(GL_DEPTH_TEST); } - state.current_depth_test = !p_material->shader->spatial.ontop; + state.current_depth_test = !p_material->shader->spatial.no_depth_test; } if (state.current_depth_draw != p_material->shader->spatial.depth_draw_mode) { @@ -2195,7 +2195,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, RasterizerStorageGLES3::Material *p_material, bool p_shadow) { bool has_base_alpha = (p_material->shader->spatial.uses_alpha && !p_material->shader->spatial.uses_alpha_scissor) || p_material->shader->spatial.uses_screen_texture; - bool has_blend_alpha = p_material->shader->spatial.blend_mode != RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX || p_material->shader->spatial.ontop; + bool has_blend_alpha = p_material->shader->spatial.blend_mode != RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX; bool has_alpha = has_base_alpha || has_blend_alpha; bool shadow = false; @@ -2267,7 +2267,7 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G } e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT; - e->sort_key |= uint64_t(e->instance->depth_layer) << RenderList::SORT_KEY_DEPTH_LAYER_SHIFT; + e->sort_key |= uint64_t(e->instance->depth_layer) << RenderList::SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT; if (!has_blend_alpha && has_alpha && p_material->shader->spatial.depth_draw_mode == RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { @@ -2283,6 +2283,8 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G if (e->instance->gi_probe_instances.size()) { e->sort_key |= SORT_KEY_GI_PROBES_FLAG; } + + e->sort_key |= uint64_t(p_material->render_priority + 128) << RenderList::SORT_KEY_PRIORITY_SHIFT; } /* @@ -4282,7 +4284,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const glEnable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); - render_list.sort_by_reverse_depth(true); + render_list.sort_by_reverse_depth_and_priority(true); if (state.directional_light_count == 0) { directional_light = NULL; diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 659408b455..b6291b03fd 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -645,17 +645,25 @@ public: MAX_LIGHTS = 4096, MAX_REFLECTIONS = 1024, - SORT_KEY_DEPTH_LAYER_SHIFT = 60, + SORT_KEY_PRIORITY_SHIFT = 56, + SORT_KEY_PRIORITY_MASK = 0xFF, + //depth layer for opaque (56-52) + SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT = 52, + SORT_KEY_OPAQUE_DEPTH_LAYER_MASK = 0xF, //64 bits unsupported in MSVC -#define SORT_KEY_UNSHADED_FLAG (uint64_t(1) << 59) -#define SORT_KEY_NO_DIRECTIONAL_FLAG (uint64_t(1) << 58) -#define SORT_KEY_GI_PROBES_FLAG (uint64_t(1) << 57) -#define SORT_KEY_VERTEX_LIT_FLAG (uint64_t(1) << 56) - SORT_KEY_SHADING_SHIFT = 56, +#define SORT_KEY_UNSHADED_FLAG (uint64_t(1) << 51) +#define SORT_KEY_NO_DIRECTIONAL_FLAG (uint64_t(1) << 50) +#define SORT_KEY_GI_PROBES_FLAG (uint64_t(1) << 49) +#define SORT_KEY_VERTEX_LIT_FLAG (uint64_t(1) << 48) + SORT_KEY_SHADING_SHIFT = 48, SORT_KEY_SHADING_MASK = 15, - SORT_KEY_MATERIAL_INDEX_SHIFT = 40, - SORT_KEY_GEOMETRY_INDEX_SHIFT = 20, - SORT_KEY_GEOMETRY_TYPE_SHIFT = 15, + //48-32 material index + SORT_KEY_MATERIAL_INDEX_SHIFT = 32, + //32-12 geometry index + SORT_KEY_GEOMETRY_INDEX_SHIFT = 12, + //bits 12-8 geometry type + SORT_KEY_GEOMETRY_TYPE_SHIFT = 8, + //bits 0-7 for flags SORT_KEY_CULL_DISABLED_FLAG = 4, SORT_KEY_SKELETON_FLAG = 2, SORT_KEY_MIRROR_FLAG = 1 @@ -721,16 +729,22 @@ public: } } - struct SortByReverseDepth { + struct SortByReverseDepthAndPriority { _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { - return A->instance->depth > B->instance->depth; + uint32_t layer_A = uint32_t(A->sort_key >> SORT_KEY_PRIORITY_SHIFT); + uint32_t layer_B = uint32_t(B->sort_key >> SORT_KEY_PRIORITY_SHIFT); + if (layer_A == layer_B) { + return A->instance->depth > B->instance->depth; + } else { + return layer_A < layer_B; + } } }; - void sort_by_reverse_depth(bool p_alpha) { //used for alpha + void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha - SortArray<Element *, SortByReverseDepth> sorter; + SortArray<Element *, SortByReverseDepthAndPriority> sorter; if (p_alpha) { sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count); } else { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a66a3d020b..91ba3aa702 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -1599,7 +1599,7 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { p_shader->spatial.uses_alpha_scissor = false; p_shader->spatial.uses_discard = false; p_shader->spatial.unshaded = false; - p_shader->spatial.ontop = false; + p_shader->spatial.no_depth_test = false; p_shader->spatial.uses_sss = false; p_shader->spatial.uses_vertex_lighting = false; p_shader->spatial.uses_screen_texture = false; @@ -1621,7 +1621,7 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { shaders.actions_scene.render_mode_values["cull_disabled"] = Pair<int *, int>(&p_shader->spatial.cull_mode, Shader::Spatial::CULL_MODE_DISABLED); shaders.actions_scene.render_mode_flags["unshaded"] = &p_shader->spatial.unshaded; - shaders.actions_scene.render_mode_flags["ontop"] = &p_shader->spatial.ontop; + shaders.actions_scene.render_mode_flags["depth_test_disable"] = &p_shader->spatial.no_depth_test; shaders.actions_scene.render_mode_flags["vertex_lighting"] = &p_shader->spatial.uses_vertex_lighting; @@ -1948,6 +1948,17 @@ void RasterizerStorageGLES3::material_remove_instance_owner(RID p_material, Rast } } +void RasterizerStorageGLES3::material_set_render_priority(RID p_material, int priority) { + + ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN); + ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX); + + Material *material = material_owner.get(p_material); + ERR_FAIL_COND(!material); + + material->render_priority = priority; +} + _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataType type, const Variant &value, uint8_t *data, bool p_linear_color) { switch (type) { case ShaderLanguage::TYPE_BOOL: { diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index c74b127b23..f75b77aabe 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -444,7 +444,7 @@ public: bool uses_alpha; bool uses_alpha_scissor; bool unshaded; - bool ontop; + bool no_depth_test; bool uses_vertex; bool uses_discard; bool uses_sss; @@ -502,6 +502,7 @@ public: SelfList<Material> dirty_list; Vector<RID> textures; float line_width; + int render_priority; RID next_pass; @@ -523,6 +524,7 @@ public: ubo_id = 0; ubo_size = 0; last_pass = 0; + render_priority = 0; } }; @@ -550,6 +552,8 @@ public: virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance); virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance); + virtual void material_set_render_priority(RID p_material, int priority); + void _update_material(Material *material); void update_dirty_materials(); |