diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-08-14 20:56:43 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-08-14 20:57:58 +0300 |
commit | a3c9f4de7041993ace15078e9943dc2e2c7c1fff (patch) | |
tree | 0ef7c3ab45df8d5a47a0dc2be37b781efbb62f8d /source | |
parent | 26812a185f42d52a42ebb5fdc1bb7fff58066cd1 (diff) |
Cleanup: remove unused basic shader, we use many specialized shaders now.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 1 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 1 | ||||
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 8 | ||||
-rw-r--r-- | source/blender/gpu/GPU_basic_shader.h | 133 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_basic_shader.c | 350 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_immediate_util.c | 1 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_basic_frag.glsl | 265 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_basic_geom.glsl | 100 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_basic_vert.glsl | 75 |
12 files changed, 0 insertions, 939 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 019aabdb466..2296c3bc39d 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -53,7 +53,6 @@ #include "interface_intern.h" -#include "GPU_basic_shader.h" #include "GPU_batch.h" #include "GPU_batch_presets.h" #include "GPU_immediate.h" diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 7fa093106df..b1bda08e9a5 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -48,7 +48,6 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" -#include "GPU_basic_shader.h" #include "GPU_immediate.h" #include "GPU_matrix.h" #include "GPU_state.h" diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 3649c6f6dbb..616095188bb 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -95,7 +95,6 @@ #include "GPU_draw.h" #include "GPU_select.h" -#include "GPU_basic_shader.h" #include "GPU_shader.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index b9cc1de447f..938c074920c 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -58,7 +58,6 @@ set(INC_SYS set(SRC intern/gpu_attr_binding.c - intern/gpu_basic_shader.c intern/gpu_batch.c intern/gpu_batch_presets.c intern/gpu_batch_utils.c @@ -98,9 +97,6 @@ set(SRC shaders/gpu_shader_material.glsl shaders/gpu_shader_sep_gaussian_blur_frag.glsl shaders/gpu_shader_sep_gaussian_blur_vert.glsl - shaders/gpu_shader_basic_frag.glsl - shaders/gpu_shader_basic_vert.glsl - shaders/gpu_shader_basic_geom.glsl shaders/gpu_shader_vertex.glsl shaders/gpu_shader_vsm_store_frag.glsl shaders/gpu_shader_vsm_store_vert.glsl @@ -110,7 +106,6 @@ set(SRC shaders/gpu_shader_smoke_vert.glsl GPU_attr_binding.h - GPU_basic_shader.h GPU_batch.h GPU_buffers.h GPU_common.h @@ -252,9 +247,6 @@ data_to_c_simple(shaders/gpu_shader_smoke_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_material.glsl SRC) data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_basic_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_basic_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_basic_geom.glsl SRC) data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC) data_to_c_simple(shaders/gpu_shader_vertex_world.glsl SRC) data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC) diff --git a/source/blender/gpu/GPU_basic_shader.h b/source/blender/gpu/GPU_basic_shader.h deleted file mode 100644 index 89d31f57607..00000000000 --- a/source/blender/gpu/GPU_basic_shader.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Brecht Van Lommel. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file GPU_basic_shader.h - * \ingroup gpu - */ - -#ifndef __GPU_BASIC_SHADER_H__ -#define __GPU_BASIC_SHADER_H__ - -#include "BLI_utildefines.h" -#include "GPU_glew.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Fixed Function Shader */ - -typedef enum GPUBasicShaderOption { - GPU_SHADER_USE_COLOR = (1 << 0), /* use glColor, for lighting it replaces diffuse */ - GPU_SHADER_LIGHTING = (1 << 1), /* use lighting */ - GPU_SHADER_TWO_SIDED = (1 << 2), /* flip normals towards viewer */ - GPU_SHADER_TEXTURE_2D = (1 << 3), /* use 2D texture to replace diffuse color */ - GPU_SHADER_TEXTURE_RECT = (1 << 4), /* same as GPU_SHADER_TEXTURE_2D, for GL_TEXTURE_RECTANGLE */ - - GPU_SHADER_SOLID_LIGHTING = (1 << 5), /* use faster lighting (set automatically) */ - GPU_SHADER_STIPPLE = (1 << 6), /* use stipple */ - GPU_SHADER_LINE = (1 << 7), /* draw lines */ - GPU_SHADER_FLAT_NORMAL = (1 << 8), /* use flat normals */ - GPU_SHADER_OPTIONS_NUM = 9, - GPU_SHADER_OPTION_COMBINATIONS = (1 << GPU_SHADER_OPTIONS_NUM) -} GPUBasicShaderOption; - -/* Keep these in sync with gpu_shader_basic_frag.glsl */ -typedef enum GPUBasicShaderStipple { - GPU_SHADER_STIPPLE_HALFTONE = 0, - GPU_SHADER_STIPPLE_QUARTTONE = 1, - GPU_SHADER_STIPPLE_CHECKER_8PX = 2, - GPU_SHADER_STIPPLE_HEXAGON = 3, - GPU_SHADER_STIPPLE_DIAG_STRIPES = 4, - GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP = 5, -} GPUBasicShaderStipple; - -void GPU_basic_shaders_init(void); -void GPU_basic_shaders_exit(void); - -void GPU_basic_shader_bind(int options); -void GPU_basic_shader_bind_enable(int options); -void GPU_basic_shader_bind_disable(int options); - -int GPU_basic_shader_bound_options(void); - -/* Only use for small blocks of code that don't support glsl shader. */ -#define GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options) \ -if (GPU_basic_shader_use_glsl_get()) { \ - if ((bound_options = GPU_basic_shader_bound_options())) { \ - GPU_basic_shader_bind(0); \ - } \ -} \ -else { bound_options = 0; } ((void)0) -#define GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options) \ -if (GPU_basic_shader_use_glsl_get()) { \ - if (bound_options) { \ - GPU_basic_shader_bind(bound_options); \ - } \ -} ((void)0) - - -void GPU_basic_shader_colors( - const float diffuse[3], const float specular[3], - int shininess, float alpha); - -/* Fixed Function Lighting */ - -typedef enum GPULightType { - GPU_LIGHT_POINT, - GPU_LIGHT_SPOT, - GPU_LIGHT_SUN -} GPULightType; - -typedef struct GPULightData { - GPULightType type; - - float position[3]; - float direction[3]; - - float diffuse[3]; - float specular[3]; - - float constant_attenuation; - float linear_attenuation; - float quadratic_attenuation; - - float spot_cutoff; - float spot_exponent; -} GPULightData; - -void GPU_basic_shader_light_set(int light_num, GPULightData *light); -void GPU_basic_shader_light_set_viewer(bool local); -void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id); -void GPU_basic_shader_line_stipple(GLint stipple_factor, GLushort stipple_pattern); -void GPU_basic_shader_line_width(float line_width); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c deleted file mode 100644 index 1b7b1ecf85a..00000000000 --- a/source/blender/gpu/intern/gpu_basic_shader.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2013 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Brecht Van Lommel. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/gpu/intern/gpu_basic_shader.c - * \ingroup gpu - * - * GLSL shaders to replace fixed function OpenGL materials and lighting. These - * are deprecated in newer OpenGL versions and missing in OpenGL ES 2.0. Also, - * two sided lighting is no longer natively supported on NVidia cards which - * results in slow software fallback. - * - * Todo: - * - Replace glLight and glMaterial functions entirely with GLSL uniforms, to - * make OpenGL ES 2.0 work. - * - Replace glTexCoord and glColor with generic attributes. - * - Optimize for case where fewer than 3 or 8 lights are used. - * - Optimize for case where specular is not used. - * - Optimize for case where no texture matrix is used. - */ - -#include "BLI_math.h" -#include "BLI_utildefines.h" - -#include "GPU_basic_shader.h" -#include "GPU_glew.h" -#include "GPU_shader.h" - -/* State */ - -static struct { - GPUShader *cached_shaders[GPU_SHADER_OPTION_COMBINATIONS]; - bool failed_shaders[GPU_SHADER_OPTION_COMBINATIONS]; - - int bound_options; - - int lights_enabled; - int lights_directional; - float line_width; - GLint viewport[4]; -} GPU_MATERIAL_STATE; - - -/* Stipple patterns */ -/* ******************************************** */ -const GLubyte stipple_halftone[128] = { - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, -}; - -const GLubyte stipple_quarttone[128] = { - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, - 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, -}; - -const GLubyte stipple_diag_stripes_pos[128] = { - 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, - 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, - 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, - 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, - 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, - 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, - 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, - 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, - 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, - 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, - 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, - 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, -}; - -const GLubyte stipple_diag_stripes_neg[128] = { - 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, - 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, - 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, - 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, - 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, - 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, - 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, - 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, - 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, - 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, - 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, - 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, -}; - -const GLubyte stipple_checker_8px[128] = { - 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, - 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, - 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, - 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, - 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, - 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, - 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, - 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, -}; - -const GLubyte stipple_hexagon[128] = { - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, -}; -/* ********************************************* */ - -/* Init / exit */ - -void GPU_basic_shaders_init(void) -{ - memset(&GPU_MATERIAL_STATE, 0, sizeof(GPU_MATERIAL_STATE)); -} - -void GPU_basic_shaders_exit(void) -{ - int i; - - for (i = 0; i < GPU_SHADER_OPTION_COMBINATIONS; i++) - if (GPU_MATERIAL_STATE.cached_shaders[i]) - GPU_shader_free(GPU_MATERIAL_STATE.cached_shaders[i]); -} - -/* Shader lookup / create */ - -static bool solid_compatible_lighting(void) -{ - int enabled = GPU_MATERIAL_STATE.lights_enabled; - int directional = GPU_MATERIAL_STATE.lights_directional; - - /* more than 3 lights? */ - if (enabled >= (1 << 3)) - return false; - - /* all directional? */ - return ((directional & enabled) == enabled); -} - -static GPUShader *gpu_basic_shader(int options) -{ - /* glsl code */ - extern char datatoc_gpu_shader_basic_vert_glsl[]; - extern char datatoc_gpu_shader_basic_frag_glsl[]; - extern char datatoc_gpu_shader_basic_geom_glsl[]; - char *geom_glsl = NULL; - GPUShader *shader; - - /* detect if we can do faster lighting for solid draw mode */ - if (options & GPU_SHADER_LIGHTING) - if (solid_compatible_lighting()) - options |= GPU_SHADER_SOLID_LIGHTING; - - /* cached shaders */ - shader = GPU_MATERIAL_STATE.cached_shaders[options]; - - if (!shader && !GPU_MATERIAL_STATE.failed_shaders[options]) { - /* create shader if it doesn't exist yet */ - char defines[64 * GPU_SHADER_OPTIONS_NUM] = ""; - - if (options & GPU_SHADER_USE_COLOR) - strcat(defines, "#define USE_COLOR\n"); - if (options & GPU_SHADER_TWO_SIDED) - strcat(defines, "#define USE_TWO_SIDED\n"); - if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) - strcat(defines, "#define USE_TEXTURE\n"); - if (options & GPU_SHADER_TEXTURE_RECT) - strcat(defines, "#define USE_TEXTURE_RECTANGLE\n"); - if (options & GPU_SHADER_STIPPLE) - strcat(defines, "#define USE_STIPPLE\n"); - if (options & GPU_SHADER_LINE) { - strcat(defines, "#define DRAW_LINE\n"); - geom_glsl = datatoc_gpu_shader_basic_geom_glsl; - } - if (options & GPU_SHADER_FLAT_NORMAL) - strcat(defines, "#define USE_FLAT_NORMAL\n"); - if (options & GPU_SHADER_SOLID_LIGHTING) - strcat(defines, "#define USE_SOLID_LIGHTING\n"); - else if (options & GPU_SHADER_LIGHTING) - strcat(defines, "#define USE_SCENE_LIGHTING\n"); - - shader = GPU_shader_create( - datatoc_gpu_shader_basic_vert_glsl, - datatoc_gpu_shader_basic_frag_glsl, - geom_glsl, - NULL, - defines, - __func__); - - if (shader) { - /* set texture map to first texture unit */ - if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) { - GPU_shader_bind(shader); - glUniform1i(GPU_shader_get_uniform(shader, "texture_map"), 0); - GPU_shader_unbind(); - } - - GPU_MATERIAL_STATE.cached_shaders[options] = shader; - } - else - GPU_MATERIAL_STATE.failed_shaders[options] = true; - } - - return shader; -} - -static void gpu_basic_shader_uniform_autoset(GPUShader *shader, int options) -{ - if (options & GPU_SHADER_LINE) { - glGetIntegerv(GL_VIEWPORT, &GPU_MATERIAL_STATE.viewport[0]); - glUniform4iv(GPU_shader_get_uniform(shader, "viewport"), 1, &GPU_MATERIAL_STATE.viewport[0]); - glUniform1f(GPU_shader_get_uniform(shader, "line_width"), GPU_MATERIAL_STATE.line_width); - } -} - -/* Bind / unbind */ - -void GPU_basic_shader_bind(int options) -{ - if (options) { - GPUShader *shader = gpu_basic_shader(options); - - if (shader) { - GPU_shader_bind(shader); - gpu_basic_shader_uniform_autoset(shader, options); - } - } - else { - GPU_shader_unbind(); - } - - GPU_MATERIAL_STATE.bound_options = options; -} - -void GPU_basic_shader_bind_enable(int options) -{ - GPU_basic_shader_bind(GPU_MATERIAL_STATE.bound_options | options); -} - -void GPU_basic_shader_bind_disable(int options) -{ - GPU_basic_shader_bind(GPU_MATERIAL_STATE.bound_options & ~options); -} - -int GPU_basic_shader_bound_options(void) -{ - /* ideally this should disappear, anything that uses this is making fragile - * assumptions that the basic shader is bound and not another shader */ - return GPU_MATERIAL_STATE.bound_options; -} - -/* Material Colors */ - -void GPU_basic_shader_colors( - const float diffuse[3], const float specular[3], - int shininess, float alpha) -{ - UNUSED_VARS(diffuse, specular, shininess, alpha); - return; -} - -void GPU_basic_shader_light_set(int light_num, GPULightData *light) -{ - UNUSED_VARS(light_num, light); - return; -} - -void GPU_basic_shader_light_set_viewer(bool local) -{ - UNUSED_VARS(local); - return; -} - -void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id) -{ - glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_id"), stipple_id); -} - -void GPU_basic_shader_line_width(float line_width) -{ - GPU_MATERIAL_STATE.line_width = line_width; - if (GPU_MATERIAL_STATE.bound_options & GPU_SHADER_LINE) { - glUniform1f(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "line_width"), line_width); - } -} - -void GPU_basic_shader_line_stipple(GLint stipple_factor, GLushort stipple_pattern) -{ - glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_factor"), stipple_factor); - glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_pattern"), stipple_pattern); -} diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 965caba0955..64301179dac 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -71,7 +71,6 @@ #include "BKE_scene.h" #include "BKE_DerivedMesh.h" -#include "GPU_basic_shader.h" #include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_material.h" diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 43081154e89..0c2f11b1f74 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -38,7 +38,6 @@ #include "BKE_global.h" -#include "GPU_basic_shader.h" #include "GPU_extensions.h" #include "GPU_glew.h" #include "GPU_texture.h" @@ -259,12 +258,10 @@ void gpu_extensions_init(void) GPU_invalid_tex_init(); - GPU_basic_shaders_init(); } void gpu_extensions_exit(void) { - GPU_basic_shaders_exit(); GPU_invalid_tex_free(); } diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c index 8384ef3b5d0..0a75bd17d8c 100644 --- a/source/blender/gpu/intern/gpu_immediate_util.c +++ b/source/blender/gpu/intern/gpu_immediate_util.c @@ -30,7 +30,6 @@ #include "BLI_utildefines.h" #include "BLI_math.h" -#include "GPU_basic_shader.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" #include "GPU_matrix.h" diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl deleted file mode 100644 index c4657bb7f66..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl +++ /dev/null @@ -1,265 +0,0 @@ - -/* Options: - * - * USE_COLOR: use glColor for diffuse colors - * USE_TEXTURE: use texture for diffuse colors - * USE_TEXTURE_RECTANGLE: use GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D - * USE_SCENE_LIGHTING: use lights (up to 8) - * USE_SOLID_LIGHTING: assume 3 directional lights for solid draw mode - * USE_TWO_SIDED: flip normal towards viewer - * NO_SPECULAR: use specular component - */ - -#define NUM_SOLID_LIGHTS 3 -#define NUM_SCENE_LIGHTS 8 - -/* Keep these in sync with GPU_basic_shader.h */ -#define STIPPLE_HALFTONE 0 -#define STIPPLE_QUARTTONE 1 -#define STIPPLE_CHECKER_8PX 2 -#define STIPPLE_HEXAGON 3 -#define STIPPLE_DIAG_STRIPES 4 -#define STIPPLE_DIAG_STRIPES_SWAP 5 - -#ifndef NO_SPECULAR -uniform mat4 ProjectionMatrix; -#endif - -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) -#if defined(USE_FLAT_NORMAL) -varying vec3 eyespace_vert_pos; -#else -varying vec3 varying_normal; -#endif -#ifndef USE_SOLID_LIGHTING -varying vec3 varying_position; -#endif -#endif - -#ifdef USE_COLOR -varying vec4 varying_vertex_color; -#endif - -#ifdef USE_TEXTURE -#ifdef USE_TEXTURE_RECTANGLE -#define sampler2D_default sampler2DRect -#define texture2D_default texture2DRect -#else -#define sampler2D_default sampler2D -#define texture2D_default texture2D -#endif - -varying vec2 varying_texture_coord; -uniform sampler2D_default texture_map; -#endif - -#ifdef USE_STIPPLE -uniform int stipple_id; -#if defined(DRAW_LINE) -varying float t; -uniform int stipple_pattern; -#endif -#endif - -void main() -{ -#if defined(USE_STIPPLE) -#if defined(DRAW_LINE) - /* GLSL 1.3 */ - if (!bool((1 << int(mod(t, 16))) & stipple_pattern)) - discard; -#else - /* We have to use mod function and integer casting. - * This can be optimized further with the bitwise operations - * when GLSL 1.3 is supported. */ - if (stipple_id == STIPPLE_HALFTONE) { - int result = int(mod(gl_FragCoord.x + gl_FragCoord.y, 2)); - bool dis = result == 0; - if (dis) - discard; - } - else if (stipple_id == STIPPLE_QUARTTONE) { - int mody = int(mod(gl_FragCoord.y, 4)); - int modx = int(mod(gl_FragCoord.x, 4)); - if (mody == 0) { - if (modx != 2) - discard; - } - else if (mody == 2) { - if (modx != 0) - discard; - } - else - discard; - } - else if (stipple_id == STIPPLE_CHECKER_8PX) { - int result = int(mod(int(gl_FragCoord.x) / 8 + int(gl_FragCoord.y) / 8, 2)); - if (result != 0) - discard; - } - else if (stipple_id == STIPPLE_DIAG_STRIPES) { - int mody = int(mod(gl_FragCoord.y, 16)); - int modx = int(mod(gl_FragCoord.x, 16)); - if ((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx) - discard; - } - else if (stipple_id == STIPPLE_DIAG_STRIPES_SWAP) { - int mody = int(mod(gl_FragCoord.y, 16)); - int modx = int(mod(gl_FragCoord.x, 16)); - if (!((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx)) - discard; - } - else if (stipple_id == STIPPLE_HEXAGON) { - int mody = int(mod(gl_FragCoord.y, 2)); - int modx = int(mod(gl_FragCoord.x, 4)); - if (mody != 0) { - if (modx != 1) - discard; - } - else { - if (modx != 3) - discard; - } - } -#endif /* !DRAW_LINE */ -#endif /* USE_STIPPLE */ - -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) - /* compute normal */ -#if defined(USE_FLAT_NORMAL) - vec3 N = normalize(cross(dFdx(eyespace_vert_pos), dFdy(eyespace_vert_pos))); -#else - vec3 N = normalize(varying_normal); -#endif - -#ifdef USE_TWO_SIDED - if (!gl_FrontFacing) - N = -N; -#endif - - /* compute diffuse and specular lighting */ - vec3 L_diffuse = vec3(0.0); -#ifndef NO_SPECULAR - vec3 L_specular = vec3(0.0); -#endif - -#ifdef USE_SOLID_LIGHTING - /* assume 3 directional lights */ - for (int i = 0; i < NUM_SOLID_LIGHTS; i++) { - vec3 light_direction = gl_LightSource[i].position.xyz; - - /* diffuse light */ - vec3 light_diffuse = gl_LightSource[i].diffuse.rgb; - float diffuse_bsdf = max(dot(N, light_direction), 0.0); - L_diffuse += light_diffuse * diffuse_bsdf; - -#ifndef NO_SPECULAR - /* specular light */ - vec3 light_specular = gl_LightSource[i].specular.rgb; - vec3 H = gl_LightSource[i].halfVector.xyz; - - float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess); - L_specular += light_specular * specular_bsdf; -#endif - } -#else - /* all 8 lights, makes no assumptions, potentially slow */ - -#ifndef NO_SPECULAR - /* view vector computation, depends on orthographics or perspective */ - vec3 V = (ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0); -#endif - - for (int i = 0; i < NUM_SCENE_LIGHTS; i++) { - /* todo: this is a slow check for disabled lights */ - if (gl_LightSource[i].specular.a == 0.0) - continue; - - float intensity = 1.0; - vec3 light_direction; - - if (gl_LightSource[i].position.w == 0.0) { - /* directional light */ - light_direction = gl_LightSource[i].position.xyz; - } - else { - /* point light */ - vec3 d = gl_LightSource[i].position.xyz - varying_position; - light_direction = normalize(d); - - /* spot light cone */ - if (gl_LightSource[i].spotCutoff < 90.0) { - float cosine = max(dot(light_direction, -gl_LightSource[i].spotDirection), 0.0); - intensity = pow(cosine, gl_LightSource[i].spotExponent); - intensity *= step(gl_LightSource[i].spotCosCutoff, cosine); - } - - /* falloff */ - float distance = length(d); - - intensity /= gl_LightSource[i].constantAttenuation + - gl_LightSource[i].linearAttenuation * distance + - gl_LightSource[i].quadraticAttenuation * distance * distance; - } - - /* diffuse light */ - vec3 light_diffuse = gl_LightSource[i].diffuse.rgb; - float diffuse_bsdf = max(dot(N, light_direction), 0.0); - L_diffuse += light_diffuse * diffuse_bsdf * intensity; - -#ifndef NO_SPECULAR - /* specular light */ - vec3 light_specular = gl_LightSource[i].specular.rgb; - vec3 H = normalize(light_direction - V); - - float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess); - L_specular += light_specular * specular_bsdf * intensity; -#endif - } -#endif - - /* compute diffuse color, possibly from texture or vertex colors */ - float alpha; - -#if defined(USE_TEXTURE) && defined(USE_COLOR) - vec4 texture_color = texture2D_default(texture_map, varying_texture_coord); - - L_diffuse *= texture_color.rgb * varying_vertex_color.rgb; - alpha = texture_color.a * varying_vertex_color.a; -#elif defined(USE_TEXTURE) - vec4 texture_color = texture2D_default(texture_map, varying_texture_coord); - - L_diffuse *= texture_color.rgb; - alpha = texture_color.a; -#elif defined(USE_COLOR) - L_diffuse *= varying_vertex_color.rgb; - alpha = varying_vertex_color.a; -#else - L_diffuse *= gl_FrontMaterial.diffuse.rgb; - alpha = gl_FrontMaterial.diffuse.a; -#endif - - /* sum lighting */ - vec3 L = gl_FrontLightModelProduct.sceneColor.rgb + L_diffuse; - -#ifndef NO_SPECULAR - L += L_specular * gl_FrontMaterial.specular.rgb; -#endif - - /* write out fragment color */ - gl_FragColor = vec4(L, alpha); -#else - - /* no lighting */ -#if defined(USE_TEXTURE) && defined(USE_COLOR) - gl_FragColor = texture2D_default(texture_map, varying_texture_coord) * varying_vertex_color; -#elif defined(USE_TEXTURE) - gl_FragColor = texture2D_default(texture_map, varying_texture_coord); -#elif defined(USE_COLOR) - gl_FragColor = varying_vertex_color; -#else - gl_FragColor = gl_FrontMaterial.diffuse; -#endif - -#endif -} diff --git a/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl b/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl deleted file mode 100644 index 13f05b340bf..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Used the implementation of wide lines of Timo Suoranta (http://neure.dy.fi/wideline.html) - */ - -#define PASSTHROUGH 0 - -layout(lines) in; - -#if defined(DRAW_LINE) - -#if PASSTHROUGH -layout(line_strip, max_vertices = 10) out; -#else -layout(triangle_strip, max_vertices = 6) out; -#endif - -out float t; -in vec4 varying_vertex_color_line[]; -out vec4 varying_vertex_color; - -uniform ivec4 viewport; -uniform float line_width; -uniform int stipple_factor; - -void main(void) -{ - vec2 window_size = viewport.zw; - vec4 start = gl_in[0].gl_Position; - vec4 end = gl_in[1].gl_Position; -#if PASSTHROUGH - gl_Position = start; EmitVertex(); - gl_Position = end; EmitVertex(); - EndPrimitive(); - return; -#endif - - /* t = 0 t = ~(len(end - start) + 2*line_width) - * A-------------------------------------B - * | | | | - * | side | | - * | | | | - * |--axis--*start--------------*end-----| - * | | | | - * | | | | - * | | | | - * D-------------------------------------C - */ - - /* Clip the line before homogenization. - * Compute line start and end distances to nearplane in clipspace - * Distances are t0 = dot(start, plane) and t1 = dot(end, plane) - */ - float t0 = start.z + start.w; - float t1 = end.z + end.w; - if (t0 < 0.0) { - if (t1 < 0.0) { - return; - } - start = mix(start, end, (0 - t0) / (t1 - t0)); - } - if (t1 < 0.0) { - end = mix(start, end, (0 - t0) / (t1 - t0)); - } - - /* Compute line axis and side vector in screen space */ - vec2 startInNDC = start.xy / start.w; /* clip to NDC: homogenize and drop z */ - vec2 endInNDC = end.xy / end.w; - vec2 lineInNDC = endInNDC - startInNDC; - vec2 lineInScreen = lineInNDC * window_size; /* ndc to screen (direction vector) */ - - vec2 axisInScreen = normalize(lineInScreen); - vec2 sideInScreen = vec2(-axisInScreen.y, axisInScreen.x); /* rotate */ - vec2 axisInNDC = axisInScreen / window_size; /* screen to NDC */ - vec2 sideInNDC = sideInScreen / window_size; - vec4 axis = vec4(axisInNDC, 0.0, 0.0) * line_width; /* NDC to clip (delta vector) */ - vec4 side = vec4(sideInNDC, 0.0, 0.0) * line_width; - - vec4 A = (start + (side - axis) * start.w); - vec4 B = (end + (side + axis) * end.w); - vec4 C = (end - (side - axis) * end.w); - vec4 D = (start - (side + axis) * start.w); - - /* There is no relation between lines yet */ - /* TODO Pass here t0 to make continuous pattern. */ - t0 = 0; - t1 = (length(lineInScreen) + 2 * line_width) / (2 * line_width * stipple_factor); - - gl_Position = A; t = t0; varying_vertex_color = varying_vertex_color_line[0]; EmitVertex(); - gl_Position = D; t = t0; varying_vertex_color = varying_vertex_color_line[0]; EmitVertex(); - gl_Position = B; t = t1; varying_vertex_color = varying_vertex_color_line[1]; EmitVertex(); - gl_Position = C; t = t1; varying_vertex_color = varying_vertex_color_line[1]; EmitVertex(); - EndPrimitive(); -} - -#else -void main(void) -{ - -} -#endif diff --git a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl deleted file mode 100644 index 4fdaf809cd1..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl +++ /dev/null @@ -1,75 +0,0 @@ - -uniform mat4 ModelViewMatrix; -uniform mat4 ProjectionMatrix; -uniform mat3 NormalMatrix; - -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) -#if defined(USE_FLAT_NORMAL) -varying vec3 eyespace_vert_pos; -#else -varying vec3 varying_normal; -#endif - -#ifndef USE_SOLID_LIGHTING -varying vec3 varying_position; -#endif -#endif - -#ifdef USE_COLOR -#ifdef DRAW_LINE -varying vec4 varying_vertex_color_line; -#else -varying vec4 varying_vertex_color; -#endif -#endif - -#ifdef USE_TEXTURE -varying vec2 varying_texture_coord; -#endif - -#ifdef CLIP_WORKAROUND -varying float gl_ClipDistance[6]; -#endif - -void main() -{ - vec4 co = ModelViewMatrix * gl_Vertex; - -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) -#if !defined(USE_FLAT_NORMAL) - varying_normal = normalize(NormalMatrix * gl_Normal); -#endif -#if defined(USE_FLAT_NORMAL) - /* transform vertex into eyespace */ - eyespace_vert_pos = (ModelViewMatrix * gl_Vertex).xyz; -#endif - -#ifndef USE_SOLID_LIGHTING - varying_position = co.xyz; -#endif -#endif - - gl_Position = ProjectionMatrix * co; - -#ifdef CLIP_WORKAROUND - int i; - for (i = 0; i < 6; i++) - gl_ClipDistance[i] = dot(co, gl_ClipPlane[i]); -#elif !defined(GPU_ATI) - // Setting gl_ClipVertex is necessary to get glClipPlane working on NVIDIA - // graphic cards, while on ATI it can cause a software fallback. - gl_ClipVertex = co; -#endif - -#ifdef USE_COLOR -#ifdef DRAW_LINE - varying_vertex_color_line = gl_Color; -#else - varying_vertex_color = gl_Color; -#endif -#endif - -#ifdef USE_TEXTURE - varying_texture_coord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; -#endif -} |