diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-03-04 02:18:21 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-03-04 02:18:21 +0300 |
commit | a514fea93248756b4319a5f661a2f292bb9125ae (patch) | |
tree | 5a937d54afc7ebdcfc6e914ab31c0381ed4dbc5a | |
parent | 87d5f670a0af2b0fcbf92ef591859cbb0a2a0670 (diff) |
OpenGL: remove old DrawPixels util functions
a little bit of T49043, mostly related to T49165
Thx to @fclem for marking these as unused & making shader-based replacements.
-rw-r--r-- | source/blender/editors/include/BIF_glutil.h | 58 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 268 |
2 files changed, 3 insertions, 323 deletions
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index 74c96f46cc5..e67094027f6 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -136,45 +136,6 @@ int glaGetOneInt(int param); */ void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y); -#if 0 /* Obsolete / unused */ -/** - * Functions like a limited glDrawPixels, except ensures that - * the image is displayed onscreen even if the \a x and \a y - * coordinates for would be clipped. The routine respects the - * glPixelZoom values, pixel unpacking parameters are _not_ - * respected. - * - * \attention This routine makes many assumptions: the rect data - * is expected to be in RGBA unsigned byte format, the coordinate - * (GLA_PIXEL_OFS, GLA_PIXEL_OFS) is assumed to be within the view frustum, - * and the modelview and projection matrices are assumed to define a - * 1-to-1 mapping to screen space. - * \attention Furthermore, in the case of zoomed or unpixel aligned - * images extending outside the view frustum, but still within the - * window, some portion of the image may be visible left and/or - * below of the given \a x and \a y coordinates. It is recommended - * to use the glScissor functionality if images are to be drawn - * with an inset view matrix. - */ -void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect); - -/** - * glaDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the - * image using textures, which can be tremendously faster on low-end - * cards, and also avoids problems with the raster position being - * clipped when offscreen. The routine respects the glPixelZoom values, - * pixel unpacking parameters are _not_ respected. - * - * \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 - * 1-to-1 mapping to screen space. - */ -void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect); -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 */ @@ -199,22 +160,6 @@ void immDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int ty void immDrawPixelsTex_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, float xzoom, float yzoom, float color[4]); -#if 0 /* Obsolete / unused */ -/** - * glaDrawPixelsAuto - Switches between texture or pixel drawing using UserDef. - * only RGBA - * needs glaDefine2DArea to be set. - */ -void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect); -void glaDrawPixelsAuto_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); - - -void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY); -void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY, - float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y); -#endif - void immDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY, float xzoom, float yzoom, float color[4]); 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, @@ -234,6 +179,9 @@ void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h, int * \param screen_rect The screen rectangle to be defined for 2D drawing. */ void glaDefine2DArea(struct rcti *screen_rect); + +/* TODO(merwin): put the following 2D code to use, or build new 2D code inspired & informd by it */ + #if 0 /* UNUSED */ typedef struct gla2DDrawInfo gla2DDrawInfo; diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index dcf7b1ba208..14fdcb1f721 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -286,274 +286,6 @@ static int get_cached_work_texture(int *r_w, int *r_h) return texid; } -#if 0 /* Obsolete / unused */ -/* DEPRECATED: use immDrawPixelsTexScaled_clipping instead */ -void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h, - int format, int type, int zoomfilter, void *rect, - float scaleX, float scaleY, - float clip_min_x, float clip_min_y, - float clip_max_x, float clip_max_y) -{ - unsigned char *uc_rect = (unsigned char *) rect; - const float *f_rect = (float *)rect; - float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y); - int subpart_x, subpart_y, tex_w, tex_h; - int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y; - int texid = get_cached_work_texture(&tex_w, &tex_h); - int components; - const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y)); - - /* Specify the color outside this function, and tex will modulate it. - * This is useful for changing alpha without using glPixelTransferf() - */ - glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w); - glBindTexture(GL_TEXTURE_2D, texid); - - /* don't want nasty border artifacts */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter); - - /* setup seamless 2=on, 0=off */ - seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0; - - offset_x = tex_w - seamless; - offset_y = tex_h - seamless; - - nsubparts_x = (img_w + (offset_x - 1)) / (offset_x); - nsubparts_y = (img_h + (offset_y - 1)) / (offset_y); - - if (format == GL_RGBA) - components = 4; - else if (format == GL_RGB) - components = 3; - else if (ELEM(format, GL_LUMINANCE, GL_ALPHA)) - components = 1; - else { - BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled"); - return; - } - - if (type == GL_FLOAT) { - /* need to set internal format to higher range float */ - - /* NOTE: this could fail on some drivers, like mesa, - * but currently this code is only used by color - * management stuff which already checks on whether - * it's possible to use GL_RGBA16F_ARB - */ - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, tex_w, tex_h, 0, format, GL_FLOAT, NULL); - } - else { - /* switch to 8bit RGBA for byte buffer */ - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL); - } - - for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) { - for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) { - int remainder_x = img_w - subpart_x * offset_x; - int remainder_y = img_h - subpart_y * offset_y; - int subpart_w = (remainder_x < tex_w) ? remainder_x : tex_w; - int subpart_h = (remainder_y < tex_h) ? remainder_y : tex_h; - int offset_left = (seamless && subpart_x != 0) ? 1 : 0; - int offset_bot = (seamless && subpart_y != 0) ? 1 : 0; - int offset_right = (seamless && remainder_x > tex_w) ? 1 : 0; - int offset_top = (seamless && remainder_y > tex_h) ? 1 : 0; - float rast_x = x + subpart_x * offset_x * xzoom; - float rast_y = y + subpart_y * offset_y * yzoom; - /* check if we already got these because we always get 2 more when doing seamless */ - if (subpart_w <= seamless || subpart_h <= seamless) - continue; - - if (use_clipping) { - if (rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX < clip_min_x || - rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY < clip_min_y) - { - continue; - } - if (rast_x + (float)offset_left * xzoom > clip_max_x || - rast_y + (float)offset_bot * yzoom > clip_max_y) - { - continue; - } - } - - if (type == GL_FLOAT) { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]); - - /* add an extra border of pixels so linear looks ok at edges of full image */ - if (subpart_w < tex_w) - glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - if (subpart_h < tex_h) - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, subpart_h, subpart_w, 1, format, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]); - if (subpart_w < tex_w && subpart_h < tex_h) - glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, subpart_h, 1, 1, format, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - } - else { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]); - - if (subpart_w < tex_w) - glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - if (subpart_h < tex_h) - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, subpart_h, subpart_w, 1, format, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]); - if (subpart_w < tex_w && subpart_h < tex_h) - glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, subpart_h, 1, 1, format, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - } - - GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR); - glBegin(GL_QUADS); - glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h); - glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom); - - glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h); - glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)offset_bot * yzoom); - - glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(subpart_h - offset_top) / tex_h); - glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY); - - glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h); - glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY); - glEnd(); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); - } - } - - glBindTexture(GL_TEXTURE_2D, 0); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); -} - -/* DEPRECATED: use immDrawPixelsTexScaled instead */ -void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, - int format, int type, int zoomfilter, void *rect, - float scaleX, float scaleY) -{ - glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, - scaleX, scaleY, 0.0f, 0.0f, 0.0f, 0.0f); -} - -/* DEPRECATED: use immDrawPixelsTex instead */ -void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect) -{ - glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f, - 0.0f, 0.0f, 0.0f, 0.0f); -} - -/* DEPRECATED: use immDrawPixelsTex_clipping instead */ -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) -{ - glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f, - clip_min_x, clip_min_y, clip_max_x, clip_max_y); -} - -void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect) -{ - float xzoom = glaGetOneFloat(GL_ZOOM_X); - float yzoom = glaGetOneFloat(GL_ZOOM_Y); - - /* The pixel space coordinate of the intersection of - * the [zoomed] image with the origin. - */ - float ix = -x / xzoom; - float iy = -y / yzoom; - - /* The maximum pixel amounts the image can be cropped - * at the lower left without exceeding the origin. - */ - int off_x = floor(max_ff(ix, 0.0f)); - int off_y = floor(max_ff(iy, 0.0f)); - - /* The zoomed space coordinate of the raster position - * (starting at the lower left most unclipped pixel). - */ - float rast_x = x + off_x * xzoom; - float rast_y = y + off_y * yzoom; - - GLfloat scissor[4]; - int draw_w, draw_h; - - /* Determine the smallest number of pixels we need to draw - * before the image would go off the upper right corner. - * - * It may seem this is just an optimization but some graphics - * cards (ATI) freak out if there is a large zoom factor and - * a large number of pixels off the screen (probably at some - * level the number of image pixels to draw is getting multiplied - * by the zoom and then clamped). Making sure we draw the - * fewest pixels possible keeps everyone mostly happy (still - * fails if we zoom in on one really huge pixel so that it - * covers the entire screen). - */ - glGetFloatv(GL_SCISSOR_BOX, scissor); - draw_w = min_ii(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom)); - draw_h = min_ii(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom)); - - if (draw_w > 0 && draw_h > 0) { - - int bound_options; - GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options); - - /* Don't use safe RasterPos (slower) if we can avoid it. */ - if (rast_x >= 0 && rast_y >= 0) { - glRasterPos2f(rast_x, rast_y); - } - else { - glaRasterPosSafe2f(rast_x, rast_y, 0, 0); - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w); - if (format == GL_LUMINANCE || format == GL_RED) { - if (type == GL_FLOAT) { - const float *f_rect = (float *)rect; - glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x)); - } - else if (type == GL_INT || type == GL_UNSIGNED_INT) { - const int *i_rect = (int *)rect; - glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y * row_w + off_x)); - } - } - else { /* RGBA */ - if (type == GL_FLOAT) { - const float *f_rect = (float *)rect; - glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x) * 4); - } - else if (type == GL_UNSIGNED_BYTE) { - unsigned char *uc_rect = (unsigned char *) rect; - glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y * row_w + off_x) * 4); - } - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options); - } -} - -/* uses either DrawPixelsSafe or DrawPixelsTex, based on user defined maximum */ -void glaDrawPixelsAuto_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) -{ - if (U.image_draw_method != IMAGE_DRAW_METHOD_DRAWPIXELS) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glaDrawPixelsTex_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, - clip_min_x, clip_min_y, clip_max_x, clip_max_y); - } - else { - glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect); - } -} - -void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect) -{ - glaDrawPixelsAuto_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, - 0.0f, 0.0f, 0.0f, 0.0f); -} -#endif - /* To be used before calling immDrawPixelsTex * Default shader is GPU_SHADER_2D_IMAGE_COLOR * You can still set uniforms with : |