Should have done ages ago!
This commit replaces the glDrawPixels and rectwrite_part with the very nice (thanks zr!) glaDrawPixelsSafe() call. Result is: - 3d window background image displays correctly onto the edges when zoomed in extreme - same for UV image window and sequence preview - preview render now doesnt disappear when left part is outside window (zr also deserves kick in butt for not doing this himself in NaN days!) Especially from preview drawing quite some old hacks were deleted. It is even quite some faster. Please notify me when it doesnt work on your card... this now is just 100% according opengl guidelines though :) Also fixes bug #2100
This commit is contained in:
@@ -44,7 +44,6 @@ void image_changed(struct SpaceImage *sima, int dotile);
|
||||
void image_home(void);
|
||||
void image_viewmove(void);
|
||||
void image_viewzoom(unsigned short event);
|
||||
void rectwrite_part(int winxmin, int winymin, int winxmax, int winymax, int x1, int y1, int xim, int yim, float zoomx, float zoomy, unsigned int *rect);
|
||||
void uvco_to_areaco(float *vec, short *mval);
|
||||
void uvco_to_areaco_noclip(float *vec, short *mval);
|
||||
void what_image(struct SpaceImage *sima);
|
||||
|
||||
@@ -86,71 +86,11 @@
|
||||
#include "butspace.h" // event codes
|
||||
|
||||
|
||||
void rectwrite_part(int winxmin, int winymin, int winxmax, int winymax, int x1, int y1, int xim, int yim, float zoomx, float zoomy, unsigned int *rect)
|
||||
{
|
||||
int cx, cy, oldxim, x2, y2;
|
||||
|
||||
oldxim= xim;
|
||||
|
||||
/* coordinates how its drawn at the screen */
|
||||
x2= x1+ zoomx*xim;
|
||||
y2= y1+ zoomy*yim;
|
||||
|
||||
/* partial clip */
|
||||
if(x1<winxmin) {
|
||||
/* with OpenGL, rects are not allowed to start outside of the left/bottom window edge */
|
||||
cx= winxmin-x1+(int)zoomx;
|
||||
/* make sure the rect will be drawn pixel-exact */
|
||||
cx/= zoomx;
|
||||
cx++;
|
||||
x1+= zoomx*cx;
|
||||
xim-= cx;
|
||||
rect+= cx;
|
||||
}
|
||||
if(y1<winymin) {
|
||||
cy= winymin-y1+(int)zoomy;
|
||||
cy/= zoomy;
|
||||
cy++;
|
||||
y1+= zoomy*cy;
|
||||
rect+= cy*oldxim;
|
||||
yim-= cy;
|
||||
}
|
||||
if(x2>=winxmax) {
|
||||
cx= x2-winxmax;
|
||||
cx/= zoomx;
|
||||
xim-= cx+3;
|
||||
}
|
||||
if(y2>=winymax) {
|
||||
cy= y2-winymax;
|
||||
cy/= zoomy;
|
||||
yim-= cy+3;
|
||||
}
|
||||
|
||||
if(xim<=0) return;
|
||||
if(yim<=0) return;
|
||||
|
||||
mywinset(G.curscreen->mainwin);
|
||||
glScissor(winxmin, winymin, winxmax-winxmin+1, winymax-winymin+1);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, oldxim);
|
||||
|
||||
glPixelZoom(zoomx, zoomy);
|
||||
|
||||
glRasterPos2i(x1, y1);
|
||||
glDrawPixels(xim, yim, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
|
||||
mywinset(curarea->win);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fields of the View2D member of the SpaceImage struct
|
||||
* This routine can be called in two modes:
|
||||
* mode == 'f': float mode ???
|
||||
* mode == 'p': pixel mode ???
|
||||
* mode == 'f': float mode (0.0 - 1.0)
|
||||
* mode == 'p': pixel mode (0 - size)
|
||||
*
|
||||
* @param sima the image space to update
|
||||
* @param mode the mode to use for the update
|
||||
@@ -875,15 +815,20 @@ void drawimagespace(ScrArea *sa, void *spacedata)
|
||||
}
|
||||
else {
|
||||
/* calc location */
|
||||
x1= xmin+(curarea->winx-G.sima->zoom*ibuf->x)/2;
|
||||
y1= ymin+(curarea->winy-G.sima->zoom*ibuf->y)/2;
|
||||
x1= (curarea->winx-G.sima->zoom*ibuf->x)/2;
|
||||
y1= (curarea->winy-G.sima->zoom*ibuf->y)/2;
|
||||
|
||||
x1-= G.sima->zoom*G.sima->xof;
|
||||
y1-= G.sima->zoom*G.sima->yof;
|
||||
|
||||
|
||||
/* needed for gla draw */
|
||||
glaDefine2DArea(&curarea->winrct);
|
||||
glPixelZoom((float)G.sima->zoom, (float)G.sima->zoom);
|
||||
|
||||
if(G.sima->flag & SI_EDITTILE) {
|
||||
rectwrite_part(xmin, ymin, xmax, ymax, x1, y1, ibuf->x, ibuf->y, (float)G.sima->zoom, (float)G.sima->zoom, ibuf->rect);
|
||||
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect);
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
dx= ibuf->x/G.sima->image->xrep;
|
||||
dy= ibuf->y/G.sima->image->yrep;
|
||||
@@ -902,9 +847,9 @@ void drawimagespace(ScrArea *sa, void *spacedata)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glRects(sx+1, sy+1, sx+dx, sy+dy); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
else if(G.sima->mode==SI_TEXTURE) {
|
||||
|
||||
if(G.sima->image->tpageflag & IMA_TILES) {
|
||||
|
||||
|
||||
/* just leave this a while */
|
||||
if(G.sima->image->xrep<1) return;
|
||||
if(G.sima->image->yrep<1) return;
|
||||
@@ -926,17 +871,17 @@ void drawimagespace(ScrArea *sa, void *spacedata)
|
||||
/* rect= ibuf->rect; */
|
||||
for(sy= 0; sy+dy<=ibuf->y; sy+= dy) {
|
||||
for(sx= 0; sx+dx<=ibuf->x; sx+= dx) {
|
||||
|
||||
rectwrite_part(xmin, ymin, xmax, ymax,
|
||||
x1+sx*G.sima->zoom, y1+sy*G.sima->zoom, dx, dy, (float)G.sima->zoom, (float)G.sima->zoom, rect);
|
||||
glaDrawPixelsSafe(x1+sx*G.sima->zoom, y1+sy*G.sima->zoom, dx, dy, rect);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(rect);
|
||||
}
|
||||
else
|
||||
rectwrite_part(xmin, ymin, xmax, ymax, x1, y1, ibuf->x, ibuf->y, (float)G.sima->zoom,(float)G.sima->zoom, ibuf->rect);
|
||||
|
||||
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect);
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
draw_tfaces();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#include "BIF_screen.h"
|
||||
#include "BIF_drawseq.h"
|
||||
#include "BIF_editseq.h"
|
||||
#include "BIF_drawimage.h"
|
||||
#include "BIF_glutil.h"
|
||||
#include "BIF_resources.h"
|
||||
#include "BIF_space.h"
|
||||
#include "BIF_interface.h"
|
||||
@@ -497,12 +497,16 @@ static void draw_image_seq(ScrArea *sa)
|
||||
if(sseq==0) return;
|
||||
|
||||
/* calc location */
|
||||
x1= sa->winrct.xmin+(sa->winx-sseq->zoom*ibuf->x)/2;
|
||||
y1= sa->winrct.ymin+(sa->winy-sseq->zoom*ibuf->y)/2;
|
||||
x1= (sa->winx-sseq->zoom*ibuf->x)/2;
|
||||
y1= (sa->winy-sseq->zoom*ibuf->y)/2;
|
||||
|
||||
rectwrite_part(sa->winrct.xmin, sa->winrct.ymin,
|
||||
sa->winrct.xmax, sa->winrct.ymax,
|
||||
x1, y1, ibuf->x, ibuf->y, (float)sseq->zoom,(float)sseq->zoom, ibuf->rect);
|
||||
/* needed for gla draw */
|
||||
glaDefine2DArea(&curarea->winrct);
|
||||
glPixelZoom((float)sseq->zoom, (float)sseq->zoom);
|
||||
|
||||
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect);
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
sa->win_swap= WIN_BACK_OK;
|
||||
}
|
||||
@@ -776,7 +780,6 @@ void drawseqspace(ScrArea *sa, void *spacedata)
|
||||
sseq= curarea->spacedata.first;
|
||||
if(sseq->mainb==1) {
|
||||
draw_image_seq(curarea);
|
||||
curarea->win_swap= WIN_BACK_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,17 +93,18 @@
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_resources.h"
|
||||
#include "BIF_screen.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_space.h"
|
||||
#include "BIF_butspace.h"
|
||||
#include "BIF_drawimage.h"
|
||||
#include "BIF_editgroup.h"
|
||||
#include "BIF_mywindow.h"
|
||||
#include "BIF_editarmature.h"
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_mywindow.h"
|
||||
#include "BIF_poseobject.h"
|
||||
#include "BIF_resources.h"
|
||||
#include "BIF_screen.h"
|
||||
#include "BIF_space.h"
|
||||
|
||||
#include "BDR_drawmesh.h"
|
||||
#include "BDR_drawobject.h"
|
||||
@@ -427,9 +428,11 @@ static void draw_bgpic(void)
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
rectwrite_part(curarea->winrct.xmin, curarea->winrct.ymin, curarea->winrct.xmax, curarea->winrct.ymax,
|
||||
x1+curarea->winrct.xmin, y1+curarea->winrct.ymin, ima->ibuf->x, ima->ibuf->y, zoomx, zoomy, bgpic->rect);
|
||||
|
||||
glaDefine2DArea(&curarea->winrct);
|
||||
glPixelZoom(zoomx, zoomy);
|
||||
glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, bgpic->rect);
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
if(G.zbuf) glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
#include "BIF_screen.h"
|
||||
#include "BIF_space.h" /* allqueue */
|
||||
#include "BIF_butspace.h"
|
||||
#include "BIF_drawimage.h" /* rectwrite_part */
|
||||
#include "BIF_mywindow.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_glutil.h"
|
||||
@@ -91,6 +90,7 @@
|
||||
#include "RE_renderconverter.h"
|
||||
|
||||
#include "blendef.h" /* CLAMP */
|
||||
#include "interface.h" /* ui_graphics_to_window() SOLVE! (ton) */
|
||||
|
||||
#define PR_RECTX 141
|
||||
#define PR_RECTY 141
|
||||
@@ -101,8 +101,7 @@
|
||||
|
||||
#define PR_FACY (PR_YMAX-PR_YMIN-4)/(PR_RECTY)
|
||||
|
||||
static rcti prerect;
|
||||
static int pr_sizex, pr_sizey;
|
||||
static rctf prerect;
|
||||
static float pr_facx, pr_facy;
|
||||
|
||||
|
||||
@@ -236,61 +235,58 @@ static unsigned int previewback(int type, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
static void view2d_to_window(int win, int *x_r, int *y_r)
|
||||
{
|
||||
int x= *x_r, y= *y_r;
|
||||
int size[2], origin[2];
|
||||
float winmat[4][4];
|
||||
|
||||
bwin_getsinglematrix(win, winmat);
|
||||
bwin_getsize(win, &size[0], &size[1]);
|
||||
bwin_getsuborigin(win, &origin[0], &origin[1]);
|
||||
|
||||
*x_r= origin[0] + (size[0]*(0.5 + 0.5*(x*winmat[0][0] + y*winmat[1][0] + winmat[3][0])));
|
||||
*y_r= origin[1] + (size[1]*(0.5 + 0.5*(x*winmat[0][1] + y*winmat[1][1] + winmat[3][1])));
|
||||
}
|
||||
|
||||
static void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax)
|
||||
{
|
||||
float pr_sizex, pr_sizey;
|
||||
|
||||
prerect.xmin= xmin;
|
||||
prerect.ymin= ymin;
|
||||
prerect.xmax= xmax;
|
||||
prerect.ymax= ymax;
|
||||
|
||||
view2d_to_window(win, &prerect.xmin, &prerect.ymin);
|
||||
view2d_to_window(win, &prerect.xmax, &prerect.ymax);
|
||||
ui_graphics_to_window(win, &prerect.xmin, &prerect.ymin);
|
||||
ui_graphics_to_window(win, &prerect.xmax, &prerect.ymax);
|
||||
|
||||
pr_sizex= (prerect.xmax-prerect.xmin);
|
||||
pr_sizey= (prerect.ymax-prerect.ymin);
|
||||
|
||||
pr_facx= ( (float)pr_sizex-1)/PR_RECTX;
|
||||
pr_facy= ( (float)pr_sizey-1)/PR_RECTY;
|
||||
pr_facx= ( pr_sizex-1.0)/PR_RECTX;
|
||||
pr_facy= ( pr_sizey-1.0)/PR_RECTY;
|
||||
|
||||
/* correction for gla draw */
|
||||
prerect.xmin-= curarea->winrct.xmin;
|
||||
prerect.ymin-= curarea->winrct.ymin;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
glaDefine2DArea(&curarea->winrct);
|
||||
|
||||
glPixelZoom(pr_facx, pr_facy);
|
||||
|
||||
}
|
||||
|
||||
static void end_previewrect(void)
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
}
|
||||
|
||||
static void display_pr_scanline(unsigned int *rect, int recty)
|
||||
{
|
||||
static double lasttime= 0;
|
||||
/* we display 3 new scanlines, one old, the overlap is for wacky 3d cards that cant handle zoom proper */
|
||||
|
||||
if(recty % 2) return;
|
||||
if(recty<2) return;
|
||||
|
||||
rect+= (recty-2)*PR_RECTX;
|
||||
|
||||
/* enlarge a bit in the y direction, to avoid GL/mesa bug */
|
||||
glPixelZoom(pr_facx, pr_facy);
|
||||
|
||||
glRasterPos2f( (float)PR_XMIN+0.5, 1.0+(float)PR_YMIN + (recty*PR_FACY) );
|
||||
glDrawPixels(PR_RECTX, 3, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
||||
|
||||
//glaDrawPixelsTex((float)PR_XMIN, (float)PR_YMIN + (recty*PR_FACY), PR_RECTX, 3, rect);
|
||||
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
||||
/* flush opengl for cards with frontbuffer slowness */
|
||||
if(recty==PR_RECTY-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) {
|
||||
lasttime= PIL_check_seconds_timer();
|
||||
glFlush();
|
||||
if(recty & 1) {
|
||||
|
||||
rect+= (recty-1)*PR_RECTX;
|
||||
|
||||
glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-1.0)*pr_facy), PR_RECTX, 2, rect);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +382,8 @@ void BIF_previewdraw(void)
|
||||
}
|
||||
}
|
||||
if(sbuts->cury==0) BIF_preview_changed(sbuts);
|
||||
|
||||
end_previewrect();
|
||||
}
|
||||
|
||||
static void sky_preview_pixel(float lens, int x, int y, char *rect)
|
||||
@@ -1002,6 +1000,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
|
||||
|
||||
void BIF_previewrender(SpaceButs *sbuts)
|
||||
{
|
||||
static double lasttime= 0;
|
||||
ID *id, *idfrom;
|
||||
Material *mat= NULL;
|
||||
Tex *tex= NULL;
|
||||
@@ -1139,7 +1138,9 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
init_render_textures(); /* dont do it twice!! (brightness) */
|
||||
}
|
||||
|
||||
set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX);
|
||||
uiPanelPush(block); // sets 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");
|
||||
@@ -1175,7 +1176,6 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
|
||||
/* here it starts! */
|
||||
glDrawBuffer(GL_FRONT);
|
||||
uiPanelPush(block);
|
||||
|
||||
for(y=starty; y<endy; y++) {
|
||||
|
||||
@@ -1266,6 +1266,12 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
|
||||
display_pr_scanline(sbuts->rect, sbuts->cury);
|
||||
|
||||
/* flush opengl for cards with frontbuffer slowness */
|
||||
if(sbuts->cury==PR_RECTY-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) {
|
||||
lasttime= PIL_check_seconds_timer();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
sbuts->cury++;
|
||||
}
|
||||
|
||||
@@ -1273,6 +1279,8 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX)
|
||||
draw_tex_crop(sbuts->lockpoin);
|
||||
|
||||
end_previewrect();
|
||||
|
||||
glDrawBuffer(GL_BACK);
|
||||
/* draw again for clean swapbufers */
|
||||
BIF_previewdraw();
|
||||
|
||||
Reference in New Issue
Block a user