summaryrefslogtreecommitdiff
path: root/drivers/gles2
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-04-30 17:20:05 +0200
committerGitHub <noreply@github.com>2019-04-30 17:20:05 +0200
commita5c619dc8dc8a488599c3b08314ddb69e0ed445e (patch)
treef3a4e8494f735cd76cda26d8a9da56652ac6e957 /drivers/gles2
parent9dc9434b1bcde48259fa68066a7a3e2cff5d5eab (diff)
parent7ae3809f4b40785b5e06589458932fc83aa59680 (diff)
Merge pull request #28520 from clayjohn/GLES2-alpha-draw-order
Fixed GLES2 transparency order
Diffstat (limited to 'drivers/gles2')
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp2
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h26
2 files changed, 26 insertions, 2 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 9f1425189c..99eb0665d6 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -2845,7 +2845,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- render_list.sort_by_depth(true);
+ render_list.sort_by_reverse_depth_and_priority(true);
_render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, reverse_cull, true, false);
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index f23e45b52f..48672991d1 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -502,7 +502,8 @@ public:
enum {
MAX_LIGHTS = 255,
MAX_REFLECTION_PROBES = 255,
- DEFAULT_MAX_ELEMENTS = 65536
+ DEFAULT_MAX_ELEMENTS = 65536,
+ SORT_KEY_PRIORITY_SHIFT = 56
};
int max_elements;
@@ -598,6 +599,29 @@ public:
}
}
+ struct SortByReverseDepthAndPriority {
+
+ _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
+ 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_and_priority(bool p_alpha) { //used for alpha
+
+ SortArray<Element *, SortByReverseDepthAndPriority> sorter;
+ if (p_alpha) {
+ sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
+ } else {
+ sorter.sort(elements, element_count);
+ }
+ }
+
// element adding and stuff
_FORCE_INLINE_ Element *add_element() {