mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
start work on display capture
also fix a bug in the compositing shader
This commit is contained in:
@ -907,7 +907,7 @@ void StartScanline(u32 line)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (VCount == 192)
|
if (VCount == 192)
|
||||||
{//printf("- VBLANK -\n");vbltime=NDS::ARM9Timestamp;
|
{
|
||||||
// VBlank
|
// VBlank
|
||||||
DispStat[0] |= (1<<0);
|
DispStat[0] |= (1<<0);
|
||||||
DispStat[1] |= (1<<0);
|
DispStat[1] |= (1<<0);
|
||||||
|
@ -656,8 +656,16 @@ void GPU2D::DrawScanline(u32 line)
|
|||||||
u32 dispmode = DispCnt >> 16;
|
u32 dispmode = DispCnt >> 16;
|
||||||
dispmode &= (Num ? 0x1 : 0x3);
|
dispmode &= (Num ? 0x1 : 0x3);
|
||||||
|
|
||||||
if (Num == 0 && !Accelerated)
|
if (Num == 0)
|
||||||
_3DLine = GPU3D::GetLine(n3dline);
|
{
|
||||||
|
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
|
// always render regular graphics
|
||||||
DrawScanline_Mode1(line);
|
DrawScanline_Mode1(line);
|
||||||
@ -862,6 +870,12 @@ void GPU2D::VBlankEnd()
|
|||||||
BGMosaicYMax = BGMosaicSize[1];
|
BGMosaicYMax = BGMosaicSize[1];
|
||||||
OBJMosaicY = 0;
|
OBJMosaicY = 0;
|
||||||
OBJMosaicYMax = OBJMosaicSize[1];
|
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;
|
srcA = _3DLine;
|
||||||
else
|
else
|
||||||
srcA = BGOBJLine;
|
srcA = BGOBJLine;
|
||||||
|
srcA = _3DLine;
|
||||||
u16* srcB = NULL;
|
u16* srcB = NULL;
|
||||||
u32 srcBaddr = line * 256;
|
u32 srcBaddr = line * 256;
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ int GetScale();
|
|||||||
|
|
||||||
void VCount144();
|
void VCount144();
|
||||||
void RenderFrame();
|
void RenderFrame();
|
||||||
|
void PrepareCaptureFrame();
|
||||||
u32* GetLine(int line);
|
u32* GetLine(int line);
|
||||||
void SetupAccelFrame();
|
void SetupAccelFrame();
|
||||||
|
|
||||||
|
@ -100,9 +100,9 @@ int ScaleFactor;
|
|||||||
bool Accelerated;
|
bool Accelerated;
|
||||||
int ScreenW, ScreenH;
|
int ScreenW, ScreenH;
|
||||||
|
|
||||||
GLuint FramebufferTex[6];
|
GLuint FramebufferTex[8];
|
||||||
int FrontBuffer;
|
int FrontBuffer;
|
||||||
GLuint FramebufferID[2], PixelbufferID;
|
GLuint FramebufferID[4], PixelbufferID;
|
||||||
u32* Framebuffer = NULL;
|
u32* Framebuffer = NULL;
|
||||||
|
|
||||||
bool ChunkedRendering = false;
|
bool ChunkedRendering = false;
|
||||||
@ -260,10 +260,10 @@ bool Init()
|
|||||||
glVertexAttribIPointer(3, 3, GL_UNSIGNED_INT, 7*4, (void*)(4*4));
|
glVertexAttribIPointer(3, 3, GL_UNSIGNED_INT, 7*4, (void*)(4*4));
|
||||||
|
|
||||||
|
|
||||||
glGenFramebuffers(2, &FramebufferID[0]);
|
glGenFramebuffers(4, &FramebufferID[0]);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
||||||
|
|
||||||
glGenTextures(6, &FramebufferTex[0]);
|
glGenTextures(8, &FramebufferTex[0]);
|
||||||
FrontBuffer = 0;
|
FrontBuffer = 0;
|
||||||
|
|
||||||
// color buffers
|
// 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_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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
|
// attribute buffer
|
||||||
// R: opaque polyID (for edgemarking)
|
// 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_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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
|
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
|
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]);
|
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_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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]);
|
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);
|
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]);
|
glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
|
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);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
|
||||||
if (accel) glBufferData(GL_PIXEL_PACK_BUFFER, ScreenW*ScreenH*4, NULL, GL_DYNAMIC_READ);
|
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
|
||||||
else glBufferData(GL_PIXEL_PACK_BUFFER, 256*192, NULL, GL_DYNAMIC_READ);
|
|
||||||
|
|
||||||
if (Framebuffer) delete[] Framebuffer;
|
if (Framebuffer) delete[] Framebuffer;
|
||||||
if (accel) Framebuffer = new u32[256*192];
|
if (accel) Framebuffer = new u32[256*192];
|
||||||
@ -774,7 +806,8 @@ void RenderFrame()
|
|||||||
|
|
||||||
if (Accelerated)
|
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;
|
FrontBuffer = FrontBuffer ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,18 +889,36 @@ void RenderFrame()
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Accelerated)
|
/*if (!Accelerated)
|
||||||
{
|
{
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
|
||||||
|
|
||||||
glReadPixels(0, 0, 256<<ScaleFactor, 192<<ScaleFactor, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
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)
|
u32* GetLine(int line)
|
||||||
{
|
{
|
||||||
int stride = 256 << (ScaleFactor*2);
|
int stride = 256;// << (ScaleFactor*2);
|
||||||
|
|
||||||
if (line == 0)
|
if (line == 0)
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,7 @@ out vec4 oColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0));
|
ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0));
|
||||||
|
ivec4 zog=pixel;
|
||||||
// bit0-13: BLDCNT
|
// bit0-13: BLDCNT
|
||||||
// bit14-15: DISPCNT display mode
|
// bit14-15: DISPCNT display mode
|
||||||
// bit16-20: EVA
|
// bit16-20: EVA
|
||||||
@ -86,7 +86,7 @@ void main()
|
|||||||
|
|
||||||
int winmask = top.b >> 7;
|
int winmask = top.b >> 7;
|
||||||
|
|
||||||
if ((top.a & 0x40) != 0)
|
if ((top.a & 0xC0) == 0x40)
|
||||||
{
|
{
|
||||||
float xpos = top.r + fract(fTexcoord.x);
|
float xpos = top.r + fract(fTexcoord.x);
|
||||||
float ypos = mod(fTexcoord.y, 768);
|
float ypos = mod(fTexcoord.y, 768);
|
||||||
@ -96,7 +96,7 @@ void main()
|
|||||||
if (_3dpix.a > 0) { top = _3dpix; top.a |= 0x40; bot = mid; }
|
if (_3dpix.a > 0) { top = _3dpix; top.a |= 0x40; bot = mid; }
|
||||||
else top = mid;
|
else top = mid;
|
||||||
}
|
}
|
||||||
else if ((mid.a & 0x40) != 0)
|
else if ((mid.a & 0xC0) == 0x40)
|
||||||
{
|
{
|
||||||
float xpos = mid.r + fract(fTexcoord.x);
|
float xpos = mid.r + fract(fTexcoord.x);
|
||||||
float ypos = mod(fTexcoord.y, 768);
|
float ypos = mod(fTexcoord.y, 768);
|
||||||
|
Reference in New Issue
Block a user