int lh_saveimage(lua_State *L) { checkArg(L, 2, "saveimage"); Image *o = luaO(1, Image); if(useGL(o)) screenshotGL(luaStr(2)); else SDL_SaveBMP(o->s, luaStr(2)); return 0; }
int lh_getpixel(lua_State *L) { checkArg(L, 3, "getpixel"); Image *srcI = luaO(1, Image); int srcX = luaInt(2); int srcY = luaInt(3); #ifdef OPENGL if(useGL(srcI)) return retInt(L, getpixelGL(srcX, srcY)); #endif srcI->setLock(true); int res = qpixel(srcI->s, srcX, srcY); return retInt(L, res); }
int lh_setpixel(lua_State *L) { checkArg(L, 4, "setpixel"); Image *srcI = luaO(1, Image); int srcX = luaInt(2); int srcY = luaInt(3); #ifdef OPENGL if(useGL(srcI)) return 0; #endif srcI->setLock(true); qpixel(srcI->s, srcX, srcY) = luaInt(4); srcI->changes++; return 0; }
int lh_fillimage(lua_State *L) { checkArg(L, 6, "fillimage"); SDL_Rect rect; rect.x = luaInt(2); rect.y = luaInt(3); rect.w = luaInt(4); rect.h = luaInt(5); int col = luaInt(6); Image *img = luaO(1,Image); #ifdef OPENGL if(useGL(img)) fillRectGL(rect.x, rect.y, rect.w, rect.h, col); else #endif SDL_FillRect(img->s, &rect, col); img->changes++; return 0; }
static void testRetarget() { int major, minor; Display *disp1; Window win1; GLXContext ctx1; Display *disp2; Window win2; GLXContext ctx2; fprintf(stderr, "%s: Create #1\n", msg); disp1 = XOpenDisplay(NULL); createGLWin(disp1, 200, 200, &win1, &ctx1); fprintf(stderr, "%s: Create #2\n", msg); disp2 = disp1; // disp2 = XOpenDisplay(NULL); createGLWin(disp2, 300, 300, &win2, &ctx2); fprintf(stderr, "%s: Use #1.1\n", msg); useGL(disp1, win1, ctx1, 200, 200, 0.0f, 1); // OK fprintf(stderr, "%s: Use #1.2\n", msg); useGL(disp2, win2, ctx2, 300, 300, 1.0f, 1); // OK usleep( demodelay ); fprintf(stderr, "%s: Retarget Drawable\n", msg); { Window _win = win2; win2 = win1; win1 = _win; } fprintf(stderr, "%s: Use #2.1\n", msg); useGL(disp1, win1, ctx1, 200, 200, 0.0f, 0); // no setSwapInterval - OK fprintf(stderr, "%s: Use #2.2\n", msg); useGL(disp2, win2, ctx2, 300, 300, 1.0f, 0); // no setSwapInterval - OK usleep( demodelay ); fprintf(stderr, "%s: Use #3.1\n", msg); useGL(disp1, win1, ctx1, 200, 200, 0.1f, 1); // setSwapInterval - crash on Mesa 8.0.4 DRI2 fprintf(stderr, "%s: Use #3.2\n", msg); useGL(disp2, win2, ctx2, 300, 300, 0.9f, 1); // setSwapInterval - crash on Mesa 8.0.4 DRI2 fprintf(stderr, "%s: Success - no bug\n", msg); usleep( demodelay ); fprintf(stderr, "%s: Destroy #1.0\n", msg); glXMakeContextCurrent(disp1, 0, 0, 0); glXDestroyContext(disp1, ctx1); if( disp1 != disp2 ) { XCloseDisplay(disp1); } fprintf(stderr, "%s: Destroy #1.X\n", msg); fprintf(stderr, "%s: Destroy #2.0\n", msg); glXMakeContextCurrent(disp2, 0, 0, 0); glXDestroyContext(disp2, ctx2); XCloseDisplay(disp2); fprintf(stderr, "%s: Destroy #2.X\n", msg); fprintf(stderr, "%s: Exit - OK\n", msg); }
void testOrder(int reverseDestroyOrder, const char * msg) { int major, minor; Display *disp1; Window win1; GLXContext ctx1; Display *disp2; Window win2; GLXContext ctx2; fprintf(stderr, "%s: Create #1\n", msg); disp1 = XOpenDisplay(NULL); XLOCKDISPLAY(disp1); createGLWin(disp1, 200, 200, &win1, &ctx1); useGL(disp1, win1, ctx1, 200, 200); XUNLOCKDISPLAY(disp1); fprintf(stderr, "%s: Create #2\n", msg); disp2 = XOpenDisplay(NULL); XLOCKDISPLAY(disp2); createGLWin(disp2, 300, 300, &win2, &ctx2); useGL(disp2, win2, ctx2, 300, 300); XUNLOCKDISPLAY(disp2); if(reverseDestroyOrder) { fprintf(stderr, "%s: Destroy #2.0\n", msg); XLOCKDISPLAY(disp2); glXMakeCurrent(disp2, 0, 0); glXDestroyContext(disp2, ctx2); XUNLOCKDISPLAY(disp2); XCloseDisplay(disp2); fprintf(stderr, "%s: Destroy #2.X\n", msg); fprintf(stderr, "%s: Destroy #1.0\n", msg); XLOCKDISPLAY(disp1); fprintf(stderr, "%s: Destroy #1.1\n", msg); glXMakeCurrent(disp1, 0, 0); fprintf(stderr, "%s: Destroy #1.2\n", msg); glXDestroyContext(disp1, ctx1); fprintf(stderr, "%s: Destroy #1.3\n", msg); XUNLOCKDISPLAY(disp1); fprintf(stderr, "%s: Destroy #1.4\n", msg); XCloseDisplay(disp1); fprintf(stderr, "%s: Destroy #1.X\n", msg); } else { fprintf(stderr, "%s: Destroy #1.0\n", msg); XLOCKDISPLAY(disp1); glXMakeCurrent(disp1, 0, 0); glXDestroyContext(disp1, ctx1); XUNLOCKDISPLAY(disp1); XCloseDisplay(disp1); fprintf(stderr, "%s: Destroy #1.X\n", msg); fprintf(stderr, "%s: Destroy #2.0\n", msg); XLOCKDISPLAY(disp2); fprintf(stderr, "%s: Destroy #2.1\n", msg); glXMakeCurrent(disp2, 0, 0); fprintf(stderr, "%s: Destroy #2.2\n", msg); glXDestroyContext(disp2, ctx2); fprintf(stderr, "%s: Destroy #2.3\n", msg); XUNLOCKDISPLAY(disp2); fprintf(stderr, "%s: Destroy #2.4\n", msg); XCloseDisplay(disp2); fprintf(stderr, "%s: Destroy #2.X\n", msg); } fprintf(stderr, "%s: Success - no bug\n", msg); }