[Bf-blender-cvs] [995c613] GPU_data_request: fixed issues in batched geometry API
Mike Erwin
noreply at git.blender.org
Fri Apr 3 03:16:31 CEST 2015
Commit: 995c61340406ca3b24cd124e54185171cb7c2e60
Author: Mike Erwin
Date: Thu Apr 2 20:59:43 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rB995c61340406ca3b24cd124e54185171cb7c2e60
fixed issues in batched geometry API
- made default state available to all
- fixed vertex index tracking
- fixed attrib stride calculation
- fixed VBO binding
- fixed VAO attrib enables
===================================================================
M source/blender/gpu/GPUx_element.h
M source/blender/gpu/GPUx_state.h
M source/blender/gpu/intern/GPUx_element_private.h
M source/blender/gpu/intern/gpux_element.c
M source/blender/gpu/intern/gpux_state.c
M source/blender/gpu/intern/gpux_vbo.c
===================================================================
diff --git a/source/blender/gpu/GPUx_element.h b/source/blender/gpu/GPUx_element.h
index 2bf61b8..2e5c46f 100644
--- a/source/blender/gpu/GPUx_element.h
+++ b/source/blender/gpu/GPUx_element.h
@@ -12,8 +12,8 @@
struct ElementList; /* forward declaration */
typedef struct ElementList ElementList;
-ElementList *create_element_list(GLenum prim_type, unsigned prim_ct, unsigned max_index);
-void discard_element_list(ElementList*);
+ElementList *element_list_create(GLenum prim_type, unsigned prim_ct, unsigned max_index);
+void element_list_discard(ElementList*);
void set_point_vertex(ElementList*, unsigned prim_idx, unsigned v1);
void set_line_vertices(ElementList*, unsigned prim_idx, unsigned v1, unsigned v2);
diff --git a/source/blender/gpu/GPUx_state.h b/source/blender/gpu/GPUx_state.h
index 0b6f72e..9bf6087 100644
--- a/source/blender/gpu/GPUx_state.h
+++ b/source/blender/gpu/GPUx_state.h
@@ -42,6 +42,8 @@ typedef struct {
PolygonDrawState polygon;
} DrawState;
+extern const DrawState default_state;
+
void reset_draw_state(); /* to defaults */
/* ^-- call this before using set_*_state functions below */
diff --git a/source/blender/gpu/intern/GPUx_element_private.h b/source/blender/gpu/intern/GPUx_element_private.h
index e68b9db..5efac40 100644
--- a/source/blender/gpu/intern/GPUx_element_private.h
+++ b/source/blender/gpu/intern/GPUx_element_private.h
@@ -2,6 +2,7 @@
#define BLENDER_GL_ELEMENT_LIST_PRIVATE
#include "GPUx_element.h"
+#include <stdbool.h>
/* track min & max observed index (for glDrawRangeElements) */
#define TRACK_INDEX_RANGE true
@@ -18,9 +19,7 @@ struct ElementList {
void *indices; /* array of index_type */
};
-#if TRACK_INDEX_RANGE
unsigned min_index(const ElementList*);
unsigned max_index(const ElementList*);
-#endif /* TRACK_INDEX_RANGE */
#endif /* BLENDER_GL_ELEMENT_LIST_PRIVATE */
diff --git a/source/blender/gpu/intern/gpux_element.c b/source/blender/gpu/intern/gpux_element.c
index 4ac3fd4..1109e44 100644
--- a/source/blender/gpu/intern/gpux_element.c
+++ b/source/blender/gpu/intern/gpux_element.c
@@ -30,7 +30,7 @@ unsigned max_index(const ElementList *el)
#endif /* TRACK_INDEX_RANGE */
}
-ElementList *create_element_list(GLenum prim_type, unsigned prim_ct, unsigned max_index)
+ElementList *element_list_create(GLenum prim_type, unsigned prim_ct, unsigned max_index)
{
ElementList *el;
unsigned index_size, prim_vertex_ct;
@@ -68,8 +68,7 @@ ElementList *create_element_list(GLenum prim_type, unsigned prim_ct, unsigned ma
}
#if TRACK_INDEX_RANGE
- el->min_observed_index = 0xFFFFFFFF;
-/* el->min_observed_index = (unsigned) -1; */
+ el->min_observed_index = max_index + 1; /* any valid index will be < this */
el->max_observed_index = 0;
#endif /* TRACK_INDEX_RANGE */
@@ -79,7 +78,7 @@ ElementList *create_element_list(GLenum prim_type, unsigned prim_ct, unsigned ma
return el;
}
-void discard_element_list(ElementList *el)
+void element_list_discard(ElementList *el)
{
free(el->indices);
free(el);
diff --git a/source/blender/gpu/intern/gpux_state.c b/source/blender/gpu/intern/gpux_state.c
index b3c43a9..1f6fd23 100644
--- a/source/blender/gpu/intern/gpux_state.c
+++ b/source/blender/gpu/intern/gpux_state.c
@@ -8,7 +8,7 @@
#include <assert.h>
#endif /* TRUST_NO_ONE */
-static const DrawState default_state = {
+const DrawState default_state = {
.common = { false, true, true, false },
.point = { false, 1.0f },
.line = { false, 1.0f, 0 },
@@ -23,7 +23,9 @@ static bool polygon_stipple_pattern_set = false;
void reset_draw_state()
{
current = default_state;
+#if 0 /* TODO: make default state play nice with UI drawing code */
force_state_update();
+#endif
}
void set_common_state(const CommonDrawState *state)
diff --git a/source/blender/gpu/intern/gpux_vbo.c b/source/blender/gpu/intern/gpux_vbo.c
index de65008..4d1afbe 100644
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@ -60,11 +60,12 @@ static unsigned attrib_sz(const Attrib *a)
static unsigned attrib_align(const Attrib *a)
{
- /* I know AMD HW can't fetch these well, so pad it out */
- if (a->comp_ct == 3 && a->sz <= 2)
- return 4 * a->sz;
+ const unsigned c = comp_sz(a->comp_type);
+ /* AMD HW can't fetch these well, so pad it out (other vendors too?) */
+ if (a->comp_ct == 3 && c <= 2)
+ return 4 * c;
else
- return a->comp_ct * a->sz;
+ return a->comp_ct * c;
}
struct VertexBuffer
@@ -332,10 +333,10 @@ void vertex_buffer_use(VertexBuffer *buff)
#if USE_VBO
if (a->vbo_id)
- glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
else {
glGenBuffers(1, &a->vbo_id);
- glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
/* 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);
}
@@ -379,7 +380,7 @@ void vertex_buffer_use(VertexBuffer *buff)
}
#if USE_VBO
- glBindBuffer(0, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif /* USE_VBO */
}
@@ -398,12 +399,20 @@ void vertex_buffer_prime(VertexBuffer *buff)
for (unsigned a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
Attrib *a = buff->attribs + a_idx;
+ #if USE_VAO
+ #if GENERIC_ATTRIB
+ glEnableVertexAttribArray(a_idx);
+ #else
+ glEnableClientState(a->array);
+ #endif /* GENERIC_ATTRIB */
+ #endif /* USE_VAO */
+
#if TRUST_NO_ONE
assert(a->vbo_id == 0);
#endif /* TRUST_NO_ONE */
glGenBuffers(1, &a->vbo_id);
- glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
/* 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);
@@ -441,7 +450,7 @@ void vertex_buffer_prime(VertexBuffer *buff)
#endif /* USE_VAO */
}
- glBindBuffer(0, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif /* USE_VBO */
#if USE_VAO
@@ -472,7 +481,7 @@ void vertex_buffer_use_primed(const VertexBuffer *buff)
#if TRUST_NO_ONE
assert(a->vbo_id);
#endif /* TRUST_NO_ONE */
- glBindBuffer(a->vbo_id, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
const void *data = 0;
#else /* client vertex array */
@@ -512,7 +521,7 @@ void vertex_buffer_use_primed(const VertexBuffer *buff)
}
#if USE_VBO
- glBindBuffer(0, GL_ARRAY_BUFFER);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif /* USE_VBO */
#endif /* USE_VAO */
}
More information about the Bf-blender-cvs
mailing list