[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49966] branches/soc-2012-swiss_cheese/ source/blender/gpu: Adding implementation for implementation for glsl.

Alexander Kuznetsov kuzsasha at gmail.com
Fri Aug 17 21:29:31 CEST 2012


Revision: 49966
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49966
Author:   alexk
Date:     2012-08-17 19:29:31 +0000 (Fri, 17 Aug 2012)
Log Message:
-----------
Adding implementation for implementation for glsl. Maybe, there is a reason to share some code between gl11 and glsl (with gpu_object).

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_internal.h

Added Paths:
-----------
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_glsl.c

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt	2012-08-17 19:23:08 UTC (rev 49965)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt	2012-08-17 19:29:31 UTC (rev 49966)
@@ -54,6 +54,7 @@
 	intern/gpu_draw.c
 	intern/gpu_extensions.c
 	intern/gpu_immediate.c
+	intern/gpu_immediate_glsl.c
 	intern/gpu_immediate_gl11.c
 	intern/gpu_immediate_vbo.c
 	intern/gpu_lighting.c

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c	2012-08-17 19:23:08 UTC (rev 49965)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c	2012-08-17 19:29:31 UTC (rev 49966)
@@ -30,7 +30,8 @@
 */
 
 #include "gpu_immediate_internal.h"
-
+#include "GPU_extensions.h"
+#include "gpu_object_gles.h"
 #include "MEM_guardedalloc.h"
 
 #include <math.h>
@@ -38,6 +39,7 @@
 
 
 
+
 /* global symbol needed because the immediate drawing functons are inline */
 GPUimmediate *restrict GPU_IMMEDIATE = NULL;
 
@@ -198,6 +200,28 @@
 	immediate->copyVertex   = gpu_copy_vertex;
 	immediate->appendClientArrays = gpu_append_client_arrays;
 
+
+	if(!GPU_GLTYPE_FIXED_ENABLED)
+	{
+		immediate->lockBuffer          = gpu_lock_buffer_glsl;
+		immediate->unlockBuffer        = gpu_unlock_buffer_glsl;
+		immediate->beginBuffer         = gpu_begin_buffer_glsl;
+		immediate->endBuffer           = gpu_end_buffer_glsl;
+		immediate->shutdownBuffer      = gpu_shutdown_buffer_glsl;
+		immediate->currentColor        = gpu_current_color_glsl;
+		immediate->getCurrentColor     = gpu_get_current_color_glsl;
+		immediate->currentNormal       = gpu_current_normal_glsl;
+		immediate->indexBeginBuffer    = gpu_index_begin_buffer_glsl;
+		immediate->indexShutdownBuffer = gpu_index_shutdown_buffer_glsl;
+		immediate->indexEndBuffer      = gpu_index_end_buffer_glsl;
+		immediate->drawElements        = gpu_draw_elements_glsl;
+		immediate->drawRangeElements   = gpu_draw_range_elements_glsl;
+		
+		gpu_quad_elements_init();
+		
+		
+	}
+	// else {
 	//	immediate->lockBuffer          = gpu_lock_buffer_vbo;
 	//	immediate->beginBuffer         = gpu_begin_buffer_vbo;
 	//	immediate->endBuffer           = gpu_end_buffer_vbo;
@@ -211,8 +235,9 @@
 	//	immediate->indexShutdownBuffer = gpu_index_shutdown_buffer_vbo;
 	//	immediate->drawElements        = gpu_draw_elements_vbo;
 	//	immediate->drawRangeElements   = gpu_draw_range_elements_vbo;
-	//}
-	//else {
+	//}	
+	#ifndef GLES
+	else {
 		immediate->lockBuffer          = gpu_lock_buffer_gl11;
 		immediate->unlockBuffer        = gpu_unlock_buffer_gl11;
 		immediate->beginBuffer         = gpu_begin_buffer_gl11;
@@ -226,7 +251,8 @@
 		immediate->indexEndBuffer      = gpu_index_end_buffer_gl11;
 		immediate->drawElements        = gpu_draw_elements_gl11;
 		immediate->drawRangeElements   = gpu_draw_range_elements_gl11;
-	//}
+	}
+	#endif
 #if GPU_SAFETY
 	calc_last_texture(immediate);
 #endif

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c	2012-08-17 19:23:08 UTC (rev 49965)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c	2012-08-17 19:29:31 UTC (rev 49966)
@@ -28,7 +28,7 @@
 /** \file blender/gpu/intern/gpu_immediate_gl11.c
 *  \ingroup gpu
 */
