From de287825eec01aaa5e8ab925171cd75d86a23cb4 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 17 May 2019 22:50:41 +0200 Subject: start work on display capture also fix a bug in the compositing shader --- src/GPU.cpp | 2 +- src/GPU2D.cpp | 20 +++++++++-- src/GPU3D.h | 1 + src/GPU3D_OpenGL43.cpp | 81 ++++++++++++++++++++++++++++++++++++-------- src/libui_sdl/main_shaders.h | 6 ++-- 5 files changed, 88 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/GPU.cpp b/src/GPU.cpp index 8142e47..1799ef8 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -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); diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index f80eb85..e18f30e 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -656,8 +656,16 @@ void GPU2D::DrawScanline(u32 line) u32 dispmode = DispCnt >> 16; dispmode &= (Num ? 0x1 : 0x3); - if (Num == 0 && !Accelerated) - _3DLine = GPU3D::GetLine(n3dline); + 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; diff --git a/src/GPU3D.h b/src/GPU3D.h index 10c8966..708811f 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -153,6 +153,7 @@ int GetScale(); void VCount144(); void RenderFrame(); +void PrepareCaptureFrame(); u32* GetLine(int line); void SetupAccelFrame(); diff --git a/src/GPU3D_OpenGL43.cpp b/src/GPU3D_OpenGL43.cpp index 062e40e..72956fb 100644 --- a/src/GPU3D_OpenGL43.cpp +++ b/src/GPU3D_OpenGL43.cpp @@ -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<> 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); -- cgit v1.2.3