Opengl glaDrawPixels removal: More descriptive setup.
This commit is contained in:
parent
0584c82ad7
commit
1e7475a5d7
|
@ -210,6 +210,12 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int ty
|
|||
void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
|
||||
float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y);
|
||||
#endif
|
||||
|
||||
/* To be used before calling immDrawPixelsTex
|
||||
* Default shader is GPU_SHADER_2D_IMAGE_COLOR
|
||||
* Returns a shader to be able to set uniforms */
|
||||
struct GPUShader *immDrawPixelsTexSetup(int builtin);
|
||||
|
||||
/**
|
||||
* immDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
|
||||
* image using textures, which can be tremendously faster on low-end
|
||||
|
@ -217,6 +223,8 @@ void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int forma
|
|||
* clipped when offscreen. Pixel unpacking parameters and
|
||||
* the glPixelZoom values are _not_ respected.
|
||||
*
|
||||
* \attention Use immDrawPixelsTexSetup before calling this function.
|
||||
*
|
||||
* \attention This routine makes many assumptions: the rect data
|
||||
* is expected to be in RGBA byte or float format, and the
|
||||
* modelview and projection matrices are assumed to define a
|
||||
|
|
|
@ -501,6 +501,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
|
|||
facy = (float)h / (float)ibuf->y;
|
||||
}
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect,
|
||||
facx, facy, NULL);
|
||||
|
||||
|
@ -1735,7 +1736,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
|
|||
UI_draw_roundbox_gl_mode(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
|
||||
}
|
||||
|
||||
GPU_shader_unbind(); /* make sure there is no program bound */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, drawibuf->rect, 1.0f, 1.0f, NULL);
|
||||
|
||||
/* draw cross for pixel position */
|
||||
|
|
|
@ -1009,6 +1009,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
|
|||
/* draw */
|
||||
#if 0
|
||||
if (is_preview) {
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
|
||||
1.0f, 1.0f, col);
|
||||
}
|
||||
|
@ -1017,6 +1018,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
|
|||
int bound_options;
|
||||
GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
|
||||
1.0f, 1.0f, col);
|
||||
|
||||
|
|
|
@ -753,6 +753,7 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
|
|||
}
|
||||
|
||||
if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
|
||||
float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
|
||||
float *buffer = threaded_mask_rasterize(mask, width, height);
|
||||
|
||||
if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
|
||||
|
@ -767,12 +768,10 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
|
|||
if (stabmat) {
|
||||
glMultMatrixf((const float *) stabmat);
|
||||
}
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
|
||||
immDrawPixelsTex(0.0f, 0.0f, width, height, GL_RED, GL_FLOAT, GL_NEAREST, buffer, 1.0f, 1.0f, NULL);
|
||||
GPU_shader_unbind();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
#include "IMB_colormanagement.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
@ -1537,7 +1538,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
|
|||
if (force_fallback == false) {
|
||||
if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) {
|
||||
glEnable(GL_BLEND);
|
||||
glUseProgram(0); /* immDrawPixelsTex use it's own shader */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
|
||||
GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf,
|
||||
scale_x, scale_y, NULL);;
|
||||
|
@ -1557,7 +1558,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
|
|||
4, dither, &scene->view_settings, &scene->display_settings);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glUseProgram(0); /* immDrawPixelsTex use it's own shader */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
GL_NEAREST, display_buffer,
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
|
||||
#include "RE_pipeline.h"
|
||||
#include "RE_engine.h"
|
||||
|
@ -599,6 +600,7 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect,
|
|||
if (re)
|
||||
RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0);
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(fx, fy, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect_byte,
|
||||
1.0f, 1.0f, NULL);
|
||||
|
||||
|
|
|
@ -620,11 +620,34 @@ void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int t
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Use the currently bound shader if there is one.
|
||||
* To let it draw without other shaders use glUseProgram(0)
|
||||
* or GPU_shader_unbind() before calling immDrawPixelsTex.
|
||||
/* To be used before calling immDrawPixelsTex
|
||||
* Default shader is GPU_SHADER_2D_IMAGE_COLOR
|
||||
* You can still set uniforms with :
|
||||
* GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);
|
||||
* */
|
||||
GPUShader *immDrawPixelsTexSetup(int builtin)
|
||||
{
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(builtin);
|
||||
/* Shader will be unbind by immUnbindProgram in immDrawPixelsTexScaled_clipping */
|
||||
GPU_shader_bind(shader);
|
||||
GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "image"), 0);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
/* Use the currently bound shader.
|
||||
*
|
||||
* If color is NULL then use white by default */
|
||||
* Use immDrawPixelsTexSetup to bind the shader you
|
||||
* want before calling immDrawPixelsTex.
|
||||
*
|
||||
* If using a special shader double check it uses the same
|
||||
* attributes "pos" "texCoord" and uniform "image".
|
||||
*
|
||||
* If color is NULL then use white by default
|
||||
*
|
||||
* Be also aware that this function unbinds the shader when
|
||||
* it's finished.
|
||||
* */
|
||||
void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
|
||||
int format, int type, int zoomfilter, void *rect,
|
||||
float scaleX, float scaleY,
|
||||
|
@ -692,19 +715,19 @@ void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
|
|||
|
||||
unsigned int program = glaGetOneInt(GL_CURRENT_PROGRAM);
|
||||
|
||||
if (program) {
|
||||
immBindProgram(program);
|
||||
/* This is needed for the OCIO case.
|
||||
* Shader program is set outside of blender and
|
||||
* we need it in imm module to do all attrib /
|
||||
* uniform bindings. */
|
||||
|
||||
/* optionnal */
|
||||
if (glGetUniformLocation(program, "color") != -1)
|
||||
immUniform4fv("color", (color) ? color : white);
|
||||
}
|
||||
else {
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immUniform1i("image", 0);
|
||||
/* A program is already bound.
|
||||
* set it in imm.bound_program to be able to use imm functions */
|
||||
BLI_assert(program);
|
||||
immBindProgram(program);
|
||||
|
||||
/* optionnal */
|
||||
if (glGetUniformLocation(program, "color") != -1)
|
||||
immUniform4fv("color", (color) ? color : white);
|
||||
}
|
||||
|
||||
|
||||
for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
|
||||
for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
|
||||
|
@ -1118,7 +1141,7 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
|
|||
display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
|
||||
|
||||
if (display_buffer) {
|
||||
GPU_shader_unbind(); /* Make sure no shader is bound */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
zoomfilter, display_buffer,
|
||||
clip_min_x, clip_min_y, clip_max_x, clip_max_y,
|
||||
|
|
|
@ -391,6 +391,7 @@ static void file_draw_preview(
|
|||
UI_GetThemeColor4fv(TH_TEXT, col);
|
||||
}
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect,
|
||||
scale, scale, 1.0f, 1.0f, col);
|
||||
|
||||
|
|
|
@ -420,14 +420,11 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int
|
|||
recti[a] = rect[a] * 0.5f + 0.5f;
|
||||
}
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
|
||||
|
||||
immDrawPixelsTex(x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
|
||||
|
||||
GPU_shader_unbind();
|
||||
|
||||
MEM_freeN(recti);
|
||||
}
|
||||
|
||||
|
@ -461,14 +458,11 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
|
|||
}
|
||||
}
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
|
||||
|
||||
immDrawPixelsTex(x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
|
||||
|
||||
GPU_shader_unbind();
|
||||
|
||||
MEM_freeN(rectf);
|
||||
}
|
||||
|
||||
|
@ -526,8 +520,7 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
|
|||
else if (sima->flag & SI_SHOW_ALPHA)
|
||||
shuffle[3] = 1.0f;
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
|
||||
|
||||
IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
|
||||
|
@ -539,8 +532,6 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
|
|||
}
|
||||
|
||||
IMB_display_buffer_release(cache_handle);
|
||||
|
||||
GPU_shader_unbind();
|
||||
}
|
||||
|
||||
if (sima->flag & SI_USE_ALPHA)
|
||||
|
@ -615,24 +606,19 @@ static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene,
|
|||
shuffle[3] = 1.0f;
|
||||
}
|
||||
|
||||
/* To make sure no program is bound */
|
||||
GPU_shader_unbind();
|
||||
|
||||
for (sy = 0; sy + dy <= ibuf->y; sy += dy) {
|
||||
for (sx = 0; sx + dx <= ibuf->x; sx += dx) {
|
||||
UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y);
|
||||
|
||||
if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) {
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
|
||||
}
|
||||
else {
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
|
||||
|
||||
immDrawPixelsTex(x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
|
||||
|
||||
GPU_shader_unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -735,7 +721,10 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen
|
|||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
|
||||
|
|
|
@ -3226,8 +3226,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
|
|||
else
|
||||
shuffle[3] = 1.0f;
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
|
||||
|
||||
immDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
|
||||
|
|
|
@ -705,6 +705,7 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv)
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* premul graphics */
|
||||
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect,
|
||||
scale, scale, NULL);
|
||||
|
||||
|
|
|
@ -782,7 +782,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
|
|||
}
|
||||
|
||||
float col[4] = {1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend};
|
||||
glUseProgram(0); /* immDrawPixelsTex use it's own shader */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTex(x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
|
||||
zoomx, zoomy, col);
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "UI_interface.h"
|
||||
|
@ -333,6 +335,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
|
|||
drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy);
|
||||
else {
|
||||
float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* this blends texture */
|
||||
immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
immDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
|
||||
drag->imb->rect, drag->scale, drag->scale, 1.0f, 1.0f, col);
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
|
|||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
|
||||
GPU_shader_bind(shader);
|
||||
GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
|
||||
|
||||
|
|
Loading…
Reference in New Issue