[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47030] branches/soc-2012-swiss_cheese/ source/blender: misc. fixes and optimizations of gpuImmediate
Jason Wilkins
Jason.A.Wilkins at gmail.com
Sat May 26 01:39:00 CEST 2012
Revision: 47030
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47030
Author: jwilkins
Date: 2012-05-25 23:39:00 +0000 (Fri, 25 May 2012)
Log Message:
-----------
misc. fixes and optimizations of gpuImmediate
* Need to know the lock count of gpuImmediate, not just if its locked
* Use ClientActiveTexture before TexCoordPointer, not ActiveTexture
* Only set blending state one when drawing text
* Do not use gpuBegin right away because the texture hasn't been loaded yet
* The maximum number of texture units calculation depends on the GL version
Modified Paths:
--------------
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_inline.h
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c 2012-05-25 23:35:29 UTC (rev 47029)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c 2012-05-25 23:39:00 UTC (rev 47030)
@@ -483,7 +483,7 @@
void BLF_draw_lock(void)
{
- if (!gpuImmediateIsLocked()) {
+ if (gpuImmediateLockCount() == 0) {
GLint texCoordSizes[1] = { 2 };
GLint texUnitMap[1];
@@ -496,14 +496,23 @@
gpuImmediateFloatAttribCount(0);
gpuImmediateUbyteAttribCount(0);
- gpuImmediateLock();
+ /* one time GL setup */
+
+ glEnable(GL_BLEND);
+ glEnable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+
+ gpuImmediateLock();
}
void BLF_draw_unlock(void)
{
- if (gpuImmediateIsLocked()) {
- gpuImmediateUnlock();
+ gpuImmediateUnlock();
+
+ if (gpuImmediateLockCount() == 0) {
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
}
}
@@ -514,10 +523,6 @@
* in BLF_position (old ui_rasterpos_safe).
*/
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
/* Save the current matrix mode. */
glGetIntegerv(GL_MATRIX_MODE, mode);
@@ -551,7 +556,7 @@
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
BLF_draw_lock();
- gpuBegin(GL_QUADS);
+ /* gpuBegin not called here because texture still needs binding */
}
static void blf_draw__end(GLint mode, GLint param)
@@ -571,9 +576,6 @@
if (mode != GL_MODELVIEW)
glMatrixMode(mode);
-
- glDisable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
}
void BLF_draw(int fontid, const char *str, size_t len)
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-25 23:35:29 UTC (rev 47029)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-25 23:39:00 UTC (rev 47030)
@@ -367,7 +367,7 @@
float dx, dx1;
float y1, y2;
float xo, yo;
- int need_begin = 0;
+ int need_begin = font->tex_bind_state == -1;
if (g->width == 0 || g->height == 0) {
return TRUE;
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-05-25 23:35:29 UTC (rev 47029)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c 2012-05-25 23:39:00 UTC (rev 47030)
@@ -122,14 +122,12 @@
}
}
- if (GPU_IMMEDIATE->lockCount > 0) {
- GPU_IMMEDIATE->lockCount--;
- }
+ GPU_IMMEDIATE->lockCount--;
}
-GLboolean gpuImmediateIsLocked(void)
+GLint gpuImmediateLockCount(void)
{
assert(GPU_IMMEDIATE);
@@ -137,23 +135,27 @@
return GL_FALSE;
}
- return GPU_IMMEDIATE->lockCount > 0;
+ return GPU_IMMEDIATE->lockCount;
}
static void calc_last_texture(GPUimmediate* immediate)
{
- GLint maxTextureCoords;
- GLint maxCombinedTextureImageUnits;
+ GLint maxTextureCoords = 1;
+ GLint maxCombinedTextureImageUnits = 0;
- glGetIntegerv(
- GL_MAX_TEXTURE_COORDS,
- &maxTextureCoords);
+ if (GLEW_VERSION_1_3 || GLEW_ARB_multitexture) {
+ glGetIntegerv(
+ GL_MAX_TEXTURE_COORDS,
+ &maxTextureCoords);
+ }
- glGetIntegerv(
- GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
- &maxCombinedTextureImageUnits);
+ if (GLEW_VERSION_2_0) {
+ glGetIntegerv(
+ GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
+ &maxCombinedTextureImageUnits);
+ }
immediate->lastTexture =
GL_TEXTURE0 + MAX2(maxTextureCoords, maxCombinedTextureImageUnits) - 1;
@@ -253,18 +255,16 @@
glGetFloatv(GL_CURRENT_NORMAL, GPU_IMMEDIATE->normal);
}
- if (GPU_IMMEDIATE->textureUnitCount != 0) {
- GLint savedActiveTexture;
- glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
-
+ if (GPU_IMMEDIATE->textureUnitCount == 1) {
+ glGetFloatv(GL_CURRENT_TEXTURE_COORDS, GPU_IMMEDIATE->texCoord[0]);
+ }
+ else if (GPU_IMMEDIATE->textureUnitCount > 1) {
for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
- glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
- glGetFloatv(
- GL_CURRENT_TEXTURE_COORDS,
- GPU_IMMEDIATE->texCoord[i]);
+ glClientActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
+ glGetFloatv(GL_CURRENT_TEXTURE_COORDS, GPU_IMMEDIATE->texCoord[i]);
}
- glActiveTexture(savedActiveTexture);
+ glClientActiveTexture(GL_TEXTURE0);
}
for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
@@ -295,7 +295,6 @@
Copies GPU_IMMEDIATE state back into the current OpenGL context */
void gpu_legacy_put_state(void)
{
- GLint savedActiveTexture;
size_t i;
GPU_CHECK_NO_BEGIN();
@@ -308,15 +307,16 @@
glNormal3fv(GPU_IMMEDIATE->normal);
}
- if (GPU_IMMEDIATE->textureUnitCount != 0) {
- glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
-
+ if (GPU_IMMEDIATE->textureUnitCount == 1) {
+ glTexCoord4fv(GPU_IMMEDIATE->texCoord[0]);
+ }
+ else if (GPU_IMMEDIATE->textureUnitCount > 1) {
for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
- glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
+ glClientActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
glTexCoord4fv(GPU_IMMEDIATE->texCoord[i]);
}
- glActiveTexture(savedActiveTexture);
+ glClientActiveTexture(GL_TEXTURE0);
}
for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
@@ -505,13 +505,13 @@
GPU_CHECK_NO_LOCK();
- for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) {
GLboolean sizeOK = sizes[i] > 0 && sizes[i] <= 4; //-V112
assert(sizeOK);
if (sizeOK) {
- GPU_IMMEDIATE->attribSize_f[i] = sizes[i];
+ GPU_IMMEDIATE->attribSize_ub[i] = sizes[i];
}
}
}
@@ -524,8 +524,8 @@
GPU_CHECK_NO_LOCK();
- for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
- GPU_IMMEDIATE->attribIndexMap_f[i] = map[i];
+ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) {
+ GPU_IMMEDIATE->attribIndexMap_ub[i] = map[i];
}
}
Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h 2012-05-25 23:35:29 UTC (rev 47029)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h 2012-05-25 23:39:00 UTC (rev 47030)
@@ -54,6 +54,33 @@
+#ifndef GPU_SAFETY
+#define GPU_SAFETY 1
+#endif
+
+#if GPU_SAFETY
+
+#define GPU_SAFE_RETURN(test) \
+ assert(test); \
+ if (!(test)) { \
+ return; \
+ } \
+
+#endif
+
+#define GPU_CHECK_IMMEDIATE() \
+ GPU_SAFE_RETURN(GPU_IMMEDIATE);
+
+#define GPU_CHECK_NO_BEGIN() \
+ GPU_CHECK_IMMEDIATE(); \
+ GPU_SAFE_RETURN(!(GPU_IMMEDIATE->buffer));
+
+#define GPU_CHECK_NO_LOCK() \
+ GPU_CHECK_NO_BEGIN(); \
+ GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0);
+
+
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -81,7 +108,7 @@
void gpuImmediateLock(void);
void gpuImmediateUnlock(void);
-GLboolean gpuImmediateIsLocked(void);
+GLint gpuImmediateLockCount(void);
@@ -147,44 +174,20 @@
-#define GPU_CHECK_IMMEDIATE() \
- assert(GPU_IMMEDIATE); \
- \
- if (!GPU_IMMEDIATE) { \
- return; \
- }
-
-#define GPU_CHECK_NO_BEGIN() \
- GPU_CHECK_IMMEDIATE(); \
- assert(!(GPU_IMMEDIATE->buffer)); \
- \
- if (GPU_IMMEDIATE->buffer) { \
- return; \
- }
-
-#define GPU_CHECK_NO_LOCK() \
- GPU_CHECK_NO_BEGIN(); \
- assert(GPU_IMMEDIATE->lockCount == 0); \
- \
- if (GPU_IMMEDIATE->lockCount != 0) { \
- return; \
- }
-
-
-
+#ifndef GPU_LEGACY_INTEROP
#define GPU_LEGACY_INTEROP 1
+#endif
-#ifdef GPU_LEGACY_INTEROP
+#if GPU_LEGACY_INTEROP
void gpu_legacy_get_state(void);
void gpu_legacy_put_state(void);
+#else
+#define gpu_legacy_get_state() ((void)0)
+#define gpu_legacy_put_state() ((void)0)
#endif
-void gpu_vector_copy(void);
-
-
-
#ifdef __cplusplus
}
#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-05-25 23:35:29 UTC (rev 47029)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c 2012-05-25 23:39:00 UTC (rev 47030)
@@ -86,7 +86,6 @@
{
size_t i;
size_t offset;
- GLint savedActiveTexture;
bufferDataGL11* bufferData = (bufferDataGL11*)(GPU_IMMEDIATE->bufferData);
/* Assume that vertex arrays have been disabled for everything
@@ -139,24 +138,35 @@
/* texture coordinate */
- glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
-
- for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
- glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
-
+ if (GPU_IMMEDIATE->textureUnitCount == 1) {
glTexCoordPointer(
- GPU_IMMEDIATE->texCoordSize[i],
+ GPU_IMMEDIATE->texCoordSize[0],
GL_FLOAT,
bufferData->stride,
bufferData->ptr + offset);
- offset += (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat);
+ offset += (size_t)(GPU_IMMEDIATE->texCoordSize[0]) * sizeof(GLfloat);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
+ else if (GPU_IMMEDIATE->textureUnitCount > 1) {
+ for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) {
+ glClientActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]);
- glActiveTexture(savedActiveTexture);
+ glTexCoordPointer(
+ GPU_IMMEDIATE->texCoordSize[i],
+ GL_FLOAT,
+ bufferData->stride,
+ bufferData->ptr + offset);
+ offset += (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+
+ glClientActiveTexture(GL_TEXTURE0);
+ }
+
/* float vertex attribute */
for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) {
@@ -256,16 +266,16 @@
/* texture coordinate */
- if (GPU_IMMEDIATE->textureUnitCount != 0) {
- GLint savedActiveTexture;
- glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture);
-
+ if (GPU_IMMEDIATE->textureUnitCount == 1) {
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list