diff --git a/source/build/include/build.h b/source/build/include/build.h index 555603082..37b93a408 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -836,7 +836,7 @@ void renderSetAspect(int32_t daxrange, int32_t daaspect); inline void renderFlushPerms(void) {} void plotpixel(int32_t x, int32_t y, char col); -void renderSetTarget(int16_t tilenume, int32_t xsiz, int32_t ysiz); +FCanvasTexture *renderSetTarget(int16_t tilenume); void renderRestoreTarget(); void renderPrepareMirror(int32_t dax, int32_t day, int32_t daz, fix16_t daang, fix16_t dahoriz, int16_t dawall, int32_t *tposx, int32_t *tposy, fix16_t *tang); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index d26b9b821..0d4ce1c96 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -5356,16 +5356,15 @@ static vec2_t bakwindowxy1, bakwindowxy2; // // setviewtotile // -void renderSetTarget(int16_t tilenume, int32_t xsiz, int32_t ysiz) +FCanvasTexture* renderSetTarget(int16_t tilenume) { - if (setviewcnt > 0) - return; - if (xsiz <= 0 || - ysiz <= 0) - return; - - OpenGLRenderer::GLRenderer->StartOffscreen(); - OpenGLRenderer::GLRenderer->BindToFrameBuffer(tileGetTexture(tilenume)->GetTexture()); + auto tex = tileGetTexture(tilenume); + if (!tex || !tex->isHardwareCanvas()) return nullptr; + auto canvas = static_cast(tex->GetTexture()); + if (!canvas) return nullptr; + int xsiz = tex->GetTexelWidth(), ysiz = tex->GetTexelHeight(); + if (setviewcnt > 0 || xsiz <= 0 || ysiz <= 0) + return nullptr; //DRAWROOMS TO TILE BACKUP&SET CODE bakxsiz = xdim; bakysiz = ydim; @@ -5374,10 +5373,11 @@ void renderSetTarget(int16_t tilenume, int32_t xsiz, int32_t ysiz) setviewcnt++; - xdim = ysiz*4; - ydim = xsiz*4; - videoSetViewableArea(0,0,ysiz*4-1,xsiz*4-1); + xdim = ysiz; + ydim = xsiz; + videoSetViewableArea(0,0,ysiz-1,xsiz-1); renderSetAspect(65536,65536); + return canvas; } @@ -5389,8 +5389,6 @@ void renderRestoreTarget() if (setviewcnt <= 0) return; setviewcnt--; - OpenGLRenderer::GLRenderer->EndOffscreen(); - xdim = bakxsiz; ydim = bakysiz; videoSetViewableArea(bakwindowxy1.x,bakwindowxy1.y, diff --git a/source/duke3d/src/sector.cpp b/source/duke3d/src/sector.cpp index 3c90156bc..e5e11b4d7 100644 --- a/source/duke3d/src/sector.cpp +++ b/source/duke3d/src/sector.cpp @@ -385,36 +385,32 @@ int SetAnimation(int sectNum, int32_t *animPtr, int goalVal, int animVel) static void G_SetupCamTile(int spriteNum, int tileNum, int smoothRatio) { - int const playerNum = screenpeek; - - vec3_t const camera = G_GetCameraPosition(spriteNum, smoothRatio); + vec3_t const camera = G_GetCameraPosition(spriteNum, smoothRatio); int const saveMirror = display_mirror; - renderSetTarget(tileNum, tilesiz[tileNum].y, tilesiz[tileNum].x); + auto canvas = renderSetTarget(tileNum); + if (!canvas) return; - int const noDraw = VM_OnEventWithReturn(EVENT_DISPLAYROOMSCAMERATILE, spriteNum, playerNum, 0); + screen->RenderTextureView(canvas, [=](IntRect& rect) + { + // Beware! Apparently this is allowed to render to the camera itself. Breakage is basically guarenteed... + if (VM_OnEventWithReturn(EVENT_DISPLAYROOMSCAMERATILE, spriteNum, screenpeek, 0) != 1) + { + yax_preparedrawrooms(); + drawrooms(camera.x, camera.y, camera.z, SA(spriteNum), 100 + sprite[spriteNum].shade, SECT(spriteNum)); + yax_drawrooms(G_DoSpriteAnimations, SECT(spriteNum), 0, smoothRatio); - if (noDraw == 1) - goto finishTileSetup; -#ifdef DEBUGGINGAIDS - else if (EDUKE32_PREDICT_FALSE(noDraw != 0)) // event return values other than 0 and 1 are reserved - Printf(TEXTCOLOR_RED "ERROR: EVENT_DISPLAYROOMSCAMERATILE return value must be 0 or 1, " - "other values are reserved.\n"); -#endif - - yax_preparedrawrooms(); - drawrooms(camera.x, camera.y, camera.z, SA(spriteNum), 100 + sprite[spriteNum].shade, SECT(spriteNum)); - yax_drawrooms(G_DoSpriteAnimations, SECT(spriteNum), 0, smoothRatio); - - display_mirror = 3; - G_DoSpriteAnimations(camera.x, camera.y, camera.z, SA(spriteNum), smoothRatio); - display_mirror = saveMirror; - renderDrawMasks(); - -finishTileSetup: + display_mirror = 3; + G_DoSpriteAnimations(camera.x, camera.y, camera.z, SA(spriteNum), smoothRatio); + display_mirror = saveMirror; + renderDrawMasks(); + } + }); renderRestoreTarget(); + } + void G_AnimateCamSprite(int smoothRatio) { #ifdef DEBUG_VALGRIND_NO_SMC diff --git a/source/rr/src/sector.cpp b/source/rr/src/sector.cpp index 9574e1ad2..8ec44741d 100644 --- a/source/rr/src/sector.cpp +++ b/source/rr/src/sector.cpp @@ -506,18 +506,23 @@ static void G_SetupCamTile(int spriteNum, int tileNum, int smoothRatio) vec3_t const camera = G_GetCameraPosition(spriteNum, smoothRatio); int const saveMirror = display_mirror; - renderSetTarget(tileNum, tilesiz[tileNum].y, tilesiz[tileNum].x); + auto canvas = renderSetTarget(tileNum); + if (!canvas) return; - yax_preparedrawrooms(); - drawrooms(camera.x, camera.y, camera.z, SA(spriteNum), 100 + sprite[spriteNum].shade, SECT(spriteNum)); - yax_drawrooms(G_DoSpriteAnimations, SECT(spriteNum), 0, smoothRatio); + screen->RenderTextureView(canvas, [=](IntRect& rect) + { + yax_preparedrawrooms(); + drawrooms(camera.x, camera.y, camera.z, SA(spriteNum), 100 + sprite[spriteNum].shade, SECT(spriteNum)); + yax_drawrooms(G_DoSpriteAnimations, SECT(spriteNum), 0, smoothRatio); - display_mirror = 3; - G_DoSpriteAnimations(camera.x, camera.y, camera.z, SA(spriteNum), smoothRatio); - display_mirror = saveMirror; - renderDrawMasks(); + display_mirror = 3; + G_DoSpriteAnimations(camera.x, camera.y, camera.z, SA(spriteNum), smoothRatio); + display_mirror = saveMirror; + renderDrawMasks(); + }); renderRestoreTarget(); + } void G_AnimateCamSprite(int smoothRatio) diff --git a/source/sw/src/jsector.cpp b/source/sw/src/jsector.cpp index 55dd1af2f..47415ad9c 100644 --- a/source/sw/src/jsector.cpp +++ b/source/sw/src/jsector.cpp @@ -477,11 +477,15 @@ void drawroomstotile(int daposx, int daposy, int daposz, { TileFiles.MakeCanvas(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y); - renderSetTarget(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y); + auto canvas = renderSetTarget(tilenume); + if (!canvas) return; - renderDrawRoomsQ16(daposx, daposy, daposz, daq16ang, daq16horiz, dacursectnum); - analyzesprites(daposx, daposy, daposz, FALSE); - renderDrawMasks(); + screen->RenderTextureView(canvas, [=](IntRect& rect) + { + renderDrawRoomsQ16(daposx, daposy, daposz, daq16ang, daq16horiz, dacursectnum); + analyzesprites(daposx, daposy, daposz, FALSE); + renderDrawMasks(); + }); renderRestoreTarget(); }