Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-08-17 19:08:47 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-08-18 22:30:10 +0300
commit536c2e0ec916eb49c534b4937b36da278dbe2364 (patch)
tree87f955824a41094dfd9e4e015c776b86832ea22e
parent482a51aabf596ca1f279ab3b7cb3170c867b4a42 (diff)
GPUState: Only apply state before drawing
-rw-r--r--source/blender/gpu/intern/gpu_batch.cc2
-rw-r--r--source/blender/gpu/intern/gpu_framebuffer.cc7
-rw-r--r--source/blender/gpu/intern/gpu_immediate.cc2
-rw-r--r--source/blender/gpu/intern/gpu_state.cc16
-rw-r--r--source/blender/gpu/intern/gpu_state_private.hh6
-rw-r--r--source/blender/gpu/opengl/gl_batch.cc2
-rw-r--r--source/blender/gpu/opengl/gl_state.cc3
7 files changed, 20 insertions, 18 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc
index 6ea82cbc4f1..36f60c3dcc8 100644
--- a/source/blender/gpu/intern/gpu_batch.cc
+++ b/source/blender/gpu/intern/gpu_batch.cc
@@ -282,6 +282,8 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
/* just draw some vertices and let shader place them where we want. */
void GPU_draw_primitive(GPUPrimType prim_type, int v_count)
{
+ GPU_context_active_get()->state_manager->apply_state();
+
/* we cannot draw without vao ... annoying ... */
glBindVertexArray(GPU_vao_default());
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index 4c7f13a58eb..a94212969b9 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -622,6 +622,8 @@ void GPU_framebuffer_clear(GPUFrameBuffer *fb,
{
CHECK_FRAMEBUFFER_IS_BOUND(fb);
+ GPU_context_active_get()->state_manager->apply_state();
+
if (buffers & GPU_COLOR_BIT) {
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(clear_col[0], clear_col[1], clear_col[2], clear_col[3]);
@@ -786,6 +788,8 @@ void GPU_framebuffer_blit(GPUFrameBuffer *fb_read,
GLbitfield mask = convert_buffer_bits_to_gl(blit_buffers);
+ GPU_context_active_get()->state_manager->apply_state();
+
glBlitFramebuffer(0,
0,
fb_read->width,
@@ -1043,6 +1047,8 @@ void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
const int w = GPU_texture_width(ofs->color);
const int h = GPU_texture_height(ofs->color);
+ GPU_context_active_get()->state_manager->apply_state();
+
GPUFrameBuffer *ofs_fb = gpu_offscreen_fb_get(ofs);
glBindFramebuffer(GL_READ_FRAMEBUFFER, ofs_fb->object);
@@ -1107,6 +1113,7 @@ void GPU_clear_depth(float depth)
void GPU_clear(eGPUFrameBufferBits flags)
{
+ GPU_context_active_get()->state_manager->apply_state();
glClear(convert_buffer_bits_to_gl(flags));
}
diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc
index ed2950d8ee9..dd05689d69a 100644
--- a/source/blender/gpu/intern/gpu_immediate.cc
+++ b/source/blender/gpu/intern/gpu_immediate.cc
@@ -210,6 +210,8 @@ static bool vertex_count_makes_sense_for_primitive(uint vertex_len, GPUPrimType
void immBegin(GPUPrimType prim_type, uint vertex_len)
{
+ GPU_context_active_get()->state_manager->apply_state();
+
#if TRUST_NO_ONE
assert(initialized);
assert(imm.prim_type == GPU_PRIM_NONE); /* make sure we haven't already begun */
diff --git a/source/blender/gpu/intern/gpu_state.cc b/source/blender/gpu/intern/gpu_state.cc
index bd581f06462..039bce1f0ac 100644
--- a/source/blender/gpu/intern/gpu_state.cc
+++ b/source/blender/gpu/intern/gpu_state.cc
@@ -45,8 +45,6 @@ using namespace blender::gpu;
GPUStateManager *stack = GPU_context_active_get()->state_manager; \
auto &state_object = stack->_prefix##state; \
state_object._state = _value; \
- /* TODO remove this and only push state at draw time. */ \
- stack->set_##_prefix##state(state_object); \
} while (0)
#define SET_IMMUTABLE_STATE(_state, _value) SET_STATE(, _state, _value)
@@ -112,8 +110,6 @@ void GPU_color_mask(bool r, bool g, bool b, bool a)
SET_FLAG_FROM_TEST(write_mask, b, GPU_WRITE_BLUE);
SET_FLAG_FROM_TEST(write_mask, a, GPU_WRITE_ALPHA);
state.write_mask = write_mask;
- /* TODO remove this and only push state at draw time. */
- stack->set_state(state);
}
void GPU_depth_mask(bool depth)
@@ -123,8 +119,6 @@ void GPU_depth_mask(bool depth)
eGPUWriteMask write_mask = state.write_mask;
SET_FLAG_FROM_TEST(write_mask, depth, GPU_WRITE_DEPTH);
state.write_mask = write_mask;
- /* TODO remove this and only push state at draw time. */
- stack->set_state(state);
}
void GPU_clip_distances(int distances_enabled)
@@ -143,8 +137,6 @@ void GPU_depth_range(float near, float far)
GPUStateManager *stack = GPU_context_active_get()->state_manager;
auto &state = stack->mutable_state;
copy_v2_fl2(state.depth_range, near, far);
- /* TODO remove this and only push state at draw time. */
- stack->set_mutable_state(state);
}
void GPU_line_width(float width)
@@ -167,8 +159,6 @@ void GPU_program_point_size(bool enable)
auto &state = stack->mutable_state;
/* Set point size sign negative to disable. */
state.point_size = fabsf(state.point_size) * (enable ? 1 : -1);
- /* TODO remove this and only push state at draw time. */
- stack->set_mutable_state(state);
}
void GPU_scissor_test(bool enable)
@@ -177,8 +167,6 @@ void GPU_scissor_test(bool enable)
auto &state = stack->mutable_state;
/* Set point size sign negative to disable. */
state.scissor_rect[2] = abs(state.scissor_rect[2]) * (enable ? 1 : -1);
- /* TODO remove this and only push state at draw time. */
- stack->set_mutable_state(state);
}
void GPU_scissor(int x, int y, int width, int height)
@@ -187,8 +175,6 @@ void GPU_scissor(int x, int y, int width, int height)
auto &state = stack->mutable_state;
int scissor_rect[4] = {x, y, width, height};
copy_v4_v4_int(state.scissor_rect, scissor_rect);
- /* TODO remove this and only push state at draw time. */
- stack->set_mutable_state(state);
}
void GPU_viewport(int x, int y, int width, int height)
@@ -197,8 +183,6 @@ void GPU_viewport(int x, int y, int width, int height)
auto &state = stack->mutable_state;
int viewport_rect[4] = {x, y, width, height};
copy_v4_v4_int(state.viewport_rect, viewport_rect);
- /* TODO remove this and only push state at draw time. */
- stack->set_mutable_state(state);
}
/** \} */
diff --git a/source/blender/gpu/intern/gpu_state_private.hh b/source/blender/gpu/intern/gpu_state_private.hh
index 4326c3a73e5..3324cf6934f 100644
--- a/source/blender/gpu/intern/gpu_state_private.hh
+++ b/source/blender/gpu/intern/gpu_state_private.hh
@@ -138,6 +138,12 @@ class GPUStateManager {
virtual void set_state(const GPUState &state) = 0;
virtual void set_mutable_state(const GPUStateMutable &state) = 0;
+
+ inline void apply_state(void)
+ {
+ this->set_state(this->state);
+ this->set_mutable_state(this->mutable_state);
+ };
};
} // namespace gpu
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
index f1cbb2c10d5..fade8763065 100644
--- a/source/blender/gpu/opengl/gl_batch.cc
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -300,6 +300,8 @@ GLBatch::~GLBatch()
void GLBatch::bind(int i_first)
{
+ GPU_context_active_get()->state_manager->apply_state();
+
if (flag & GPU_BATCH_DIRTY) {
vao_cache_.clear();
}
diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc
index f4360f51527..5274a86ebe5 100644
--- a/source/blender/gpu/opengl/gl_state.cc
+++ b/source/blender/gpu/opengl/gl_state.cc
@@ -102,9 +102,8 @@ void GLStateManager::set_mutable_state(const GPUStateMutable &state)
if ((changed.scissor_rect[0] != 0) || (changed.scissor_rect[1] != 0) ||
(changed.scissor_rect[2] != 0) || (changed.scissor_rect[3] != 0)) {
- glScissor(UNPACK4(state.scissor_rect));
-
if ((state.scissor_rect[2] > 0)) {
+ glScissor(UNPACK4(state.scissor_rect));
glEnable(GL_SCISSOR_TEST);
}
else {