-
+#ifndef GLES
 #include "gpu_immediate_internal.h"
 #include "GPU_matrix.h"
 #include "MEM_guardedalloc.h"
@@ -449,3 +449,4 @@
 
 	GPU_CHECK_NO_ERROR();
 }
+#endif
\ No newline at end of file

Added: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_glsl.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_glsl.c	                        (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_glsl.c	2012-08-17 19:29:31 UTC (rev 49966)
@@ -0,0 +1,540 @@
+/*
+* ***** 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) 2012 Blender Foundation.
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Alexandr Kuznetsov, Jason Wilkins.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+/** \file blender/gpu/intern/gpu_immediate_glsl.c
+*  \ingroup gpu
+*/
+#include "gpu_immediate_internal.h"
+#include "GPU_matrix.h"
+#include "MEM_guardedalloc.h"
+#include "BLI_math_vector.h"
+
+#include <string.h>
+
+#include "GPU_functions.h"
+#include "gpu_glew.h"
+#include "gpu_object_gles.h"
+#include "GPU_object.h"
+#include REAL_GL_MODE
+
+typedef struct bufferDataGLSL {
+	size_t   size;
+	GLubyte* ptr;
+} bufferDataGLSL;
+
+typedef struct stateDataGLSL {
+	GLfloat curcolor[4];
+	GLfloat curnormal[3];
+} stateDataGLSL;
+
+stateDataGLSL stateData = {{1, 1, 1, 1}, {0, 0, 1}};
+
+static void allocate(void)
+{
+	size_t newSize;
+	bufferDataGLSL* bufferData;
+
+	GPU_IMMEDIATE->stride = gpu_calc_stride();
+
+	newSize = (size_t)(GPU_IMMEDIATE->stride * GPU_IMMEDIATE->maxVertexCount);
+
+	if (GPU_IMMEDIATE->bufferData) {
+		bufferData = GPU_IMMEDIATE->bufferData;
+
+		if (newSize > bufferData->size) {
+			bufferData->ptr = MEM_reallocN(bufferData->ptr, newSize);
+			GPU_ASSERT(bufferData->ptr != NULL);
+
+			bufferData->size = newSize;
+		}
+	}
+	else {
+		bufferData = MEM_mallocN(
+			sizeof(bufferDataGLSL),
+			"bufferDataGLSL");
+
+		GPU_ASSERT(bufferData != NULL);
+
+		GPU_IMMEDIATE->bufferData = bufferData;
+
+		bufferData->ptr = MEM_mallocN(newSize, "bufferDataGLSL->ptr");
+		GPU_ASSERT(bufferData->ptr != NULL);
+
+		bufferData->size = newSize;
+	}
+}
+
+
+
+static void setup(void)
+{
+	size_t i;
+	size_t offset;
+	bufferDataGLSL* bufferData = GPU_IMMEDIATE->bufferData;
+
+	offset = 0;
+glEnable(GL_BLEND);
+glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
+	GPU_CHECK_NO_ERROR();
+
+	/* setup vertex arrays
+	   Assume that vertex arrays have been disabled for everything
+	   and only enable what is needed */
+	   if (GPU_IMMEDIATE->format.textureUnitCount == 0)
+	   {
+	   		gpu_set_shader_es(&shader_main_info, 0);
+	   		
+	   		gpu_glUseProgram(shader_main);
+		} else
+		{
+	   		gpu_set_shader_es(&shader_alphatexture_info, 0);
+	   		
+	   		gpu_glUseProgram(shader_alphatexture);		
+		
+		}
+		
+		
+
+	/* vertex */
+
+gpugameobj.gpuVertexPointer(GPU_IMMEDIATE->format.vertexSize,
+		GL_FLOAT,
+		GPU_IMMEDIATE->stride,
+		bufferData->ptr + offset);
+
+	offset += (size_t)(GPU_IMMEDIATE->format.vertexSize) * sizeof(GLfloat);
+
+
+	/* normal */
+
+	if (GPU_IMMEDIATE->format.normalSize != 0) {
+	gpugameobj.gpuNormalPointer(
+			GL_FLOAT,
+			GPU_IMMEDIATE->stride,
+			bufferData->ptr + offset);
+
+		offset += 3 * sizeof(GLfloat);
+
+	}
+
+	/* color */
+
+	if (GPU_IMMEDIATE->format.colorSize != 0) {
+	gpugameobj.gpuColorPointer(
+			4 * sizeof(GLubyte),
+			GL_UNSIGNED_BYTE,
+			GPU_IMMEDIATE->stride,
+			bufferData->ptr + offset);
+
+		/* 4 bytes are always reserved for color, for efficient memory alignment */
+		offset += 4 * sizeof(GLubyte);
+
+
+	} else 
+	{
+		/*gpugameobj.gpuColorPointer(
+			4 * sizeof(GLubyte),
+			GL_UNSIGNED_BYTE,
+			GPU_IMMEDIATE->stride,
+			bufferData->ptr + offset);*/
+			
+			
+			
+			//gpugameobj.gpuColorSet(	stateData.curcolor);
+			}
+
+	/* texture coordinate */
+
+	if (GPU_IMMEDIATE->format.textureUnitCount == 1) {
+		gpugameobj.gpuTexCoordPointer(
+			GPU_IMMEDIATE->format.texCoordSize[0],
+			GL_FLOAT,
+			GPU_IMMEDIATE->stride,
+			bufferData->ptr + offset);
+
+		offset +=
+			(size_t)(GPU_IMMEDIATE->format.texCoordSize[0]) * sizeof(GLfloat);
+
+	}
+	else if (GPU_IMMEDIATE->format.textureUnitCount > 1) {
+		/*for (i = 0; i < GPU_IMMEDIATE->format.textureUnitCount; i++) {
+			glClientActiveTexture(GPU_IMMEDIATE->format.textureUnitMap[i]);
+
+			glTexCoordPointer(
+				GPU_IMMEDIATE->format.texCoordSize[i],
+				GL_FLOAT,
+				GPU_IMMEDIATE->stride,
+				bufferData->ptr + offset);
+
+			offset +=
+				(size_t)(GPU_IMMEDIATE->format.texCoordSize[i]) * sizeof(GLfloat);
+
+		//	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+		}*/
+
+	//	glClientActiveTexture(GL_TEXTURE0);
+	}
+
+	/* float vertex attribute */
+
+	for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) {
+		gpu_glVertexAttribPointer(
+			GPU_IMMEDIATE->format.attribIndexMap_f[i],
+			GPU_IMMEDIATE->format.attribSize_f[i],
+			GL_FLOAT,
+			GPU_IMMEDIATE->format.attribNormalized_f[i],
+			GPU_IMMEDIATE->stride,
+			bufferData->ptr + offset);
+
+		offset +=
+			(size_t)(GPU_IMMEDIATE->format.attribSize_f[i]) * sizeof(GLfloat);
+
+		gpu_glEnableVertexAttribArray(
+			GPU_IMMEDIATE->format.attribIndexMap_f[i]);
+	}
+
+	/* byte vertex attribute */
+
+	for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) {
+		if (GPU_IMMEDIATE->format.attribSize_ub[i] > 0) {
+			glVertexAttribPointer(
+				GPU_IMMEDIATE->format.attribIndexMap_ub[i],
+				GPU_IMMEDIATE->format.attribSize_ub[i],
+				GL_UNSIGNED_BYTE,
+				GPU_IMMEDIATE->format.attribNormalized_ub[i],
+				GPU_IMMEDIATE->stride,
+				bufferData->ptr + offset);
+
+			offset += 4 * sizeof(GLubyte);
+
+			glEnableVertexAttribArray(
+				GPU_IMMEDIATE->format.attribIndexMap_ub[i]);
+		}
+	}
+
+	GPU_CHECK_NO_ERROR();
+}
+
+typedef struct indexbufferDataGLSL {
+	void*  ptr;
+	size_t size;
+} indexbufferDataGLSL;
+
+static void allocateIndex(void)
+{
+	if (GPU_IMMEDIATE->index) {
+		indexbufferDataGLSL* bufferData;
+		GPUindex* index;
+		size_t newSize;
+
+		index = GPU_IMMEDIATE->index;
+		newSize = index->maxIndexCount * sizeof(GLuint);
+
+		if (index->bufferData) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list