- use backend independent code to render the camera textures.

This commit is contained in:
Christoph Oelckers 2020-06-14 21:57:21 +02:00
parent d4b32bf79f
commit 2a29dbf793
5 changed files with 53 additions and 50 deletions

View file

@ -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);

View file

@ -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<FCanvasTexture*>(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,

View file

@ -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

View file

@ -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)

View file

@ -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();
}