[Bf-blender-cvs] [0a99072] master: GPU: move select index code out of WM

Campbell Barton noreply at git.blender.org
Sat Jun 25 13:14:18 CEST 2016


Commit: 0a99072f0d88f6fa809680dfcabe7aba5d476e0a
Author: Campbell Barton
Date:   Sat Jun 25 20:16:33 2016 +1000
Branches: master
https://developer.blender.org/rB0a99072f0d88f6fa809680dfcabe7aba5d476e0a

GPU: move select index code out of WM

This avoids bad-level calls.

===================================================================

M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/editors/mesh/editface.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/gpu/GPU_draw.h
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_subwindow.c
M	source/blender/windowmanager/wm_subwindow.h
M	source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 267f7a6..159d5b8 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -61,8 +61,6 @@
 #include "GPU_shader.h"
 #include "GPU_basic_shader.h"
 
-#include "WM_api.h"
-
 #include <string.h>
 #include <limits.h>
 #include <math.h>
@@ -699,10 +697,10 @@ static void cdDM_drawMappedFaces(
 						}
 
 						if ((orig != ORIGINDEX_NONE) && !is_hidden)
-							WM_framebuffer_index_get(orig + 1, &selcol);
+							GPU_select_index_get(orig + 1, &selcol);
 					}
 					else if (orig != ORIGINDEX_NONE)
-						WM_framebuffer_index_get(orig + 1, &selcol);
+						GPU_select_index_get(orig + 1, &selcol);
 
 					for (j = 0; j < mpoly->totloop; j++)
 						fi_map[start_element++] = selcol;
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c
index 01be8f8..c4e8761 100644
--- a/source/blender/editors/mesh/editface.c
+++ b/source/blender/editors/mesh/editface.c
@@ -53,6 +53,7 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "GPU_draw.h"
 #include "GPU_buffers.h"
 
 /* own include */
@@ -433,7 +434,7 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, bool select, bool exten
 	if (ENDIAN_ORDER == B_ENDIAN) {
 		IMB_convert_rgba_to_abgr(ibuf);
 	}
-	WM_framebuffer_to_index_array(ibuf->rect, size[0] * size[1]);
+	GPU_select_to_index_array(ibuf->rect, size[0] * size[1]);
 
 	a = size[0] * size[1];
 	while (a--) {
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 76c19fb..7156668 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -8219,7 +8219,7 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, const floa
 	MVert *mv = &data->mvert[index];
 
 	if (!(mv->flag & ME_HIDE)) {
-		WM_framebuffer_index_set(data->offset + index);
+		GPU_select_index_set(data->offset + index);
 		glVertex3fv(co);
 	}
 }
@@ -8244,7 +8244,7 @@ static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3]
 	BMVert *eve = BM_vert_at_index(data->bm, index);
 
 	if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
-		WM_framebuffer_index_set(data->offset + index);
+		GPU_select_index_set(data->offset + index);
 		glVertex3fv(co);
 	}
 }
@@ -8263,7 +8263,7 @@ static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
 	BMEdge *eed = BM_edge_at_index(data->bm, index);
 
 	if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-		WM_framebuffer_index_set(data->offset + index);
+		GPU_select_index_set(data->offset + index);
 		return DM_DRAW_OPTION_NORMAL;
 	}
 	else {
@@ -8277,7 +8277,7 @@ static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset)
 }
 
 /**
- * dont set #WM_framebuffer_index_set. just use to mask other
+ * dont set #GPU_framebuffer_index_set. just use to mask other
  */
 static DMDrawOption bbs_mesh_mask__setSolidDrawOptions(void *userData, int index)
 {
@@ -8296,7 +8296,7 @@ static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int inde
 	BMFace *efa = BM_face_at_index(userData, index);
 
 	if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
-		WM_framebuffer_index_set(index + 1);
+		GPU_select_index_set(index + 1);
 		return DM_DRAW_OPTION_NORMAL;
 	}
 	else {
@@ -8309,7 +8309,7 @@ static void bbs_mesh_solid__drawCenter(void *userData, int index, const float ce
 	BMFace *efa = BM_face_at_index(userData, index);
 
 	if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
-		WM_framebuffer_index_set(index + 1);
+		GPU_select_index_set(index + 1);
 
 		glVertex3fv(cent);
 	}
@@ -8340,7 +8340,7 @@ static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d,
 
 static DMDrawOption bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index)
 {
-	WM_framebuffer_index_set(index + 1);
+	GPU_select_index_set(index + 1);
 	return DM_DRAW_OPTION_NORMAL;
 }
 
