diff options
author | mano-wii <germano.costa@ig.com.br> | 2019-03-15 22:02:55 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2019-03-15 23:02:48 +0300 |
commit | 681661dbed121c7b81e9129c57df5eadb03c1009 (patch) | |
tree | 8802195c72af13e1bb7324131024cc98fb5971a7 /source/blender/gpu | |
parent | 4510f88d00a721a3d4ad3aa675050723eec2292c (diff) |
GPU: Simplify select shaders.
The shaders are: `GPU_SHADER_3D_FLAT_SELECT_ID` and `GPU_SHADER_3D_UNIFORM_SELECT_ID`.
This commit allows the drawing of the mesh select ids to be done on a 32UI format texture.
This simplifies the shader that previously acted on the backbuffer and had to do an uint to rgba conversion.
Differential Revision: https://developer.blender.org/D4350
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_draw.h | 5 | ||||
-rw-r--r-- | source/blender/gpu/GPU_extensions.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 142 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 12 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl | 8 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl | 12 |
6 files changed, 4 insertions, 176 deletions
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index f9ea9a35084..ce9a20bcf7c 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -99,11 +99,6 @@ void GPU_create_smoke_velocity(struct SmokeModifierData *smd); void GPU_free_unused_buffers(struct Main *bmain); /* utilities */ -void GPU_select_index_set(int index); -void GPU_select_index_get(int index, int *r_col); -int GPU_select_to_index(unsigned int col); -void GPU_select_to_index_array(unsigned int *col, const unsigned int size); - typedef enum eGPUAttrMask { GPU_DEPTH_BUFFER_BIT = (1 << 0), GPU_ENABLE_BIT = (1 << 1), diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index 3154119592d..b656bb74d4b 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -42,7 +42,6 @@ int GPU_max_cube_map_size(void); int GPU_max_ubo_binds(void); int GPU_max_ubo_size(void); float GPU_max_line_width(void); -int GPU_color_depth(void); void GPU_get_dfdy_factors(float fac[2]); bool GPU_mip_render_workaround(void); bool GPU_depth_blitting_workaround(void); diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 62dcbb94d1c..d91ea234931 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1275,148 +1275,6 @@ void GPU_disable_program_point_size(void) /** \name Framebuffer color depth, for selection codes * \{ */ -#ifdef __APPLE__ - -/* apple seems to round colors to below and up on some configs */ - -static uint index_to_framebuffer(int index) -{ - uint i = index; - - switch (GPU_color_depth()) { - case 12: - i = ((i & 0xF00) << 12) + ((i & 0xF0) << 8) + ((i & 0xF) << 4); - /* sometimes dithering subtracts! */ - i |= 0x070707; - break; - case 15: - case 16: - i = ((i & 0x7C00) << 9) + ((i & 0x3E0) << 6) + ((i & 0x1F) << 3); - i |= 0x030303; - break; - case 24: - break; - default: /* 18 bits... */ - i = ((i & 0x3F000) << 6) + ((i & 0xFC0) << 4) + ((i & 0x3F) << 2); - i |= 0x010101; - break; - } - - return i; -} - -#else - -/* this is the old method as being in use for ages.... seems to work? colors are rounded to lower values */ - -static uint index_to_framebuffer(int index) -{ - uint i = index; - - switch (GPU_color_depth()) { - case 8: - i = ((i & 48) << 18) + ((i & 12) << 12) + ((i & 3) << 6); - i |= 0x3F3F3F; - break; - case 12: - i = ((i & 0xF00) << 12) + ((i & 0xF0) << 8) + ((i & 0xF) << 4); - /* sometimes dithering subtracts! */ - i |= 0x0F0F0F; - break; - case 15: - case 16: - i = ((i & 0x7C00) << 9) + ((i & 0x3E0) << 6) + ((i & 0x1F) << 3); - i |= 0x070707; - break; - case 24: - break; - default: /* 18 bits... */ - i = ((i & 0x3F000) << 6) + ((i & 0xFC0) << 4) + ((i & 0x3F) << 2); - i |= 0x030303; - break; - } - - return i; -} - -#endif - - -void GPU_select_index_set(int index) -{ - const int col = index_to_framebuffer(index); - glColor3ub(( (col) & 0xFF), - (((col) >> 8) & 0xFF), - (((col) >> 16) & 0xFF)); -} - -void GPU_select_index_get(int index, int *r_col) -{ - const int col = index_to_framebuffer(index); - char *c_col = (char *)r_col; - c_col[0] = (col & 0xFF); /* red */ - c_col[1] = ((col >> 8) & 0xFF); /* green */ - c_col[2] = ((col >> 16) & 0xFF); /* blue */ - c_col[3] = 0xFF; /* alpha */ -} - - -#define INDEX_FROM_BUF_8(col) ((((col) & 0xC00000) >> 18) + (((col) & 0xC000) >> 12) + (((col) & 0xC0) >> 6)) -#define INDEX_FROM_BUF_12(col) ((((col) & 0xF00000) >> 12) + (((col) & 0xF000) >> 8) + (((col) & 0xF0) >> 4)) -#define INDEX_FROM_BUF_15_16(col) ((((col) & 0xF80000) >> 9) + (((col) & 0xF800) >> 6) + (((col) & 0xF8) >> 3)) -#define INDEX_FROM_BUF_18(col) ((((col) & 0xFC0000) >> 6) + (((col) & 0xFC00) >> 4) + (((col) & 0xFC) >> 2)) -#define INDEX_FROM_BUF_24(col) ((col) & 0xFFFFFF) - -int GPU_select_to_index(uint col) -{ - if (col == 0) { - return 0; - } - - switch (GPU_color_depth()) { - case 8: return INDEX_FROM_BUF_8(col); - case 12: return INDEX_FROM_BUF_12(col); - case 15: - case 16: return INDEX_FROM_BUF_15_16(col); - case 24: return INDEX_FROM_BUF_24(col); - default: return INDEX_FROM_BUF_18(col); - } -} - -void GPU_select_to_index_array(uint *col, const uint size) -{ -#define INDEX_BUF_ARRAY(INDEX_FROM_BUF_BITS) \ - for (i = size; i--; col++) { \ - if ((c = *col)) { \ - *col = INDEX_FROM_BUF_BITS(c); \ - } \ - } ((void)0) - - if (size > 0) { - uint i, c; - - switch (GPU_color_depth()) { - case 8: - INDEX_BUF_ARRAY(INDEX_FROM_BUF_8); - break; - case 12: - INDEX_BUF_ARRAY(INDEX_FROM_BUF_12); - break; - case 15: - case 16: - INDEX_BUF_ARRAY(INDEX_FROM_BUF_15_16); - break; - case 24: - INDEX_BUF_ARRAY(INDEX_FROM_BUF_24); - break; - default: - INDEX_BUF_ARRAY(INDEX_FROM_BUF_18); - break; - } - } - -#undef INDEX_BUF_ARRAY -} #define STATE_STACK_DEPTH 16 diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 6fb40b06177..282b9dfc388 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -67,7 +67,6 @@ static struct GPUGlobal { GLint maxtexturesvert; GLint maxubosize; GLint maxubobinds; - int colordepth; int samples_color_texture_max; eGPUDeviceType device; eGPUOSType os; @@ -252,12 +251,6 @@ void gpu_extensions_init(void) BLI_assert(ret == GL_FRAMEBUFFER_DEFAULT); #endif - GLint r, g, b; - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &r); - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &g); - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &b); - GG.colordepth = r + g + b; /* Assumes same depth for RGB. */ - glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &GG.samples_color_texture_max); const char *vendor = (const char *)glGetString(GL_VENDOR); @@ -402,11 +395,6 @@ void gpu_extensions_exit(void) GPU_invalid_tex_free(); } -int GPU_color_depth(void) -{ - return GG.colordepth; -} - bool GPU_mem_stats_supported(void) { return (GLEW_NVX_gpu_memory_info || GLEW_ATI_meminfo) && (G.debug & G_DEBUG_GPU_MEM); diff --git a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl index b2d186efa91..bdb26981399 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl @@ -7,17 +7,13 @@ in vec3 pos; uniform uint offset; in uint color; -flat out vec4 id; +flat out uint id; #endif void main() { #ifndef UNIFORM_ID - id = vec4( - (((color + offset) ) & 0xFFu) * (1.0f / 255.0f), - (((color + offset) >> 8u) & 0xFFu) * (1.0f / 255.0f), - (((color + offset) >> 16u) & 0xFFu) * (1.0f / 255.0f), - (((color + offset) >> 24u) ) * (1.0f / 255.0f)); + id = offset + color; #endif vec4 pos_4d = vec4(pos, 1.0); diff --git a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl index a38113fad87..45ba6cf4d08 100644 --- a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl @@ -2,20 +2,12 @@ #ifdef UNIFORM_ID uniform uint id; #else -flat in vec4 id; +flat in uint id; #endif -out vec4 fragColor; +out uint fragColor; void main() { -#ifdef UNIFORM_ID - fragColor = vec4( - ((id ) & 0xFFu) * (1.0f / 255.0f), - ((id >> 8u) & 0xFFu) * (1.0f / 255.0f), - ((id >> 16u) & 0xFFu) * (1.0f / 255.0f), - ((id >> 24u) ) * (1.0f / 255.0f)); -#else fragColor = id; -#endif } |