[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58955] branches/soc-2013-viewport_fx/ source/blender: Basic shader now runs and renders lit objects on OpenGL 3. 2 Core.

Jason Wilkins Jason.A.Wilkins at gmail.com
Tue Aug 6 05:45:28 CEST 2013


Revision: 58955
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58955
Author:   jwilkins
Date:     2013-08-06 03:45:27 +0000 (Tue, 06 Aug 2013)
Log Message:
-----------
Basic shader now runs and renders lit objects on OpenGL 3.2 Core.  

The lighting isn't accurate yet.  Lots of glitches.  

On another note, Vertex Array Objects may not be as useful as I thought they'd be for saving immediate mode state.  

Had to work around a bug in ATI drivers that makes attribute 0 not work when changed with glVertexAttrib.

Modified Paths:
--------------
    branches/soc-2013-viewport_fx/source/blender/blenlib/intern/BLI_dynstr.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_buffers.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_common.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_draw.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_extensions.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_font_shader.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_immediate.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_immediate_gl.c
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_immediate_inline.h
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_matrix.c
    branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
    branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
    branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl
    branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_uniforms.glsl
    branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_font_frag.glsl

Modified: branches/soc-2013-viewport_fx/source/blender/blenlib/intern/BLI_dynstr.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/blenlib/intern/BLI_dynstr.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/blenlib/intern/BLI_dynstr.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -242,7 +242,7 @@
 
 char *BLI_dynstr_get_cstring(DynStr *ds)
 {
-	char *rets = MEM_mallocN(ds->curlen + 1, "dynstr_cstring");
+	char *rets = (char*)MEM_mallocN(ds->curlen + 1, "dynstr_cstring");
 	BLI_dynstr_get_cstring_ex(ds, rets);
 	return rets;
 }

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -42,17 +42,25 @@
  * - Optimize for case where no texture matrix is used.
  */
 
+/* my interface */
 #include "GPU_basic_shader.h"
 
+/* my library */
+#include "GPU_extensions.h"
+#include "GPU_matrix.h"
+
+/* internal */
 #include "intern/gpu_common.h"
 #include "intern/gpu_safety.h"
 
-#include "GPU_extensions.h"
-#include "GPU_matrix.h"
+/* external */
 
 #include "BLI_math.h"
 #include "BLI_dynstr.h"
 
+#include "MEM_guardedalloc.h"
+
+/* standard */
 #include <string.h>
 
 
@@ -76,6 +84,12 @@
 void GPU_basic_shaders_init(void)
 {
 	memset(&BASIC_SHADER, 0, sizeof(BASIC_SHADER));
+
+	//{
+	//	int i;
+	//for (i = 0; i < GPU_BASIC_OPTION_COMBINATIONS; i++)
+	//	BASIC_SHADER.failed[i] = true;
+	//}
 }
 
 
@@ -147,6 +161,10 @@
 		DynStr* frag = BLI_dynstr_new();
 		DynStr* defs = BLI_dynstr_new();
 
+		char* vert_cstring;
+		char* frag_cstring;
+		char* defs_cstring;
+
 		gpu_include_common_vert(vert);
 		BLI_dynstr_append(vert, datatoc_gpu_shader_basic_vert_glsl);
 
@@ -169,34 +187,34 @@
 
 		if (options & GPU_BASIC_LIGHTING) {
 			BLI_dynstr_append(defs, "#define USE_LIGHTING\n");
+			BLI_dynstr_append(defs, "#define USE_SPECULAR\n");
 
 			if (options & GPU_BASIC_FAST_LIGHTING)
 				BLI_dynstr_append(defs, "#define USE_FAST_LIGHTING\n");
-			else
-				BLI_dynstr_append(defs, "#define USE_SCENE_LIGHTING\n");
 		}
 
+		vert_cstring = BLI_dynstr_get_cstring(vert);
+		frag_cstring = BLI_dynstr_get_cstring(frag);
+		defs_cstring = BLI_dynstr_get_cstring(defs);
+
 		BASIC_SHADER.gpushader[options] =