@@ -8349,7 +8349,7 @@ static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
 	Mesh *me = userData;
 
 	if (!(me->mpoly[index].flag & ME_HIDE)) {
-		WM_framebuffer_index_set(index + 1);
+		GPU_select_index_set(index + 1);
 		return DM_DRAW_OPTION_NORMAL;
 	}
 	else {
@@ -8357,7 +8357,7 @@ static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
 	}
 }
 
-/* must have called WM_framebuffer_index_set beforehand */
+/* must have called GPU_framebuffer_index_set beforehand */
 static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
 {
 	Mesh *me = userData;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 9fb990b..329778c 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1488,7 +1488,7 @@ unsigned int ED_view3d_backbuf_sample(ViewContext *vc, int x, int y)
 		BLI_endian_switch_uint32(&col);
 	}
 	
-	return WM_framebuffer_to_index(col);
+	return GPU_select_to_index(col);
 }
 
 /* reads full rect, converts indices */
@@ -1521,7 +1521,7 @@ ImBuf *ED_view3d_backbuf_read(ViewContext *vc, int xmin, int ymin, int xmax, int
 		IMB_convert_rgba_to_abgr(ibuf_clip);
 	}
 
-	WM_framebuffer_to_index_array(ibuf_clip->rect, size_clip[0] * size_clip[1]);
+	GPU_select_to_index_array(ibuf_clip->rect, size_clip[0] * size_clip[1]);
 	
 	if ((clip.xmin == xmin) &&
 	    (clip.xmax == xmax) &&
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index bedcf41..a460d89 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -94,6 +94,8 @@
 
 #include "UI_interface.h"
 
+#include "GPU_draw.h"
+
 #include "view3d_intern.h"  /* own include */
 
 float ED_view3d_select_dist_px(void)
@@ -1690,7 +1692,7 @@ static int do_paintvert_box_select(ViewContext *vc, rcti *rect, bool select, boo
 		if (ENDIAN_ORDER == B_ENDIAN) {
 			IMB_convert_rgba_to_abgr(ibuf);
 		}
-		WM_framebuffer_to_index_array(ibuf->rect, size[0] * size[1]);
+		GPU_select_to_index_array(ibuf->rect, size[0] * size[1]);
 
 		a = size[0] * size[1];
 		while (a--) {
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h
index bc73238..90b65af 100644
--- a/source/blender/gpu/GPU_draw.h
+++ b/source/blender/gpu/GPU_draw.h
@@ -160,6 +160,12 @@ struct DerivedMesh;
 void GPU_draw_update_fvar_offset(struct DerivedMesh *dm);
 #endif
 
+/* utilities */
+void	GPU_select_index_set(int index);
+void	GPU_select_index_get(int index, int *r_col);
+int		GPU_select_to_index(unsigned int col);
+void	GPU_select_to_index_array(unsigned int *col, const unsigned int size);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 89816b0..064e917 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -2361,3 +2361,152 @@ void GPU_draw_update_fvar_offset(DerivedMesh *dm)
 	}
 }
 #endif
+
+
+/** \name Framebuffer color depth, for selection codes
+ * \{ */
+
+#ifdef __APPLE__
+
+/* apple seems to round colors to below and up on some configs */
+
+static unsigned int index_to_framebuffer(int index)
+{
+	unsigned int i = index;
+
+	switch (GPU_color_depth()) {
+		case 12:
+			i = ((i & 0xF00) << 12) + ((i & 0xF0) << 8) + ((i & 0xF) << 4);
+			/* sometimes dithering subtracts! */
+			i |= 0x070707;
+			break;
+		case 15:
+		case 16:
+			i = ((i & 0x7C00) << 9) + ((i & 0x3E0) << 6) + ((i & 0x1F) << 3);
+			i |= 0x030303;
+			break;
+		case 24:
+			break;
+		default: /* 18 bits... */
+			i = ((i & 0x3F000) << 6) + ((i & 0xFC0) << 4) + ((i & 0x3F) << 2);
+			i |= 0x010101;
+			break;
+	}
+
+	return i;
+}
+
+#else
+
+/* this is the old method as being in use for ages.... seems to work? colors are rounded to lower values */
+
+static unsigned int index_to_framebuffer(int index)
+{
+	unsigned int i = index;
+
+	switch (GPU_color_depth()) {
+		case 8:
+			i = ((i & 48) << 18) + ((i & 12) << 12) + ((i & 3) << 6);
+			i |= 0x3F3F3F;
+			break;
+		case 12:
+			i = ((i & 0xF00) << 12) + ((i & 0xF0) << 8) + ((i & 0xF) << 4);
+			/* sometimes dithering subtracts! */
+			i |= 0x0F0F0F;
+			break;
+		case 15:
+		case 16:
+			i = ((i & 0x7C00) << 9) + ((i & 0x3E0) << 6) + ((i & 0x1F) << 3);
+			i |= 0x070707;
+			break;
+		case 24:
+			break;
+		default:    /* 18 bits... */
+			i = ((i & 0x3F000) << 6) + ((i & 0xFC0) << 4) + ((i & 0x3F) << 2);
+			i |= 0x030303;
+			break;
+	}
+
+	return i;
+}
+
+#endif
+
+
+void GPU_select_index_set(int index)
+{
+	const int col = index_to_framebuffer(index);
+	glColor3ub(( (col)        & 0xFF),
+	           (((col) >>  8) & 0xFF),
+	           (((col) >> 16) & 0xFF));
+}
+
+void GPU_select_index_get(int index, int *r_col)
+{
+	const int col = index_to_framebuffer(index);
+	char *c_col = (char *)r_col;
+	c_col[0] = (col & 0xFF); /* red */
+	c_col[1] = ((col >>  8) & 0xFF); /* green */
+	c_col[2] = ((col >> 16) & 0xFF); /* blue */
+	c_col[3] = 0xFF; /* alpha */
+}
+
+
+#define INDEX_FROM_BUF_8(col)     ((((col) & 0xC00000) >> 18) + (((col) & 0xC000) >> 12) + (((col) & 0xC0) >> 6))
+#define INDEX_FROM_BUF_12(col)    ((((col) & 0xF00000) >> 12) + (((col) & 0xF000) >> 8)  + (((col) & 0xF0) >> 4))
+#define INDEX_FROM_BUF_15_16(col) ((((col) & 0xF80000) >> 9)  + (((col) & 0xF800) >> 6)  + (((col) & 0xF8) >> 3))
+#define INDEX_FROM_BUF_18(col)    ((((col) & 0xFC0000) >> 6)  + (((col) & 0xFC00) >> 4)  + (((col) & 0xFC) >> 2))
+#define INDEX_FROM_BUF_24(col)      ((col) & 0xFFFFFF)
+
+int GPU_select_to_index(unsigned int col)
+{
+	if (col == 0) {
+		return 0;
+	}
+
+	switch (GPU_color_depth()) {
+		case  8: return INDEX_FROM_BUF_8(col);
+		case 12: return INDEX_FROM_BUF_12(col);
+		case 15:
+		case 16: return INDEX_FROM_BUF_15_16(col);
+		case 24: return INDEX_FROM_BUF_24(col);
+		default: return INDEX_FROM_BUF_18(col);
+	}
+}
+
+void GPU_select_to_index_array(unsigned int *col, const unsigned int size)
+{
+#define INDEX_BUF_ARRAY(INDEX_FROM_BUF_BITS) \
+	for (i = size; i--; col++) { \
+		if ((c = *col)) 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list