OpenGL: draw color picker wheel with new immediate mode
Includes new imm_draw_lined_circle function that can be used for other widgets. Part of T49043
This commit is contained in:
@@ -80,6 +80,20 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
|
|||||||
*/
|
*/
|
||||||
void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
|
void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a circle outline with the given \a radius,
|
||||||
|
* starting at angle \a start and arcing through
|
||||||
|
* \a angle. The circle is centered at \a x, \a y
|
||||||
|
* and drawn in the XY plane.
|
||||||
|
*
|
||||||
|
* \param pos The vertex attribute number for position.
|
||||||
|
* \param x Horizontal center.
|
||||||
|
* \param y Vertical center.
|
||||||
|
* \param radius The circle's radius.
|
||||||
|
* \param nsegments The number of segments to use in drawing (more = smoother).
|
||||||
|
*/
|
||||||
|
void imm_draw_lined_circle(unsigned pos, float x, float y, float radius, int nsegments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a float value as obtained by glGetFloatv.
|
* Returns a float value as obtained by glGetFloatv.
|
||||||
* The param must cause only one value to be gotten from GL.
|
* The param must cause only one value to be gotten from GL.
|
||||||
|
|||||||
@@ -58,6 +58,8 @@
|
|||||||
#include "interface_intern.h"
|
#include "interface_intern.h"
|
||||||
|
|
||||||
#include "GPU_basic_shader.h"
|
#include "GPU_basic_shader.h"
|
||||||
|
#include "GPU_shader.h"
|
||||||
|
#include "GPU_immediate.h"
|
||||||
|
|
||||||
#ifdef WITH_INPUT_IME
|
#ifdef WITH_INPUT_IME
|
||||||
# include "WM_types.h"
|
# include "WM_types.h"
|
||||||
@@ -2266,18 +2268,17 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float
|
|||||||
|
|
||||||
static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
||||||
{
|
{
|
||||||
|
/* TODO(merwin): reimplement as shader for pixel-perfect colors */
|
||||||
|
|
||||||
const int tot = 64;
|
const int tot = 64;
|
||||||
const float radstep = 2.0f * (float)M_PI / (float)tot;
|
const float radstep = 2.0f * (float)M_PI / (float)tot;
|
||||||
const float centx = BLI_rcti_cent_x_fl(rect);
|
const float centx = BLI_rcti_cent_x_fl(rect);
|
||||||
const float centy = BLI_rcti_cent_y_fl(rect);
|
const float centy = BLI_rcti_cent_y_fl(rect);
|
||||||
float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f;
|
float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f;
|
||||||
|
|
||||||
/* gouraud triangle fan */
|
|
||||||
ColorPicker *cpicker = but->custom_data;
|
ColorPicker *cpicker = but->custom_data;
|
||||||
const float *hsv_ptr = cpicker->color_data;
|
const float *hsv_ptr = cpicker->color_data;
|
||||||
float xpos, ypos, ang = 0.0f;
|
|
||||||
float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
|
float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
|
||||||
int a;
|
|
||||||
bool color_profile = ui_but_is_colorpicker_display_space(but);
|
bool color_profile = ui_but_is_colorpicker_display_space(but);
|
||||||
|
|
||||||
/* color */
|
/* color */
|
||||||
@@ -2308,11 +2309,18 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
|
|||||||
|
|
||||||
ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
|
ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
|
||||||
|
|
||||||
glBegin(GL_TRIANGLE_FAN);
|
VertexFormat* format = immVertexFormat();
|
||||||
glColor3fv(colcent);
|
unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||||
glVertex2f(centx, centy);
|
unsigned color = add_attrib(format, "color", GL_FLOAT, 3, KEEP_FLOAT);
|
||||||
|
|
||||||
|
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
|
||||||
|
|
||||||
|
immBegin(GL_TRIANGLE_FAN, tot + 2);
|
||||||
|
immAttrib3fv(color, colcent);
|
||||||
|
immVertex2f(pos, centx, centy);
|
||||||
|
|
||||||
for (a = 0; a <= tot; a++, ang += radstep) {
|
float ang = 0.0f;
|
||||||
|
for (int a = 0; a <= tot; a++, ang += radstep) {
|
||||||
float si = sinf(ang);
|
float si = sinf(ang);
|
||||||
float co = cosf(ang);
|
float co = cosf(ang);
|
||||||
|
|
||||||
@@ -2320,25 +2328,37 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
|
|||||||
|
|
||||||
ui_color_picker_to_rgb_v(hsv, col);
|
ui_color_picker_to_rgb_v(hsv, col);
|
||||||
|
|
||||||
glColor3fv(col);
|
immAttrib3fv(color, col);
|
||||||
glVertex2f(centx + co * radius, centy + si * radius);
|
immVertex2f(pos, centx + co * radius, centy + si * radius);
|
||||||
}
|
}
|
||||||
glEnd();
|
immEnd();
|
||||||
|
immUnbindProgram();
|
||||||
|
|
||||||
/* fully rounded outline */
|
/* fully rounded outline */
|
||||||
glPushMatrix();
|
format = immVertexFormat();
|
||||||
glTranslatef(centx, centy, 0.0f);
|
pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||||
|
|
||||||
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glColor3ubv((unsigned char *)wcol->outline);
|
|
||||||
glutil_draw_lined_arc(0.0f, M_PI * 2.0, radius, tot + 1);
|
const float scale = 1.0f / 255.0f; /* TODO: treat as sRGB? */
|
||||||
|
const float outline_r = scale * (unsigned char)wcol->outline[0];
|
||||||
|
const float outline_g = scale * (unsigned char)wcol->outline[1];
|
||||||
|
const float outline_b = scale * (unsigned char)wcol->outline[2];
|
||||||
|
|
||||||
|
immUniform4f("color", outline_r, outline_g, outline_b, 1.0f);
|
||||||
|
imm_draw_lined_circle(pos, centx, centy, radius, tot);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
glPopMatrix();
|
|
||||||
|
immUnbindProgram();
|
||||||
|
|
||||||
/* cursor */
|
/* cursor */
|
||||||
|
float xpos, ypos;
|
||||||
ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
|
ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
|
||||||
|
|
||||||
ui_hsv_cursor(xpos, ypos);
|
ui_hsv_cursor(xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
#include "IMB_imbuf_types.h"
|
#include "IMB_imbuf_types.h"
|
||||||
|
|
||||||
#include "GPU_basic_shader.h"
|
#include "GPU_basic_shader.h"
|
||||||
|
#include "GPU_immediate.h"
|
||||||
|
|
||||||
#include "UI_interface.h"
|
#include "UI_interface.h"
|
||||||
|
|
||||||
@@ -181,6 +182,17 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegments)
|
||||||
|
{
|
||||||
|
immBegin(GL_LINE_LOOP, nsegments);
|
||||||
|
for (int i = 0; i < nsegments; ++i) {
|
||||||
|
float angle = 2 * M_PI * ((float)i / (float)nsegments);
|
||||||
|
immVertex2f(pos, x + rad * cosf(angle),
|
||||||
|
y + rad * sinf(angle));
|
||||||
|
}
|
||||||
|
immEnd();
|
||||||
|
}
|
||||||
|
|
||||||
float glaGetOneFloat(int param)
|
float glaGetOneFloat(int param)
|
||||||
{
|
{
|
||||||
GLfloat v;
|
GLfloat v;
|
||||||
|
|||||||
Reference in New Issue
Block a user