From 5e5a624681a268e759df53edc15a73f587fda6df Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 25 Oct 2020 11:10:14 +0100 Subject: [PATCH] subraster rendering on gl --- src/gl/gl3device.cpp | 36 ++++++++++++++++++++++++++++++------ src/rwbase.h | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index b07e823..877141c 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -52,6 +52,7 @@ struct GlGlobals GLFWwindow **pWindow; #endif int presentWidth, presentHeight; + int presentOffX, presentOffY; // for opening the window int winWidth, winHeight; @@ -1036,8 +1037,8 @@ flushCache(void) static void setFrameBuffer(Camera *cam) { - Raster *fbuf = cam->frameBuffer; - Raster *zbuf = cam->zBuffer; + Raster *fbuf = cam->frameBuffer->parent; + Raster *zbuf = cam->zBuffer->parent; assert(fbuf); Gl3Raster *natfb = PLUGINOFFSET(Gl3Raster, fbuf, nativeRasterOffset); @@ -1151,24 +1152,45 @@ beginUpdate(Camera *cam) setFrameBuffer(cam); 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 SDL_GetWindowSize(glGlobals.window, &w, &h); #else glfwGetWindowSize(glGlobals.window, &w, &h); #endif }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; h = cam->frameBuffer->height; } - if(w != glGlobals.presentWidth || h != glGlobals.presentHeight){ - glViewport(0, 0, w, h); + if(w != glGlobals.presentWidth || h != glGlobals.presentHeight || + x != glGlobals.presentOffX || y != glGlobals.presentOffY){ + glViewport(x, y, w, h); glGlobals.presentWidth = w; glGlobals.presentHeight = h; + glGlobals.presentOffX = x; + glGlobals.presentOffY = y; } } +static void +endUpdate(Camera *cam) +{ +} + static void clearCamera(Camera *cam, RGBA *col, uint32 mode) { @@ -1442,6 +1464,8 @@ printf("version %s\n", glGetString(GL_VERSION)); *glGlobals.pWindow = win; glGlobals.presentWidth = 0; glGlobals.presentHeight = 0; + glGlobals.presentOffX = 0; + glGlobals.presentOffY = 0; return 1; } @@ -1656,7 +1680,7 @@ deviceSystemGLFW(DeviceReq req, void *arg, int32 n) Device renderdevice = { -1.0f, 1.0f, gl3::beginUpdate, - null::endUpdate, + gl3::endUpdate, gl3::clearCamera, gl3::showRaster, gl3::rasterRenderFast, diff --git a/src/rwbase.h b/src/rwbase.h index 6b40302..573269c 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -387,8 +387,8 @@ struct Line struct Rect { - int32 h, w; int32 x, y; + int32 w, h; }; struct Sphere