[Bf-blender-cvs] [a39a459a1e] temp-blender2.8-stable: OpenGL immediate mode: interface_draw.c (cont)
Clément Foucault
noreply at git.blender.org
Wed Feb 8 00:53:00 CET 2017
Commit: a39a459a1ecbe3ab0cb772b9eae58ffc0a4d3e08
Author: Clément Foucault
Date: Tue Feb 7 20:43:58 2017 +0100
Branches: temp-blender2.8-stable
https://developer.blender.org/rBa39a459a1ecbe3ab0cb772b9eae58ffc0a4d3e08
OpenGL immediate mode: interface_draw.c (cont)
ui_draw_but_UNITVEC
Introduced a new shader to be used for simple lighting.
===================================================================
M source/blender/editors/interface/interface_draw.c
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_shader.h
M source/blender/gpu/gawain/immediate.c
M source/blender/gpu/gawain/immediate.h
M source/blender/gpu/intern/gpu_shader.c
M source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
A source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
===================================================================
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 7a12be93c7..32df2aaebb 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -1280,81 +1280,123 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
immUnbindProgram();
}
+#define SPHERE_LAT_RES 24
+#define SPHERE_LON_RES 32
+
+static float sphere_coords[SPHERE_LON_RES][SPHERE_LAT_RES][3] = {{{2.0f}}};
+
+static void ui_draw_lat_lon_vert(unsigned int pos, unsigned int nor, float radius, int lat, int lon)
+{
+ const float x = sphere_coords[lon][lat][0];
+ const float y = sphere_coords[lon][lat][1];
+ const float z = sphere_coords[lon][lat][2];
+
+ immAttrib3f(nor, x, y, z);
+ immVertex3f(pos, x * radius, y * radius, z * radius);
+}
+
+static void ui_draw_unitvec_sphere(unsigned int pos, unsigned int nor, float radius)
+{
+ const float lon_inc = 2 * M_PI / SPHERE_LON_RES;
+ const float lat_inc = M_PI / SPHERE_LAT_RES;
+ float lon, lat;
+
+ /* TODO put that in a batch */
+
+ /* Init coords only once */
+ if (sphere_coords[0][0][0] == 2.0f) {
+ lon = 0.0f;
+ for(int i = 0; i < SPHERE_LON_RES; i++, lon += lon_inc) {
+ lat = 0.0f;
+ for(int j = 0; j < SPHERE_LAT_RES; j++, lat += lat_inc) {
+ sphere_coords[i][j][0] = sinf(lat) * cosf(lon);
+ sphere_coords[i][j][1] = cosf(lat);
+ sphere_coords[i][j][2] = sinf(lat) * sinf(lon);
+ }
+ }
+ }
+
+ immBegin(GL_TRIANGLES, (SPHERE_LAT_RES-1) * SPHERE_LON_RES * 6);
+ for(int i = 0; i < SPHERE_LON_RES; i++) {
+ for(int j = 0; j < SPHERE_LAT_RES; j++) {
+ if (j != SPHERE_LAT_RES - 1) { /* Pole */
+ ui_draw_lat_lon_vert(pos, nor, radius, j, i);
+ ui_draw_lat_lon_vert(pos, nor, radius, j+1, i);
+ ui_draw_lat_lon_vert(pos, nor, radius, j+1, i+1);
+ }
+
+ if (j != 0) { /* Pole */
+ ui_draw_lat_lon_vert(pos, nor, radius, j, i);
+ ui_draw_lat_lon_vert(pos, nor, radius, j+1, i+1);
+ ui_draw_lat_lon_vert(pos, nor, radius, j, i+1);
+ }
+ }
+ }
+ immEnd();
+}
+#undef SPHERE_LAT_RES
+#undef SPHERE_LON_RES
+
void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
{
- static GLuint displist = 0;
+ /* sphere color */
float diffuse[3] = {1.0f, 1.0f, 1.0f};
+ float light[3];
float size;
/* backdrop */
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_gl_mode_3ubAlpha(GL_TRIANGLE_FAN, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f, (unsigned char *)wcol->inner, 255);
- /* sphere color */
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
/* setup lights */
- GPULightData light = {0};
- light.type = GPU_LIGHT_SUN;
- copy_v3_v3(light.diffuse, diffuse);
- zero_v3(light.specular);
- ui_but_v3_get(but, light.direction);
+ ui_but_v3_get(but, light);
+ light[2] = -light[2];
- GPU_basic_shader_light_set(0, &light);
- for (int a = 1; a < 8; a++)
- GPU_basic_shader_light_set(a, NULL);
-
- /* setup shader */
- GPU_basic_shader_colors(diffuse, NULL, 0, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING);
+ VertexFormat *format = immVertexFormat();
+ unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+ unsigned int nor = add_attrib(format, "nor", GL_FLOAT, 3, KEEP_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_SIMPLE_LIGHTING);
+ immUniformColor3fv(diffuse);
+ immUniform3fv("light", light);
/* transform to button */
- glPushMatrix();
- glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
+ gpuMatrixBegin3D_legacy();
+ gpuPushMatrix();
if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect))
size = BLI_rcti_size_x(rect) / 200.f;
else
size = BLI_rcti_size_y(rect) / 200.f;
- glScalef(size, size, MIN2(size, 1.0f));
-
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
- GPU_basic_shader_bind(GPU_basic_shader_bound_options());
- gluSphere(qobj, 100.0, 32, 24);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
+ gpuTranslate3f(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
+ gpuScale3f(size, size, MIN2(size, 1.0f));
- glCallList(displist);
+ ui_draw_unitvec_sphere(pos, nor, 100.0);
+ immUnbindProgram();
/* restore */
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- GPU_default_lights();
glDisable(GL_CULL_FACE);
/* AA circle */
+ format = immVertexFormat();
+ pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ubv((unsigned char *)wcol->inner);
+
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glColor3ubv((unsigned char *)wcol->inner);
- glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32);
+ imm_draw_lined_circle(pos, 0.0f, 0.0f, 100.0f, 32);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
/* matrix after circle */
- glPopMatrix();
+ gpuPopMatrix();
+ gpuMatrixEnd();
- /* We disabled all blender lights above, so restore them here. */
- GPU_default_lights();
+ immUnbindProgram();
}
static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index e8d23c7d3f..a2cf143bb0 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -131,6 +131,7 @@ set(SRC
data_to_c_simple(shaders/gpu_shader_depth_only_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_uniform_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_checker_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_simple_lighting_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_flat_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 7b9a3e0963..f130dcc8c6 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -97,6 +97,7 @@ typedef enum GPUBuiltinShader {
GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
GPU_SHADER_EDGES_OVERLAY_SIMPLE,
GPU_SHADER_EDGES_OVERLAY,
+ GPU_SHADER_SIMPLE_LIGHTING,
/* for simple 2D drawing */
GPU_SHADER_2D_UNIFORM_COLOR,
GPU_SHADER_2D_FLAT_COLOR,
diff --git a/source/blender/gpu/gawain/immediate.c b/source/blender/gpu/gawain/immediate.c
index 03e16ca248..d96fc6f938 100644
--- a/source/blender/gpu/gawain/immediate.c
+++ b/source/blender/gpu/gawain/immediate.c
@@ -727,6 +727,28 @@ void immUniform1f(const char* name, float x)
glUniform1f(loc, x);
}
+void immUniform3f(const char* name, float x, float y, float z)
+ {
+ int loc = glGetUniformLocation(imm.bound_program, name);
+
+#if TRUST_NO_ONE
+ assert(loc != -1);
+#endif
+
+ glUniform3f(loc, x, y, z);
+ }
+
+void immUniform3fv(const char* name, const float data[3])
+ {
+ int loc = glGetUniformLocation(imm.bound_program, name);
+
+#if TRUST_NO_ONE
+ assert(loc != -1);
+#endif
+
+ glUniform3fv(loc, 1, data);
+ }
+
void immUniform4f(const char* name, float x, float y, float z, float w)
{
int loc = glGetUniformLocation(imm.bound_program, name);
diff --git a/source/blender/gpu/gawain/immediate.h b/source/blender/gpu/gawain/immediate.h
index 50965d3d36..d8d6949d47 100644
--- a/source/blender/gpu/gawain/immediate.h
+++ b/source/blender/gpu/gawain/immediate.h
@@ -79,6 +79,8 @@ void immVertex2iv(unsigned attrib_id, const int data[2]);
// provide uniform values that don't change for the entire draw call
void immUniform1i(const char* name, int x);
void immUniform1f(const char* name, float x);
+void immUniform3f(const char* name, float x, float y, float z);
+void immUniform3fv(const char* name, const float data[3]);
void immUniform4f(const char* name, float x, float y, float z, float w);
void immUniform4fv(const char* name, const float data[4]);
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 5160a33bef..8ff312385c 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -49,6 +49,7 @@
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
extern char datatoc_gpu_shader_checker_frag_glsl[];
+extern char datatoc_gpu_shader_simple_lighting_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[];
extern char datatoc_gpu_shader_2D_vert_glsl[];
@@ -625,6 +626,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
[GPU_SHADER_EDGES_OVERLAY] = { datatoc_gpu_shader_edges_overlay_vert_glsl,
datatoc_gpu_shader_edges_overlay_frag_glsl,
datatoc_gpu_shader_edges_overlay_geom_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_simple_lighting_frag_glsl },
[GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_image_vert_glsl,
datatoc_gpu_shader_image_mask_uniform_color_frag_glsl },
@@ -686,7 +688,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
if (builtin_shaders[shader] == NULL) {
/* just a few special cases */
- const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? "#define USE_COBA;\n" : NULL;
+ const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? "#define USE_COBA;\n" :
+ (shader == GPU_SHADER_SIMPLE_LIGHTING) ? "#define USE_NORMALS;\n" : NULL;
const GPUShaderStages *stages = builtin_shader_stages + shader;
@@ -698,6 +701,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
stages = &legacy_fancy_edges;
}
+ if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP && !GLEW_VERSION_3_2) {
+ /* TODO: remove after switch to core profile (maybe) */
+ static const GPUShaderStages legacy_fancy_edges =
+ { datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl,
+ datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl };
+ stag
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list