[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55166] trunk/blender: OpenGL: more work on fixed function lighting implementation as GLSL.

Brecht Van Lommel brechtvanlommel at pandora.be
Sun Mar 10 16:38:24 CET 2013


Revision: 55166
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55166
Author:   blendix
Date:     2013-03-10 15:38:23 +0000 (Sun, 10 Mar 2013)
Log Message:
-----------
OpenGL: more work on fixed function lighting implementation as GLSL.

* Rename functions and move to own header.
* Add wrapper functions for glLight.
* Auto detect if we can use faster code for solid lighting.
* Various fixes for textured draw mode.

Modified Paths:
--------------
    trunk/blender/SConstruct
    trunk/blender/source/blender/gpu/CMakeLists.txt
    trunk/blender/source/blender/gpu/GPU_extensions.h
    trunk/blender/source/blender/gpu/SConscript
    trunk/blender/source/blender/gpu/intern/gpu_extensions.c

Added Paths:
-----------
    trunk/blender/source/blender/gpu/GPU_simple_shader.h
    trunk/blender/source/blender/gpu/intern/gpu_simple_shader.c
    trunk/blender/source/blender/gpu/shaders/gpu_shader_simple_frag.glsl
    trunk/blender/source/blender/gpu/shaders/gpu_shader_simple_vert.glsl

Removed Paths:
-------------
    trunk/blender/source/blender/gpu/intern/gpu_fixed_material.c
    trunk/blender/source/blender/gpu/shaders/gpu_shader_fixed_fragment.glsl
    trunk/blender/source/blender/gpu/shaders/gpu_shader_fixed_vertex.glsl

Modified: trunk/blender/SConstruct
===================================================================
--- trunk/blender/SConstruct	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/SConstruct	2013-03-10 15:38:23 UTC (rev 55166)
@@ -527,8 +527,8 @@
     data_to_c_simple("release/datafiles/preview_cycles.blend")
 
     # --- glsl ---
-    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fixed_fragment.glsl")
-    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fixed_vertex.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_simple_frag.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_simple_vert.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl")

Modified: trunk/blender/source/blender/gpu/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/gpu/CMakeLists.txt	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/source/blender/gpu/CMakeLists.txt	2013-03-10 15:38:23 UTC (rev 55166)
@@ -50,21 +50,22 @@
 	intern/gpu_codegen.c
 	intern/gpu_draw.c
 	intern/gpu_extensions.c
-	intern/gpu_fixed_material.c
 	intern/gpu_material.c
+	intern/gpu_simple_shader.c
 
 	GPU_buffers.h
 	GPU_draw.h
 	GPU_extensions.h
 	GPU_material.h
+	GPU_simple_shader.h
 	intern/gpu_codegen.h
 )
 
-data_to_c_simple(shaders/gpu_shader_fixed_fragment.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fixed_vertex.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_simple_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_simple_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)

Modified: trunk/blender/source/blender/gpu/GPU_extensions.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_extensions.h	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/source/blender/gpu/GPU_extensions.h	2013-03-10 15:38:23 UTC (rev 55166)
@@ -201,30 +201,6 @@
 	int totlayer;
 } GPUVertexAttribs;
 
-/* Fixed Function Materials */
-
-typedef enum GPUFixedMaterialOption {
-	GPU_FIXED_COLOR_MATERIAL = (1<<0),   /* replace diffuse with glcolor */
-	GPU_FIXED_SOLID_LIGHTING = (1<<1),   /* use solid lighting (only 3 directional lights) */
-	GPU_FIXED_SCENE_LIGHTING = (1<<2),   /* use scene lighting (up to 8 arbitrary lights) */
-	GPU_FIXED_TWO_SIDED = (1<<3),        /* flip normals towards viewer */
-	GPU_FIXED_TEXTURE_2D = (1<<4),       /* use 2D texture to replace diffuse color */
-
-	GPU_FIXED_OPTIONS_NUM = 5,
-	GPU_FIXED_OPTION_COMBINATIONS = (1<<GPU_FIXED_OPTIONS_NUM)
-} GPUFixedMaterialOption;
-
-void GPU_fixed_materials_init(void);
-void GPU_fixed_materials_exit(void);
-
-void GPU_fixed_material_shader_bind(int options);
-void GPU_fixed_material_shader_unbind(void);
-
-void GPU_fixed_material_colors(const float diffuse[3], const float specular[3],
-	int shininess, float alpha);
-
-bool GPU_fixed_material_need_normals(void);
-
 #ifdef __cplusplus
 }
 #endif

