subraster rendering on gl

This commit is contained in:
aap 2020-10-25 11:10:14 +01:00
parent ee2a32e142
commit 5e5a624681
2 changed files with 31 additions and 7 deletions

View File

@ -52,6 +52,7 @@ struct GlGlobals
GLFWwindow **pWindow; GLFWwindow **pWindow;
#endif #endif
int presentWidth, presentHeight; int presentWidth, presentHeight;
int presentOffX, presentOffY;
// for opening the window // for opening the window
int winWidth, winHeight; int winWidth, winHeight;
@ -1036,8 +1037,8 @@ flushCache(void)
static void static void
setFrameBuffer(Camera *cam) setFrameBuffer(Camera *cam)
{ {
Raster *fbuf = cam->frameBuffer; Raster *fbuf = cam->frameBuffer->parent;
Raster *zbuf = cam->zBuffer; Raster *zbuf = cam->zBuffer->parent;
assert(fbuf); assert(fbuf);
Gl3Raster *natfb = PLUGINOFFSET(Gl3Raster, fbuf, nativeRasterOffset); Gl3Raster *natfb = PLUGINOFFSET(Gl3Raster, fbuf, nativeRasterOffset);
@ -1151,24 +1152,45 @@ beginUpdate(Camera *cam)
setFrameBuffer(cam); setFrameBuffer(cam);
int w, h; int w, h;
if(cam->frameBuffer->type == Raster::CAMERA){ int x, y;
Raster *fb = cam->frameBuffer->parent;
if(fb->type == Raster::CAMERA){
#ifdef LIBRW_SDL2 #ifdef LIBRW_SDL2
SDL_GetWindowSize(glGlobals.window, &w, &h); SDL_GetWindowSize(glGlobals.window, &w, &h);
#else #else
glfwGetWindowSize(glGlobals.window, &w, &h); glfwGetWindowSize(glGlobals.window, &w, &h);
#endif #endif
}else{ }else{
w = fb->width;
h = fb->height;
}
x = 0;
y = 0;
// Got a subraster
if(cam->frameBuffer != fb){
x = cam->frameBuffer->offsetX;
// GL y offset is from bottom
y = h - cam->frameBuffer->height - cam->frameBuffer->offsetY;
w = cam->frameBuffer->width; w = cam->frameBuffer->width;
h = cam->frameBuffer->height; h = cam->frameBuffer->height;
} }
if(w != glGlobals.presentWidth || h != glGlobals.presentHeight){ if(w != glGlobals.presentWidth || h != glGlobals.presentHeight ||
glViewport(0, 0, w, h); x != glGlobals.presentOffX || y != glGlobals.presentOffY){
glViewport(x, y, w, h);
glGlobals.presentWidth = w; glGlobals.presentWidth = w;
glGlobals.presentHeight = h; glGlobals.presentHeight = h;
glGlobals.presentOffX = x;
glGlobals.presentOffY = y;
} }
} }
static void
endUpdate(Camera *cam)
{
}
static void static void
clearCamera(Camera *cam, RGBA *col, uint32 mode) clearCamera(Camera *cam, RGBA *col, uint32 mode)
{ {
@ -1442,6 +1464,8 @@ printf("version %s\n", glGetString(GL_VERSION));
*glGlobals.pWindow = win; *glGlobals.pWindow = win;
glGlobals.presentWidth = 0; glGlobals.presentWidth = 0;
glGlobals.presentHeight = 0; glGlobals.presentHeight = 0;
glGlobals.presentOffX = 0;
glGlobals.presentOffY = 0;
return 1; return 1;
} }
@ -1656,7 +1680,7 @@ deviceSystemGLFW(DeviceReq req, void *arg, int32 n)
Device renderdevice = { Device renderdevice = {
-1.0f, 1.0f, -1.0f, 1.0f,
gl3::beginUpdate, gl3::beginUpdate,
null::endUpdate, gl3::endUpdate,
gl3::clearCamera, gl3::clearCamera,
gl3::showRaster, gl3::showRaster,
gl3::rasterRenderFast, gl3::rasterRenderFast,

View File

@ -387,8 +387,8 @@ struct Line
struct Rect struct Rect
{ {
int32 h, w;
int32 x, y; int32 x, y;
int32 w, h;
}; };
struct Sphere struct Sphere