[Bf-blender-cvs] [bc4b72e] GPU_data_request: add support for non-generic vertex attribs
Mike Erwin
noreply at git.blender.org
Tue Mar 31 07:26:26 CEST 2015
Commit: bc4b72eabd2d8aaebbc15d9a38000939a015cfdf
Author: Mike Erwin
Date: Tue Mar 31 01:25:43 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rBbc4b72eabd2d8aaebbc15d9a38000939a015cfdf
add support for non-generic vertex attribs
for easier integration into legacy GL usage.
Instead of specifying generic arrays with a name string, choose any or
all of these:
GL_VERTEX_ARRAY
GL_NORMAL_ARRAY
GL_COLOR_ARRAY
GL_TEXTURE_COORD_ARRAY
Generic attribs are still there for when we move to shader-based
drawing / a newer GL.
===================================================================
M source/blender/gpu/GPUx_vbo.h
M source/blender/gpu/intern/gpux_vbo.c
===================================================================
diff --git a/source/blender/gpu/GPUx_vbo.h b/source/blender/gpu/GPUx_vbo.h
index b9d033a..0e9b62c 100644
--- a/source/blender/gpu/GPUx_vbo.h
+++ b/source/blender/gpu/GPUx_vbo.h
@@ -8,6 +8,7 @@
/* ^-- for GLenum (and if you're including this file, you're probably calling OpenGL anyway) */
#include <stdbool.h>
+#define GENERIC_ATTRIB false
#define TRUST_NO_ONE true
#define PRINT false
@@ -30,7 +31,13 @@ unsigned vertex_ct(const VertexBuffer*);
void attrib_print(const VertexBuffer*, unsigned attrib_num);
#endif /* PRINT */
-void specify_attrib(VertexBuffer*, unsigned attrib_num, const char *name, GLenum comp_type, unsigned comp_ct, VertexFetchMode);
+void specify_attrib(VertexBuffer*, unsigned attrib_num,
+#if GENERIC_ATTRIB
+ const char *name, /* use any legal GLSL identifier */
+#else
+ GLenum attrib_array, /* use GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, etc. */
+#endif
+ GLenum comp_type, unsigned comp_ct, VertexFetchMode);
/* set value of single attribute of single vertex
* incoming data must be of same type & size for this attribute */
diff --git a/source/blender/gpu/intern/gpux_vbo.c b/source/blender/gpu/intern/gpux_vbo.c
index 22d8542..e380f23 100644
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@ -29,7 +29,11 @@ typedef struct {
unsigned sz; /* size in bytes, 1 to 16 */
unsigned stride; /* natural stride in bytes, 1 to 16 */
VertexFetchMode fetch_mode;
+#if GENERIC_ATTRIB
char *name;
+#else
+ GLenum array;
+#endif
void *data;
/* TODO: more storage options
* - single VBO for all attribs (sequential)
@@ -96,7 +100,27 @@ void attrib_print(const VertexBuffer *buff, unsigned attrib_num)
/* use GLSL names when they exist, or type_count for the others */
const char *singular[] = {"byte","ubyte","short","ushort","int","uint","float"};
const char *plural[] = {"byte_","ubyte_","short_","ushort_","ivec","uint_","vec"};
+#if GENERIC_ATTRIB
const char *var_name = a->name ? a->name : "foo";
+#else
+ const char* var_name = "foo";
+ switch (a->array) {
+ case GL_VERTEX_ARRAY:
+ var_name = "gl_Vertex";
+ break;
+ case GL_NORMAL_ARRAY:
+ var_name = "gl_Normal";
+ break;
+ case GL_COLOR_ARRAY:
+ var_name = "gl_Color";
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ var_name = "gl_MultiTexCoord0";
+ break;
+ default:
+ ;
+ }
+#endif
unsigned type_idx = a->comp_type - GL_BYTE;
if (a->comp_ct == 1)
printf("attrib %s %s = {\n", singular[type_idx], var_name);
@@ -140,7 +164,9 @@ void vertex_buffer_discard(VertexBuffer *buff)
if (a->vbo_id)
glDeleteBuffers(1, &a->vbo_id);
#endif /* USE_VBO */
+#if GENERIC_ATTRIB
free(a->name);
+#endif /* GENERIC_ATTRIB */
free(a->data);
}
#if USE_VAO
@@ -161,7 +187,13 @@ static unsigned attrib_total_size(const VertexBuffer *buff, unsigned attrib_num)
return (buff->vertex_ct - 1) * attrib->stride + attrib->sz;
}
-void specify_attrib(VertexBuffer *buff, unsigned attrib_num, const char *name, GLenum comp_type, unsigned comp_ct, VertexFetchMode fetch_mode)
+void specify_attrib(VertexBuffer *buff, unsigned attrib_num,
+#if GENERIC_ATTRIB
+ const char *name,
+#else
+ GLenum attrib_array,
+#endif
+ GLenum comp_type, unsigned comp_ct, VertexFetchMode fetch_mode)
{
#if TRUST_NO_ONE
assert(attrib_num < buff->attrib_ct);
@@ -171,9 +203,52 @@ void specify_attrib(VertexBuffer *buff, unsigned attrib_num, const char *name, G
assert(fetch_mode == KEEP_FLOAT);
else
assert(fetch_mode != KEEP_FLOAT);
+ #if !GENERIC_ATTRIB
+ /* classic (non-generic) attributes each have their quirks
+ * handle below */
+ switch (attrib_array) {
+ case GL_VERTEX_ARRAY:
+ assert(comp_type == GL_FLOAT || comp_type == GL_SHORT || comp_type == GL_INT);
+ if (comp_type != GL_FLOAT)
+ assert(fetch_mode == CONVERT_INT_TO_FLOAT);
+ assert(comp_count >= 2);
+ break;
+ case GL_NORMAL_ARRAY:
+ assert(comp_type == GL_FLOAT || comp_type == GL_BYTE || comp_type == GL_SHORT || comp_type == GL_INT);
+ if (comp_type != GL_FLOAT)
+ assert(fetch_mode == NORMALIZE_INT_TO_FLOAT);
+ assert(comp_count == 3);
+ break;
+ case GL_COLOR_ARRAY:
+ /* any comp_type allowed */
+ if (comp_type != GL_FLOAT)
+ assert(fetch_mode == NORMALIZE_INT_TO_FLOAT);
+ assert(comp_count >= 3);
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ assert(comp_type == GL_FLOAT || comp_type == GL_SHORT || comp_type == GL_INT);
+ if (comp_type != GL_FLOAT)
+ assert(fetch_mode == CONVERT_INT_TO_FLOAT);
+ break;
+ /* not supporting these:
+ * GL_INDEX_ARRAY
+ * GL_SECONDARY_COLOR_ARRAY
+ * GL_EDGE_FLAG_ARRAY
+ * GL_FOG_COORD_ARRAY
+ */
+ default:
+ assert(false); /* bad or unsupported array */
+ }
+ assert(fetch_mode != KEEP_INT); /* glVertexPointer and friends have no int variants */
+ /* TODO: allow only one of each type of array (scan other attribs) */
+ #endif
#endif /* TRUST_NO_ONE */
Attrib *attrib = buff->attribs + attrib_num;
+#if GENERIC_ATTRIB
attrib->name = strdup(name);
+#else
+ attrib->array = attrib_array;
+#endif /* GENERIC_ATTRIB */
attrib->comp_type = comp_type;
attrib->comp_ct = comp_ct;
attrib->sz = attrib_sz(attrib);
@@ -263,8 +338,9 @@ void vertex_buffer_use(VertexBuffer *buff)
for (unsigned a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
Attrib *a = buff->attribs + a_idx;
+#if GENERIC_ATTRIB
glEnableVertexAttribArray(a_idx);
-#if USE_VBO
+ #if USE_VBO
if (a->vbo_id)
glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
else {
@@ -285,7 +361,7 @@ void vertex_buffer_use(VertexBuffer *buff)
case KEEP_INT:
glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, 0);
}
-#else /* client vertex array */
+ #else /* client vertex array */
switch (a->fetch_mode) {
case KEEP_FLOAT:
case CONVERT_INT_TO_FLOAT:
@@ -297,7 +373,40 @@ void vertex_buffer_use(VertexBuffer *buff)
case KEEP_INT:
glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, a->data);
}
-#endif /* USE_VBO */
+ #endif /* USE_VBO */
+#else /* classic (non-generic) attributes */
+ glEnableClientState(a->array);
+ #if USE_VBO
+ if (a->vbo_id)
+ glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ else {
+ glGenBuffers(1, &a->vbo_id);
+ glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ /* fill with delicious data & send to GPU the first time only */
+ glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
+ }
+ const void *data = 0;
+ #else /* client vertex array */
+ const void *data = a->data;
+ #endif /* USE_VBO */
+ switch (a->array) {
+ case GL_VERTEX_ARRAY:
+ glVertexPointer(a->comp_ct, a->comp_type, a->stride, data);
+ break;
+ case GL_NORMAL_ARRAY:
+ glNormalPointer(a->comp_type, a->stride, data);
+ break;
+ case GL_COLOR_ARRAY:
+ glColorPointer(a->comp_ct, a->comp_type, a->stride, data);
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, data);
+ /* TODO: transition to glMultiTexCoordPointer? */
+ break;
+ default:
+ ;
+ }
+#endif /* GENERIC_ATTRIB */
}
#if USE_VBO
@@ -330,6 +439,7 @@ void vertex_buffer_prime(VertexBuffer *buff)
glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
#if USE_VAO
+ #if GENERIC_ATTRIB
switch (a->fetch_mode) {
case KEEP_FLOAT:
case CONVERT_INT_TO_FLOAT:
@@ -341,6 +451,24 @@ void vertex_buffer_prime(VertexBuffer *buff)
case KEEP_INT:
glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, 0);
}
+ #else /* classic (non-generic) attributes */
+ switch (a->array) {
+ case GL_VERTEX_ARRAY:
+ glVertexPointer(a->comp_ct, a->comp_type, a->stride, 0);
+ break;
+ case GL_NORMAL_ARRAY:
+ glNormalPointer(a->comp_type, a->stride, 0);
+ break;
+ case GL_COLOR_ARRAY:
+ glColorPointer(a->comp_ct, a->comp_type, a->stride, 0);
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, 0);
+ break;
+ default:
+ ;
+ }
+ #endif /* GENERIC_ATTRIB */
#endif /* USE_VAO */
}
@@ -364,12 +492,12 @@ void vertex_buffer_use_primed(const VertexBuffer *buff)
#else
for (unsigned a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
Attrib *a = buff->attribs + a_idx;
- glEnableVertexAttribArray(a_idx);
- #if USE_VBO
- #if TRUST_NO_ONE
+ #if TRUST_NO_ONE
assert(a->vbo_id);
- #endif /* TRUST_NO_ONE */
-
+ #endif /* TRUST_NO_ONE */
+ #if GENERIC_ATTRIB
+ glEnableVertexAttribArray(a_idx);
+ #if USE_VBO
glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
switch (a->fetch_mode) {
@@ -383,7 +511,7 @@ void vertex_buffer_use_primed(const VertexBuffer *buff)
case KEEP_INT:
glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, 0);
}
- #else /* client vertex array */
+ #else /* client vertex array */
switch (a->fetch_mode) {
case KEEP_FLOAT:
case CONVERT_INT_TO_FLOAT:
@@ -395,7 +523,32 @@ void vertex_buffer_use_primed(const VertexBuffer *buff)
case KEEP_INT:
glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, a->data);
}
- #endif /* USE_VBO */
+ #endif /* USE_VBO */
+ #else /* classic (non-generic) attributes */
+ glEnableClientState(a->array);
+ #if USE_VBO
+ glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ const void *data = 0;
+ #else /* client vertex array */
+ const void *data = a->data;
+ #endif /* USE_VBO */
+ switch (a->array) {
+ case GL_VERTEX_ARRAY:
+ glVertexPointer(a->comp_ct, a->comp_type, a->stride, data);
+ break;
+ case GL_NORMAL_ARRAY:
+ glNormalPointer(a->comp_type, a->stride, data);
+ break;
+ case GL_COLOR_ARRAY:
+ glColorPointer(a->comp_ct, a->comp_type, a->stride, data);
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, data);
+ break;
+ default:
+ ;
+ }
+ #endif /* GENERIC_ATTRIB */
}
#if USE_VBO
@@ -410,7 +563,11 @@ void vertex_buffer_done_using(const VertexBuffer *buff)
glBindVertexArray(0);
#else
for (unsigned a_idx = 0; a_idx < buff->attrib_ct; ++a_idx)
+ #if GE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list