Skip to content

Commit

Permalink
subraster rendering on gl
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Oct 25, 2020
1 parent ee2a32e commit 5e5a624
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
36 changes: 30 additions & 6 deletions src/gl/gl3device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct GlGlobals
GLFWwindow **pWindow;
#endif
int presentWidth, presentHeight;
int presentOffX, presentOffY;

// for opening the window
int winWidth, winHeight;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rwbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ struct Line

struct Rect
{
int32 h, w;
int32 x, y;
int32 w, h;
};

struct Sphere
Expand Down

0 comments on commit 5e5a624

Please sign in to comment.