-			GPU_shader_create(
-				BLI_dynstr_get_cstring(vert),
-				BLI_dynstr_get_cstring(frag),
-				NULL,
-				BLI_dynstr_get_cstring(defs));
+			GPU_shader_create(vert_cstring, frag_cstring, NULL, defs_cstring);
 GPU_CHECK_NO_ERROR();
 
+		MEM_freeN(vert_cstring);
+		MEM_freeN(frag_cstring);
+		MEM_freeN(defs_cstring);
+
+		BLI_dynstr_free(vert);
+		BLI_dynstr_free(frag);
+		BLI_dynstr_free(defs);
+
 		if (BASIC_SHADER.gpushader[options] != NULL) {
-			int i;
-
 			gpu_init_common(BASIC_SHADER.common + options, BASIC_SHADER.gpushader[options]);
 			gpu_set_common (BASIC_SHADER.common + options);
 
 			GPU_shader_bind(BASIC_SHADER.gpushader[options]);
 GPU_CHECK_NO_ERROR();
-
-			/* the mapping between samplers and texture units is static, so it can committed here once */
-			for (i = 0; i < GPU_MAX_COMMON_SAMPLERS; i++)
-				glUniform1i(BASIC_SHADER.common[options].sampler[i], i);
-GPU_CHECK_NO_ERROR();
 		}
 		else {
 			BASIC_SHADER.failed[options] = true;

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_buffers.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_buffers.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -1088,7 +1088,7 @@
 
 	for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
 		if (attribData[i].index != -1) {
-			glDisableVertexAttribArray(attribData[i].index);
+			gpu_glDisableVertexAttribArray(attribData[i].index);
 		}
 		else
 			break;
@@ -1098,8 +1098,8 @@
 	if (useVBOs) {
 		gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
 		for (i = 0; i < numdata; i++) {
-			glEnableVertexAttribArray(data[i].index);
-			glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
+			gpu_glEnableVertexAttribArray(data[i].index);
+			gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
 			                         GL_FALSE, elementsize, (void *)offset);
 			offset += data[i].size * GPU_typesize(data[i].type);
 
@@ -1111,8 +1111,8 @@
 	}
 	else {
 		for (i = 0; i < numdata; i++) {
-			glEnableVertexAttribArray(data[i].index);
-			glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
+			gpu_glEnableVertexAttribArray(data[i].index);
+			gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
 			                         GL_FALSE, elementsize, (char *)buffer->pointer + offset);
 			offset += data[i].size * GPU_typesize(data[i].type);
 		}
@@ -1146,7 +1146,7 @@
 
 	for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
 		if (attribData[i].index != -1) {
-			glDisableVertexAttribArray(attribData[i].index);
+			gpu_glDisableVertexAttribArray(attribData[i].index);
 		}
 		else
 			break;

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_common.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_common.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_common.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -34,6 +34,7 @@
 
 /* internal */
 #include "intern/gpu_extension_wrapper.h"
+#include "intern/gpu_profile.h"
 
 /* my library */
 #include "GPU_extensions.h"
@@ -80,6 +81,15 @@
 	BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_TEXCOORDS " STRINGIFY(GPU_MAX_COMMON_TEXCOORDS) "\n");
 	BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_SAMPLERS  " STRINGIFY(GPU_MAX_COMMON_SAMPLERS ) "\n");
 	BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_LIGHTS    " STRINGIFY(GPU_MAX_COMMON_LIGHTS   ) "\n");
+
+	if (GPU_PROFILE_COMPAT)
+		BLI_dynstr_append(defs, "#define GPU_PROFILE_COMPAT\n");
+
+	if (GPU_PROFILE_CORE)
+		BLI_dynstr_append(defs, "#define GPU_PROFILE_CORE\n");
+
+	if (GPU_PROFILE_ES20)
+		BLI_dynstr_append(defs, "#define GPU_PROFILE_ES20\n");
 }
 
 
@@ -119,7 +129,7 @@
 	for (i = 0; i < GPU_MAX_COMMON_SAMPLERS; i++) {
 		char symbol[100];
 
-		sprintf(symbol, "b_Sampler[%d]", i);
+		sprintf(symbol, "b_Sampler2D[%d]", i);
 		common->sampler[i] = GPU_shader_get_uniform(gpushader, symbol);
 	}
 
@@ -312,7 +322,7 @@
 }
 
 
