[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46917] branches/soc-2012-swiss_cheese/ source/blender/gpu: gpuImmediate: A simplified replacement for OpenGL immediate mode.
Jason Wilkins
Jason.A.Wilkins at gmail.com
Wed May 23 04:11:43 CEST 2012
Revision: 46917
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46917
Author: jwilkins
Date: 2012-05-23 02:11:38 +0000 (Wed, 23 May 2012)
Log Message:
-----------
gpuImmediate: A simplified replacement for OpenGL immediate mode.
This is an initial commit of the API. I have not converted any code to use this yet. There may be problems with use of the "restrict" keyword because I was not able to test it.
Modified Paths:
--------------
branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
Added Paths:
-----------
branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h
Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-05-22 23:44:17 UTC (rev 46916)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-05-23 02:11:38 UTC (rev 46917)
@@ -49,6 +49,7 @@
intern/gpu_codegen.c
intern/gpu_draw.c
intern/gpu_extensions.c
+ intern/gpu_immediate.c
intern/gpu_material.c
shaders/gpu_shader_material.glsl.c
@@ -59,10 +60,12 @@
shaders/gpu_shader_vsm_store_vert.glsl.c
GPU_buffers.h
+ GPU_compatibility.h
GPU_draw.h
GPU_extensions.h
GPU_material.h
intern/gpu_codegen.h
+ intern/gpu_immediate.h
)
if(WITH_MOD_SMOKE)
Added: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h 2012-05-23 02:11:38 UTC (rev 46917)
@@ -0,0 +1,45 @@
+/*
+ * ***** 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): Jason Wilkins, Alexandr Kuznetsov
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_compatibility.h
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_COMPATIBILITY_H__
+#define __GPU_COMPATIBILITY_H__
+
+#include "intern/GPU_IMMEDIATE.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GPU_COMPATIBILITY_H_ */
Property changes on: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c 2012-05-23 02:11:38 UTC (rev 46917)
@@ -0,0 +1,662 @@
+/*
+* ***** 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): Jason Wilkins.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+/** \file blender/gpu/intern/GPU_IMMEDIATE.c
+* \ingroup gpu
+*/
+
+#include "GPU_IMMEDIATE.h"
+
+#include "MEM_guardedalloc.h"
+
+
+
+static GLsizei calcStride()
+{
+ size_t i;
+ size_t stride = 0;
+
+ /* vertex */
+
+ if (GPU_IMMEDIATE->vertexSize > 0) {
+ stride += (size_t)(GPU_IMMEDIATE->vertexSize) * sizeof(GLfloat);
+ }
+
+ /* normal */
+
+ if (GPU_IMMEDIATE->normalSize == 3) {
+ stride += 3 * sizeof(GLfloat);
+ }
+
+ /* color */
+
+ if (GPU_IMMEDIATE->colorSize > 0) {
+ /* 4 bytes are always reserved for color, for efficient memory alignment */
+ stride += 4 * sizeof(GLubyte);
+ }
+
+ /* texture coordinate */
+
+ for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
+ if (GPU_IMMEDIATE->texCoordSize[i] > 0) {
+ stride +=
+ (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat);
+ }
+ }
+
+ /* float vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
+ if (GPU_IMMEDIATE->attribSize_f[i] > 0) {
+ stride +=
+ (size_t)(GPU_IMMEDIATE->attribSize_f[i]) * sizeof(GLfloat);
+ }
+ }
+
+ /* byte vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) {
+ if (GPU_IMMEDIATE->attribSize_ub[i] > 0) {
+ stride +=
+ (size_t)(GPU_IMMEDIATE->attribSize_ub[i]) * sizeof(GLfloat);
+ }
+ }
+
+ return (GLsizei)stride;
+}
+
+
+
+typedef struct bufferDataVBO {
+ GLint bufferObject;
+} bufferDataVBO;
+
+void beginBufferVBO(void)
+{
+}
+
+void endBufferVBO(void)
+{
+}
+
+void shutdownBufferVBO(GPUimmediate *restrict immediate)
+{
+}
+
+
+
+typedef struct bufferDataGL11 {
+ size_t size;
+ GLubyte* ptr;
+ GLsizei stride;
+} bufferDataGL11;
+
+void beginBufferGL11(void)
+{
+ const GLsizei stride = calcStride();
+ bufferDataGL11* bufferData;
+ size_t newSize;
+ size_t offset;
+ GLint savedActiveTexture;
+ size_t i;
+
+ newSize = (size_t)(stride * GPU_IMMEDIATE->maxVertexCount);
+
+ if (GPU_IMMEDIATE->bufferData) {
+ bufferData = (bufferDataGL11*)(GPU_IMMEDIATE->bufferData);
+
+ if (newSize > bufferData->size) {
+ MEM_reallocN(bufferData->ptr, newSize);
+ bufferData->size = newSize;
+ }
+ }
+ else {
+ bufferData =
+ (bufferDataGL11*)MEM_mallocN(
+ sizeof(bufferDataGL11),
+ "bufferDataGL11");
+
+ assert(bufferData);
+
+ bufferData->ptr = MEM_mallocN(newSize, "bufferDataGL11->ptr");
+ assert(bufferData->ptr);
+
+ bufferData->size = newSize;
+ }
+
+ bufferData->stride = stride;
+
+ /* Assume that vertex arrays have been disabled for everything
+ and only enable what is needed */
+
+ offset = 0;
+
+ /* vertex */
+
+ if (GPU_IMMEDIATE->vertexSize > 0) {
+ glVertexPointer(
+ GPU_IMMEDIATE->vertexSize,
+ GL_FLOAT,
+ stride,
+ bufferData->ptr + offset);
+
+ offset += (size_t)(GPU_IMMEDIATE->vertexSize) * sizeof(GLfloat);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ }
+
+ /* normal */
+
+ if (GPU_IMMEDIATE->normalSize == 3) {
+ glNormalPointer(
+ GL_FLOAT,
+ stride,
+ bufferData->ptr + offset);
+
+ offset += 3 * sizeof(GLfloat);
+
+ glEnableClientState(GL_NORMAL_ARRAY);
+ }
+
+ /* color */
+
+ if (GPU_IMMEDIATE->colorSize > 0) {
+ glColorPointer(
+ GPU_IMMEDIATE->colorSize,
+ GL_UNSIGNED_BYTE,
+ stride,
+ bufferData->ptr + offset);
+
+ /* 4 bytes are always reserved for color, for efficient memory alignment */
+ offset += 4 * sizeof(GLubyte);
+
+ glEnableClientState(GL_COLOR_ARRAY);
+ }
+
+ /* texture coordinate */
+
+ glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
+
+ for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
+ if (GPU_IMMEDIATE->texCoordSize[i] > 0) {
+ glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
+
+ glTexCoordPointer(
+ GPU_IMMEDIATE->texCoordSize[i],
+ GL_FLOAT,
+ stride,
+ bufferData->ptr + offset);
+
+ offset +=
+ (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ }
+
+ glActiveTexture(savedActiveTexture);
+
+ /* float vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
+ if (GPU_IMMEDIATE->attribSize_f[i] > 0) {
+ glVertexAttribPointer(
+ GPU_IMMEDIATE->attribIndexMap_f[i],
+ GPU_IMMEDIATE->attribSize_f[i],
+ GL_FLOAT,
+ GPU_IMMEDIATE->attribNormalized_f[i],
+ stride,
+ bufferData->ptr + offset);
+
+ offset +=
+ (size_t)(GPU_IMMEDIATE->attribSize_f[i]) * sizeof(GLfloat);
+
+ glEnableVertexAttribArray(
+ GPU_IMMEDIATE->attribIndexMap_f[i]);
+ }
+ }
+
+ /* byte vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) {
+ if (GPU_IMMEDIATE->attribSize_ub[i] > 0) {
+ glVertexAttribPointer(
+ GPU_IMMEDIATE->attribIndexMap_ub[i],
+ GPU_IMMEDIATE->attribSize_ub[i],
+ GL_FLOAT,
+ GPU_IMMEDIATE->attribNormalized_ub[i],
+ stride,
+ bufferData->ptr + offset);
+
+ offset +=
+ (size_t)(GPU_IMMEDIATE->attribSize_ub[i]) * sizeof(GLfloat);
+
+ glEnableVertexAttribArray(
+ GPU_IMMEDIATE->attribIndexMap_ub[i]);
+ }
+ }
+
+ GPU_IMMEDIATE->buffer = bufferData->ptr;
+ GPU_IMMEDIATE->bufferData = bufferData;
+}
+
+void endBufferGL11(void)
+{
+ GLint savedActiveTexture;
+ size_t i;
+
+ glDrawArrays(GPU_IMMEDIATE->mode, 0, GPU_IMMEDIATE->count);
+
+ /* Disable any arrays that were used so that everything is off again. */
+
+ /* vertex */
+
+ if (GPU_IMMEDIATE->vertexSize > 0) {
+ glDisableClientState(GL_VERTEX_ARRAY);
+ }
+
+ /* normal */
+
+ if (GPU_IMMEDIATE->normalSize == 3) {
+ glDisableClientState(GL_NORMAL_ARRAY);
+ }
+
+ /* color */
+
+ if (GPU_IMMEDIATE->colorSize > 0) {
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ /* texture coordinate */
+
+ glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
+
+ for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
+ if (GPU_IMMEDIATE->texCoordSize[i] > 0) {
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ }
+
+ glActiveTexture(savedActiveTexture);
+
+ /* float vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
+ if (GPU_IMMEDIATE->attribSize_f[i] > 0) {
+ glDisableVertexAttribArray(
+ GPU_IMMEDIATE->attribIndexMap_f[i]);
+ }
+ }
+
+ /* byte vertex attribute */
+
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) {
+ if (GPU_IMMEDIATE->attribSize_ub[i] > 0) {
+ glDisableVertexAttribArray(
+ GPU_IMMEDIATE->attribIndexMap_ub[i]);
+ }
+ }
+}
+
+void shutdownBufferGL11(GPUimmediate *restrict immediate)
+{
+ if (immediate->bufferData) {
+ bufferDataGL11* bufferData =
+ (bufferDataGL11*)(immediate->bufferData);
+
+ if (bufferData->ptr) {
+ MEM_freeN(bufferData->ptr);
+ bufferData->ptr = NULL;
+ }
+
+ MEM_freeN(immediate->bufferData);
+ immediate->bufferData = NULL;
+ }
+}
+
+
+
+GPUimmediate* gpuNewImmediate(void)
+{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list