Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_buffers.c')
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c64
1 files changed, 22 insertions, 42 deletions
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 69aca31e21a..3c44811324c 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -28,8 +28,7 @@
/** \file blender/gpu/intern/gpu_buffers.c
* \ingroup gpu
*
- * Mesh drawing using OpenGL VBO (Vertex Buffer Objects),
- * with fall-back to vertex arrays.
+ * Mesh drawing using OpenGL VBO (Vertex Buffer Objects)
*/
#include <limits.h>
@@ -58,6 +57,7 @@
#include "GPU_buffers.h"
#include "GPU_draw.h"
+#include "GPU_basic_shader.h"
#include "bmesh.h"
@@ -101,7 +101,6 @@ const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
#define BUFFER_OFFSET(n) ((GLubyte *)NULL + (n))
-/* -1 - undefined, 0 - vertex arrays, 1 - VBOs */
static GPUBufferState GLStates = 0;
static GPUAttrib attribData[MAX_GPU_ATTRIB_DATA] = { { -1, 0, 0 } };
@@ -527,6 +526,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
if (!(buffer && (varray = glMapBuffer(target, GL_WRITE_ONLY)))) {
if (buffer)
gpu_buffer_free_intern(buffer);
+ BLI_mutex_unlock(&buffer_mutex);
return NULL;
}
}
@@ -864,10 +864,9 @@ void GPU_buffers_unbind(void)
}
if (GLStates & GPU_BUFFER_COLOR_STATE)
glDisableClientState(GL_COLOR_ARRAY);
- if (GLStates & GPU_BUFFER_ELEMENT_STATE) {
- /* not guaranteed we used VBOs but in that case it's just a no-op */
+ if (GLStates & GPU_BUFFER_ELEMENT_STATE)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
+
GLStates &= ~(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE |
GPU_BUFFER_TEXCOORD_UNIT_0_STATE | GPU_BUFFER_TEXCOORD_UNIT_2_STATE |
GPU_BUFFER_COLOR_STATE | GPU_BUFFER_ELEMENT_STATE);
@@ -881,7 +880,6 @@ void GPU_buffers_unbind(void)
}
attribData[0].index = -1;
- /* not guaranteed we used VBOs but in that case it's just a no-op */
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
@@ -1004,41 +1002,21 @@ struct GPU_PBVH_Buffers {
BLI_bitmap * const *grid_hidden;
const int *grid_indices;
int totgrid;
- int has_hidden;
+ bool has_hidden;
- int use_bmesh;
+ bool use_bmesh;
unsigned int tot_tri, tot_quad;
/* The PBVH ensures that either all faces in the node are
* smooth-shaded or all faces are flat-shaded */
- int smooth;
+ bool smooth;
bool show_diffuse_color;
bool use_matcaps;
float diffuse_color[4];
};
-typedef enum {
- VBO_ENABLED,
- VBO_DISABLED
-} VBO_State;
-
-static void gpu_colors_enable(VBO_State vbo_state)
-{
- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- if (vbo_state == VBO_ENABLED)
- glEnableClientState(GL_COLOR_ARRAY);
-}
-
-static void gpu_colors_disable(VBO_State vbo_state)
-{
- glDisable(GL_COLOR_MATERIAL);
- if (vbo_state == VBO_ENABLED)
- glDisableClientState(GL_COLOR_ARRAY);
-}
-
static float gpu_color_from_mask(float mask)
{
return 1.0f - mask * 0.75f;
@@ -1290,10 +1268,10 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
buffers->show_diffuse_color = show_diffuse_color;
buffers->use_matcaps = GPU_material_use_matcaps_get();
+ buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
/* Build VBO */
if (buffers->vert_buf) {
- int smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
const int has_mask = key->has_mask;
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
@@ -1318,7 +1296,7 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
CCGElem *elem = CCG_grid_elem(key, grid, x, y);
copy_v3_v3(vd->co, CCG_elem_co(key, elem));
- if (smooth) {
+ if (buffers->smooth) {
normal_float_to_short_v3(vd->no, CCG_elem_no(key, elem));
if (has_mask) {
@@ -1330,7 +1308,7 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
}
}
- if (!smooth) {
+ if (!buffers->smooth) {
/* for flat shading, recalc normals and set the last vertex of
* each triangle in the index buffer to have the flat normal as
* that is what opengl will use */
@@ -1383,8 +1361,6 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
buffers->grid_flag_mats = grid_flag_mats;
buffers->gridkey = *key;
- buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
-
//printf("node updated %p\n", buffers);
}
@@ -1525,7 +1501,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
if (totquad == fully_visible_totquad) {
buffers->index_buf = gpu_get_grid_buffer(gridsize, &buffers->index_type, &buffers->tot_quad);
- buffers->has_hidden = 0;
+ buffers->has_hidden = false;
}
else {
buffers->tot_quad = totquad;
@@ -1539,7 +1515,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
FILL_QUAD_BUFFER(unsigned int, totquad, buffers->index_buf);
}
- buffers->has_hidden = 1;
+ buffers->has_hidden = true;
}
/* Build coord/normal VBO */
@@ -1819,7 +1795,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
}
}
-GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading)
+GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(bool smooth_shading)
{
GPU_PBVH_Buffers *buffers;
@@ -1861,10 +1837,15 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
if (buffers->vert_buf) {
char *base = NULL;
char *index_base = NULL;
+ int bound_options = 0;
glEnableClientState(GL_VERTEX_ARRAY);
if (!wireframe) {
glEnableClientState(GL_NORMAL_ARRAY);
- gpu_colors_enable(VBO_ENABLED);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ /* weak inspection of bound options, should not be necessary ideally */
+ bound_options = GPU_basic_shader_bound_options();
+ GPU_basic_shader_bind(bound_options | GPU_SHADER_USE_COLOR);
}
GPU_buffer_bind(buffers->vert_buf, GPU_BINDING_ARRAY);
@@ -1943,7 +1924,8 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
glDisableClientState(GL_VERTEX_ARRAY);
if (!wireframe) {
glDisableClientState(GL_NORMAL_ARRAY);
- gpu_colors_disable(VBO_ENABLED);
+ glDisableClientState(GL_COLOR_ARRAY);
+ GPU_basic_shader_bind(bound_options);
}
}
}
@@ -2059,8 +2041,6 @@ void GPU_init_draw_pbvh_BB(void)
glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
}