start work on display capture

also fix a bug in the compositing shader
This commit is contained in:
Arisotura 2019-05-17 22:50:41 +02:00
parent 26f997172b
commit de287825ee
5 changed files with 88 additions and 22 deletions

View File

@ -907,7 +907,7 @@ void StartScanline(u32 line)
else
{
if (VCount == 192)
{//printf("- VBLANK -\n");vbltime=NDS::ARM9Timestamp;
{
// VBlank
DispStat[0] |= (1<<0);
DispStat[1] |= (1<<0);

View File

@ -656,8 +656,16 @@ void GPU2D::DrawScanline(u32 line)
u32 dispmode = DispCnt >> 16;
dispmode &= (Num ? 0x1 : 0x3);
if (Num == 0 && !Accelerated)
if (Num == 0)
{
if (!Accelerated)
_3DLine = GPU3D::GetLine(n3dline);
else if ((CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1))
{
_3DLine = GPU3D::GetLine(n3dline);
//GPU3D::GLRenderer43::PrepareCaptureFrame();
}
}
// always render regular graphics
DrawScanline_Mode1(line);
@ -862,6 +870,12 @@ void GPU2D::VBlankEnd()
BGMosaicYMax = BGMosaicSize[1];
OBJMosaicY = 0;
OBJMosaicYMax = OBJMosaicSize[1];
// TODO: make optional
if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1))
{
GPU3D::GLRenderer43::PrepareCaptureFrame();
}
}
@ -884,7 +898,7 @@ void GPU2D::DoCapture(u32 line, u32 width)
srcA = _3DLine;
else
srcA = BGOBJLine;
srcA = _3DLine;
u16* srcB = NULL;
u32 srcBaddr = line * 256;

View File

@ -153,6 +153,7 @@ int GetScale();
void VCount144();
void RenderFrame();
void PrepareCaptureFrame();
u32* GetLine(int line);
void SetupAccelFrame();

View File

@ -100,9 +100,9 @@ int ScaleFactor;
bool Accelerated;
int ScreenW, ScreenH;
GLuint FramebufferTex[6];
GLuint FramebufferTex[8];
int FrontBuffer;
GLuint FramebufferID[2], PixelbufferID;
GLuint FramebufferID[4], PixelbufferID;
u32* Framebuffer = NULL;
bool ChunkedRendering = false;
@ -260,10 +260,10 @@ bool Init()
glVertexAttribIPointer(3, 3, GL_UNSIGNED_INT, 7*4, (void*)(4*4));
glGenFramebuffers(2, &FramebufferID[0]);
glGenFramebuffers(4, &FramebufferID[0]);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
glGenTextures(6, &FramebufferTex[0]);
glGenTextures(8, &FramebufferTex[0]);
FrontBuffer = 0;
// color buffers
@ -286,7 +286,12 @@ bool Init()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[4], 0);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// attribute buffer
// R: opaque polyID (for edgemarking)
@ -297,16 +302,40 @@ bool Init()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[5], 0);
// downscale framebuffer, for antialiased mode
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// downscale framebuffer for antialiased mode
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[2], 0);
// downscale framebuffer for display capture (always 256x192)
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[3]);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[3]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[3], 0);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[0], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[4], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[5], 0);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[1], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[6], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[7], 0);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
@ -373,10 +402,13 @@ void SetDisplaySettings(int scale, bool accel)
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
if (accel) glBufferData(GL_PIXEL_PACK_BUFFER, ScreenW*ScreenH*4, NULL, GL_DYNAMIC_READ);
else glBufferData(GL_PIXEL_PACK_BUFFER, 256*192, NULL, GL_DYNAMIC_READ);
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
if (Framebuffer) delete[] Framebuffer;
if (accel) Framebuffer = new u32[256*192];
@ -774,7 +806,8 @@ void RenderFrame()
if (Accelerated)
{
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[FrontBuffer], 0);
//glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[FrontBuffer], 0);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]);
FrontBuffer = FrontBuffer ? 0 : 1;
}
@ -856,18 +889,36 @@ void RenderFrame()
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
}
if (!Accelerated)
/*if (!Accelerated)
{
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
glReadPixels(0, 0, 256<<ScaleFactor, 192<<ScaleFactor, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
}*/
}
void PrepareCaptureFrame()
{
// TODO: make sure this picks the right buffer when doing antialiasing
int original_fb = FrontBuffer^1;
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[original_fb]);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[3]);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[3]);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
//glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[original_fb]);
//glFlush();
}
u32* GetLine(int line)
{
int stride = 256 << (ScaleFactor*2);
int stride = 256;// << (ScaleFactor*2);
if (line == 0)
{

View File

@ -65,7 +65,7 @@ out vec4 oColor;
void main()
{
ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0));
ivec4 zog=pixel;
// bit0-13: BLDCNT
// bit14-15: DISPCNT display mode
// bit16-20: EVA
@ -86,7 +86,7 @@ void main()
int winmask = top.b >> 7;
if ((top.a & 0x40) != 0)
if ((top.a & 0xC0) == 0x40)
{
float xpos = top.r + fract(fTexcoord.x);
float ypos = mod(fTexcoord.y, 768);
@ -96,7 +96,7 @@ void main()
if (_3dpix.a > 0) { top = _3dpix; top.a |= 0x40; bot = mid; }
else top = mid;
}
else if ((mid.a & 0x40) != 0)
else if ((mid.a & 0xC0) == 0x40)
{
float xpos = mid.r + fract(fTexcoord.x);
float ypos = mod(fTexcoord.y, 768);