[Bf-committers] Preview Render Patch
Matthew H. Plough
mplough at Princeton.EDU
Thu May 26 08:38:36 CEST 2005
Hi everyone,
I was sick and tired of the stupid lines showing up for no apparent
reason in material previews, so I decided to do something about it.
Instead of rendering with unreliable copy pixels and scanlines, I render
by making the rendered image into a texture, and mapping it onto a
quadrilateral. The resulting code is very clean and easy to
understand. It is reusable, and is much simpler than the current
implementation. I hope it can make it in for the release.
The patch is attached.
Matt
-------------- next part --------------
Index: previewrender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/previewrender.c,v
retrieving revision 1.58
diff -u -p -u -r1.58 previewrender.c
--- previewrender.c 17 Apr 2005 17:43:07 -0000 1.58
+++ previewrender.c 26 May 2005 06:15:58 -0000
@@ -94,8 +94,8 @@
#include "blendef.h" /* CLAMP */
#include "interface.h" /* ui_graphics_to_window() SOLVE! (ton) */
-#define PR_RECTX 141
-#define PR_RECTY 141
+#define PR_RECTX 256
+#define PR_RECTY 256
#define PR_XMIN 10
#define PR_YMIN 5
#define PR_XMAX 200
@@ -378,17 +378,50 @@ void BIF_previewdraw(void)
{
SpaceButs *sbuts= curarea->spacedata.first;
+ fprintf(stderr, "curarea->spacedata.first: PR_RECTX = %d, PR_RECTY = %d\n",
+ PR_RECTX, PR_RECTY);
+
if (sbuts->rect==0) BIF_preview_changed(sbuts);
else {
- int y;
+ GLuint texid;
+
+ /* generate the texture here for now and bind it */
+ glEnable(GL_TEXTURE_2D);
+ glGenTextures(1, &texid);
+ /* texid is 0 if there is a problem */
+ glBindTexture(GL_TEXTURE_2D, texid);
- set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- for (y=0; y<PR_RECTY; y++) {
- display_pr_scanline(sbuts->rect, y);
- }
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- end_previewrect();
+
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, PR_RECTX, PR_RECTY, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, sbuts->rect);
+
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glDisable(GL_BLEND); /* it looks weird with blending on */
+
+ glBindTexture(GL_TEXTURE_2D, texid);
+ glColor4f(1, 1, 1, 1);
+
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0.0, 0.0); glVertex2f(PR_XMIN, PR_YMIN);
+ glTexCoord2f(0.0, 1.0); glVertex2f(PR_XMIN, PR_YMAX);
+ glTexCoord2f(1.0, 1.0); glVertex2f(PR_XMAX, PR_YMAX);
+ glTexCoord2f(1.0, 0.0); glVertex2f(PR_XMAX, PR_YMIN);
+ glEnd();
+
+ /* delete the texture here for now */
+ glDisable(GL_TEXTURE_2D);
+ glDeleteTextures(1, &texid);
if (sbuts->mainb==CONTEXT_SHADING && sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
draw_tex_crop(sbuts->lockpoin);
@@ -592,10 +625,7 @@ static void previewflare(SpaceButs *sbut
// not sure why, either waitcursor or renderflare screws up (disabled then)
//areawinset(curarea->win);
- /* draw can just be this way, all settings are OK */
- for (y=0; y<PR_RECTY; y++) {
- display_pr_scanline(sbuts->rect, y);
- }
+ BIF_previewdraw();
/* temps */
R.ycor= ycor;
@@ -1167,7 +1197,7 @@ void BIF_previewrender(SpaceButs *sbuts)
uiPanelPush(block); // sets UImat
- set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX); // uses UImat
+ /*set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX);*/ // uses UImat
if(sbuts->rect==NULL) {
sbuts->rect= MEM_callocN(sizeof(int)*PR_RECTX*PR_RECTY, "butsrect");
@@ -1291,7 +1321,7 @@ void BIF_previewrender(SpaceButs *sbuts)
}
}
- display_pr_scanline(sbuts->rect, sbuts->cury);
+ BIF_previewdraw();
/* flush opengl for cards with frontbuffer slowness */
if(sbuts->cury==PR_RECTY-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) {
@@ -1302,7 +1332,7 @@ void BIF_previewrender(SpaceButs *sbuts)
sbuts->cury++;
}
- end_previewrect();
+ /*end_previewrect();*/
if(sbuts->cury>=PR_RECTY && tex)
if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX)
More information about the Bf-committers
mailing list