[Bf-blender-cvs] [699d7fd] GPU_data_request: tweak GL state tracking
Mike Erwin
noreply at git.blender.org
Thu Apr 9 09:59:36 CEST 2015
Commit: 699d7fd7322dcbb96a131a94f1656845cfe41178
Author: Mike Erwin
Date: Thu Apr 9 02:35:11 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rB699d7fd7322dcbb96a131a94f1656845cfe41178
tweak GL state tracking
New defaults to match common 3D view usage:
- draw both sides (backface culling off)
- depth buffer test & write enabled
Also made default state more readable.
Fixed copy-paste error, GL_POLYGON_STIPPLE.
Mesh objects now draw fine in wireframe and (smooth) solid modes. Now
compatible with UI widgets drawn later!
===================================================================
M source/blender/editors/space_view3d/drawobject.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/gpu/intern/gpux_state.c
===================================================================
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index c3b41d4..8e513f5 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -2104,14 +2104,10 @@ static void drawcamera_new_new(Scene *scene, View3D *v3d, RegionView3D *rv3d, Ba
* for active cameras. We actually draw both outline+filled
* for active cameras so the wire can be seen side-on */
if (ob == v3d->camera) {
- PolygonDrawState polygon_state = default_state.polygon;
- polygon_state.draw_front = true;
- polygon_state.draw_back = true;
-
elem = GPUx_element_list_create(GL_TRIANGLES, 1, 7);
GPUx_set_triangle_vertices(elem, 0, 5,6,7);
- GPUx_draw_triangles(&default_state.common, &polygon_state, verts, elem);
+ GPUx_draw_triangles(&default_state.common, &default_state.polygon, verts, elem);
GPUx_element_list_discard(elem);
}
@@ -4468,14 +4464,11 @@ static bool draw_mesh_object_new_new(Scene *scene, ARegion *ar, View3D *v3d, Reg
/* TODO: handle flat faces */
/* TODO: handle loop normals */
int i, t, tri_ct = 0;
- MFace *faces = dm->getTessFaceDataArray(dm, CD_MFACE);
+ MFace *faces = dm->getTessFaceArray(dm);
CommonDrawState common_state = default_state.common;
PolygonDrawState polygon_state = default_state.polygon;
common_state.lighting = true;
- common_state.depth_test = true;
- common_state.depth_write = true;
- polygon_state.draw_front = true;
- polygon_state.draw_back = true;
+ polygon_state.draw_back = false;
GPUx_specify_attrib(verts, 1, GL_NORMAL_ARRAY, GL_SHORT, 3, NORMALIZE_INT_TO_FLOAT);
GPUx_fill_attrib_stride(verts, 1, &mverts[0].no, sizeof(MVert));
@@ -4496,20 +4489,16 @@ static bool draw_mesh_object_new_new(Scene *scene, ARegion *ar, View3D *v3d, Reg
/* TODO: update state tracking to handle all these */
glShadeModel(GL_SMOOTH);
-// glEnable(GL_DEPTH_TEST);
GPUx_vertex_buffer_prime(verts);
GPUx_draw_triangles(&common_state, &polygon_state, verts, elem);
-// glDisable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT); /* restore default */
}
else if (dt == OB_WIRE) {
/* draw wireframe */
int i;
MEdge *edges = dm->getEdgeArray(dm);
- LineDrawState line_state = default_state.line;
-// line_state.smooth = true;
elem = GPUx_element_list_create(GL_LINES, edge_ct, vert_ct - 1);
@@ -4519,7 +4508,7 @@ static bool draw_mesh_object_new_new(Scene *scene, ARegion *ar, View3D *v3d, Reg
}
GPUx_vertex_buffer_prime(verts);
- GPUx_draw_lines(&default_state.common, &line_state, verts, elem);
+ GPUx_draw_lines(&default_state.common, &default_state.line, verts, elem);
}
if (elem)
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 65dec7d..dfa2b41 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3587,6 +3587,8 @@ static void view3d_main_area_draw_viewport_new(const bContext *UNUSED(C), Scene
drawfloor(scene, v3d, grid_unit);
+ GPUx_reset_draw_state(); /* for code below which uses GPUx_state */
+
/* yanked verbatim from view3d_draw_objects
* not perfect but it does let us see objects positioned in space
* TODO: draw objects prettier/better/faster/stronger
@@ -3601,7 +3603,7 @@ static void view3d_main_area_draw_viewport_new(const bContext *UNUSED(C), Scene
* Hand-crafted logic here is tricky; will simplify later.
*/
- GPUx_reset_draw_state(); /* for code below which uses GPUx_state */
+ v3d->zbuf = true;
/* draw meshes (and cameras) not being edited (selected or not) */
for (base = scene->base.first; base; base = base->next) {
@@ -3654,6 +3656,9 @@ static void view3d_main_area_draw_viewport_new(const bContext *UNUSED(C), Scene
draw_object(scene, ar, v3d, base_edit, 0);
}
+ /* play nice with UI drawing code outside view3d */
+ glDisable(GL_DEPTH_TEST);
+
#if MCE_TRACE
printf("< %s\n\n", __FUNCTION__);
#endif /* MCE_TRACE */
diff --git a/source/blender/gpu/intern/gpux_state.c b/source/blender/gpu/intern/gpux_state.c
index 83e918e..a447a1d 100644
--- a/source/blender/gpu/intern/gpux_state.c
+++ b/source/blender/gpu/intern/gpux_state.c
@@ -9,10 +9,27 @@
#endif /* TRUST_NO_ONE */
const DrawState default_state = {
- .common = { false, false, false, false },
- .point = { false, 1.0f },
- .line = { false, 1.0f, 0 },
- .polygon = { true, false, MATERIAL_NONE, 0 }
+ .common = {
+ .blend = false,
+ .depth_test = true,
+ .depth_write = true,
+ .lighting = false
+ },
+ .point = {
+ .smooth = false,
+ .size = 1.0f
+ },
+ .line = {
+ .smooth = false,
+ .width = 1.0f,
+ .stipple = 0
+ },
+ .polygon = {
+ .draw_front = true,
+ .draw_back = true,
+ .material_id = MATERIAL_NONE,
+ .stipple = 0
+ }
};
static DrawState current;
@@ -23,9 +40,7 @@ static bool polygon_stipple_pattern_set = false;
void GPUx_reset_draw_state()
{
current = default_state;
-#if 0 /* TODO: make default state play nice with UI drawing code */
GPUx_force_state_update();
-#endif
}
void GPUx_set_common_state(const CommonDrawState *state)
@@ -96,7 +111,7 @@ void GPUx_set_line_state(const LineDrawState *state)
if (state->stipple != current.line.stipple) {
if (state->stipple) {
- const GLushort pattern = 0x4E72; /* or 0xAAAA */
+ const GLushort pattern = 0xAAAA;
glEnable(GL_LINE_STIPPLE);
/* line stipple is 16-bit pattern */
glLineStipple(state->stipple, pattern);
@@ -154,7 +169,7 @@ void GPUx_set_polygon_state(const PolygonDrawState *state)
}
}
else
- glDisable(GL_LINE_STIPPLE);
+ glDisable(GL_POLYGON_STIPPLE);
current.polygon.stipple = state->stipple;
}
}
@@ -202,7 +217,7 @@ void GPUx_force_state_update()
glLineWidth(current.line.width);
if (current.line.stipple) {
- const GLushort pattern = 0x4E72; /* or 0xAAAA */
+ const GLushort pattern = 0xAAAA;
glEnable(GL_LINE_STIPPLE);
/* line stipple is 16-bit pattern */
glLineStipple(current.line.stipple, pattern);
@@ -229,5 +244,5 @@ void GPUx_force_state_update()
polygon_stipple_pattern_set = true;
}
else
- glDisable(GL_LINE_STIPPLE);
+ glDisable(GL_POLYGON_STIPPLE);
}
More information about the Bf-blender-cvs
mailing list