-
+// XXX jwilkins: either remove the type parameter or add a normalize parameter (this applies to all of the pointer functions, not just gpu_color_pointer)
 void gpu_color_pointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
 {
 	GLint color = current_common != NULL ? current_common->color : -1;

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_draw.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_draw.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -1839,7 +1839,6 @@
 {
 	int a;
 	GPUbasiclight lights[GPU_MAX_COMMON_LIGHTS];
-	int count = 0;
 
 	if (!(U.light[0].flag || U.light[1].flag || U.light[2].flag)) {
 		/* initialize */
@@ -1861,7 +1860,7 @@
 		VEC4D(U.light[2].spec,  0.5f,  0.4f,  0.3f,  1.0f);
 	}
 
-	for (a = 0; a < GPU_MAX_COMMON_LIGHTS; a++) {
+	for (a = 0; a < 3; a++) {
 		if (a < 3 && U.light[a].flag) {
 			lights[a] = GPU_DEFAULT_LIGHT;
 
@@ -1870,14 +1869,12 @@
 
 			copy_v4_v4(lights[a].diffuse,  U.light[a].col);
 			copy_v4_v4(lights[a].specular, U.light[a].spec);
-
-			count++;
 		}
 	}
 
-	GPU_set_basic_lights(count, lights);
+	GPU_set_basic_lights(3, lights);
 
-	return count;
+	return 3;
 }
 
 

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_extensions.c	2013-08-06 03:45:11 UTC (rev 58954)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_extensions.c	2013-08-06 03:45:27 UTC (rev 58955)
@@ -36,6 +36,7 @@
 #include "GPU_draw.h"
 #include "GPU_basic_shader.h"
 #include "GPU_compatibility.h"
+#include "GPU_font_shader.h"
 
 /* internal */
 #include "intern/gpu_codegen.h"
@@ -294,23 +295,29 @@
 #endif
 
 	GPU_basic_shaders_init();
+	GPU_font_shader_init();
 
 	gpu_initialize_aspects();
 	gpu_initialize_aspect_funcs();
 	GPU_aspect_begin(GPU_ASPECT_BASIC, 0);
 
-	GPU_CHECK_NO_ERROR();
+GPU_CHECK_NO_ERROR();
 }
 
 void GPU_extensions_exit(void)
 {
+GPU_CHECK_NO_ERROR();
+
 	gpu_extensions_init = 0;
 	GPU_codegen_exit();
 	GPU_basic_shaders_exit();
+	GPU_font_shader_exit();
 
 	GPU_aspect_end();
 	gpu_shutdown_aspect_funcs(); // XXX jwilkins: should my shutdown functions be named exit?
 	gpu_shutdown_aspects(); // XXX jwilkins: should my shutdown functions be named exit?
+
+GPU_CHECK_NO_ERROR();
 }
 
 
@@ -413,7 +420,7 @@
 
 	len = 4*length;
 	fp = fpixels;
-	p = pixels = MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels");
+	p = pixels = (unsigned char*)MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels");
 
 	for (a=0; a<len; a++, p++, fp++)
 		*p = FTOCHAR((*fp));
@@ -598,7 +605,7 @@
 	if (!(GLEW_VERSION_1_2 || GLEW_ARB_texture3D || GLEW_EXT_texture3D || GLEW_OES_texture_3D))
 		return NULL;
 
-	tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
+	tex = (GPUTexture*)MEM_callocN(sizeof(GPUTexture), "GPUTexture");
 	tex->w = w;
 	tex->h = h;
 	tex->depth = depth;
@@ -648,7 +655,7 @@
 	if (fpixels) {
 		if (!GPU_non_power_of_two_support() && (w != tex->w || h != tex->h || depth != tex->depth)) {
 			/* clear first to avoid unitialized pixels */
-			float *zero= MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
+			float *zero= (float*)MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
 			glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->depth, format, type, zero);
 			MEM_freeN(zero);
 		}
@@ -698,7 +705,7 @@
 		return NULL;
 	}
 
-	tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
+	tex = (GPUTexture*)MEM_callocN(sizeof(GPUTexture), "GPUTexture");
 	tex->bindcode = bindcode;
 	tex->number = -1;
 	tex->refcount = 1;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list