Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-02-13 20:09:58 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-02-13 22:02:31 +0300
commite9b1163162d78324c118d3649451e81644b1af03 (patch)
treeeed298e1f49708960a548268a75a05e83da37a58 /source/blender/windowmanager/intern/wm_draw.c
parentafb213f876e32c2ecd12a159fad8d260f37b142a (diff)
Code cleanup: stop using rectangle textures in window draw, simplify code.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_draw.c')
-rw-r--r--source/blender/windowmanager/intern/wm_draw.c68
1 files changed, 21 insertions, 47 deletions
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index b12dbf7b021..d103f2291bf 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -430,15 +430,8 @@ static void wm_draw_triple_fail(bContext *C, wmWindow *win)
static bool wm_triple_gen_textures(wmWindow *win, wmDrawTriple *triple)
{
/* compute texture sizes */
- triple->x = WM_window_pixels_x(win);
- triple->y = WM_window_pixels_y(win);
-
-#if USE_TEXTURE_RECTANGLE
- /* GL_TEXTURE_RECTANGLE is part of GL 3.1 so we can use it soon without runtime checks */
- triple->target = GL_TEXTURE_RECTANGLE;
-#else
- triple->target = GL_TEXTURE_2D;
-#endif
+ const int sizex = WM_window_pixels_x(win);
+ const int sizey = WM_window_pixels_y(win);
/* generate texture names */
glGenTextures(1, &triple->bind);
@@ -447,29 +440,25 @@ static bool wm_triple_gen_textures(wmWindow *win, wmDrawTriple *triple)
* there is only one texture in use, which may not be the case */
const GLint maxsize = GPU_max_texture_size();
- if (triple->x > maxsize || triple->y > maxsize) {
+ if (sizex > maxsize || sizey > maxsize) {
printf("WM: failed to allocate texture for triple buffer drawing "
"(texture too large for graphics card).\n");
return false;
}
/* setup actual texture */
- glBindTexture(triple->target, triple->bind);
+ glBindTexture(GL_TEXTURE_2D, triple->bind);
/* no mipmaps */
-#if USE_TEXTURE_RECTANGLE
- /* already has no mipmaps */
-#else
- glTexParameteri(triple->target, GL_TEXTURE_MAX_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
/* GL_TEXTURE_BASE_LEVEL = 0 by default */
-#endif
- glTexParameteri(triple->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(triple->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(triple->target, 0, GL_RGB8, triple->x, triple->y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, sizex, sizey, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(triple->target, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
return true;
}
@@ -480,19 +469,10 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
const int sizey = WM_window_pixels_y(win);
/* wmOrtho for the screen has this same offset */
- float ratiox = sizex;
- float ratioy = sizey;
- float halfx = GLA_PIXEL_OFS;
- float halfy = GLA_PIXEL_OFS;
-
-#if USE_TEXTURE_RECTANGLE
- /* texture rectangle has unnormalized coordinates */
-#else
- ratiox /= triple->x;
- ratioy /= triple->y;
- halfx /= triple->x;
- halfy /= triple->y;
-#endif
+ const float ratiox = 1.0f;
+ const float ratioy = 1.0f;
+ const float halfx = GLA_PIXEL_OFS / sizex;
+ const float halfy = GLA_PIXEL_OFS / sizey;
Gwn_VertFormat *format = immVertexFormat();
unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
@@ -500,16 +480,10 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
const int activeTex = 7; /* arbitrary */
glActiveTexture(GL_TEXTURE0 + activeTex);
- glBindTexture(triple->target, triple->bind);
-
-#if USE_TEXTURE_RECTANGLE
- immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA);
-#else
- immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_MODULATE_ALPHA);
- /* TODO: make pure 2D version
- * and a 2D_IMAGE (replace, not modulate) version for when alpha = 1.0
- */
-#endif
+ glBindTexture(GL_TEXTURE_2D, triple->bind);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA);
+
immUniform1f("alpha", alpha);
immUniform1i("image", activeTex);
@@ -530,7 +504,7 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
immEnd();
immUnbindProgram();
- glBindTexture(triple->target, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
if (activeTex != 0)
glActiveTexture(GL_TEXTURE0);
}
@@ -540,10 +514,10 @@ static void wm_triple_copy_textures(wmWindow *win, wmDrawTriple *triple)
const int sizex = WM_window_pixels_x(win);
const int sizey = WM_window_pixels_y(win);
- glBindTexture(triple->target, triple->bind);
+ glBindTexture(GL_TEXTURE_2D, triple->bind);
/* what is GL_READ_BUFFER right now? */
- glCopyTexSubImage2D(triple->target, 0, 0, 0, 0, 0, sizex, sizey);
- glBindTexture(triple->target, 0);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sizex, sizey);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
static void wm_draw_region_blend(wmWindow *win, ARegion *ar, wmDrawTriple *triple)