Added: trunk/blender/source/blender/gpu/GPU_simple_shader.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_simple_shader.h	                        (rev 0)
+++ trunk/blender/source/blender/gpu/GPU_simple_shader.h	2013-03-10 15:38:23 UTC (rev 55166)
@@ -0,0 +1,89 @@
+/*
+ * ***** 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_simple_shader.h
+ *  \ingroup gpu
+ */
+
+#ifndef __GPU_SIMPLE_SHADER_H__
+#define __GPU_SIMPLE_SHADER_H__
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Fixed Function Shader */
+
+typedef enum GPUSimpleShaderOption {
+	GPU_SHADER_OVERRIDE_DIFFUSE = (1<<0),   /* replace diffuse with glcolor */
+	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_SOLID_LIGHTING = (1<<4),     /* use faster lighting (set automatically) */
+	GPU_SHADER_OPTIONS_NUM = 5,
+	GPU_SHADER_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM)
+} GPUSimpleShaderOption;
+
+void GPU_simple_shaders_init(void);
+void GPU_simple_shaders_exit(void);
+
+void GPU_simple_shader_bind(int options);
+void GPU_simple_shader_unbind(void);
+
+void GPU_simple_shader_colors(const float diffuse[3], const float specular[3],
+	int shininess, float alpha);
+
+bool GPU_simple_shader_need_normals(void);
+
+/* Fixed Function Lighting */
+
+typedef struct GPULightData {
+	float position[4];
+	float diffuse[4];
+	float specular[4];
+
+	float constant_attenuation;
+	float linear_attenuation;
+	float quadratic_attenuation;
+
+	float spot_direction[3];
+	float spot_cutoff;
+	float spot_exponent;
+} GPULightData;
+
+void GPU_simple_shader_light_set(int light_num, GPULightData *light);
+void GPU_simple_shader_light_set_viewer(bool local);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+

Modified: trunk/blender/source/blender/gpu/SConscript
===================================================================
--- trunk/blender/source/blender/gpu/SConscript	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/source/blender/gpu/SConscript	2013-03-10 15:38:23 UTC (rev 55166)
@@ -49,8 +49,8 @@
 # generated data files
 import os
 sources.extend((
-	os.path.join(env['DATA_SOURCES'], "gpu_shader_fixed_fragment.glsl.c"),
-	os.path.join(env['DATA_SOURCES'], "gpu_shader_fixed_vertex.glsl.c"),
+	os.path.join(env['DATA_SOURCES'], "gpu_shader_simple_frag.glsl.c"),
+	os.path.join(env['DATA_SOURCES'], "gpu_shader_simple_vert.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_material.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_sep_gaussian_blur_frag.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_sep_gaussian_blur_vert.glsl.c"),

Modified: trunk/blender/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2013-03-10 15:38:23 UTC (rev 55166)
@@ -44,6 +44,7 @@
 
 #include "GPU_draw.h"
 #include "GPU_extensions.h"
+#include "GPU_simple_shader.h"
 #include "gpu_codegen.h"
 
 #include <stdlib.h>
@@ -206,14 +207,14 @@
 	GG.os = GPU_OS_UNIX;
 #endif
 
-	GPU_fixed_materials_init();
+	GPU_simple_shaders_init();
 }
 
 void GPU_extensions_exit(void)
 {
 	gpu_extensions_init = 0;
 	GPU_codegen_exit();
-	GPU_fixed_materials_exit();
+	GPU_simple_shaders_exit();
 }
 
 int GPU_glsl_support(void)

Deleted: trunk/blender/source/blender/gpu/intern/gpu_fixed_material.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_fixed_material.c	2013-03-10 14:57:19 UTC (rev 55165)
+++ trunk/blender/source/blender/gpu/intern/gpu_fixed_material.c	2013-03-10 15:38:23 UTC (rev 55166)
@@ -1,191 +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_fixed_material.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 "GL/glew.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
-
-#include "GPU_extensions.h"
-
-/* Fixed function material types */
-
-static struct {
-	GPUShader *cached_shaders[GPU_FIXED_OPTION_COMBINATIONS];
-	bool failed_shaders[GPU_FIXED_OPTION_COMBINATIONS];
-
-	bool need_normals;
-} GPU_MATERIAL_STATE;
-
-/* Init / exit */
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list