diff --git a/src/GPU.h b/src/GPU.h index 1564ef7f..47934aa5 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -447,6 +447,7 @@ void Reset(); void SetRenderSettings(RenderSettings& settings); +void DoCapture(u32 capcnt); void RenderFrame(); void BindOutputTexture(); diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 7774c650..3f218719 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -928,6 +928,16 @@ void GPU2D::DrawScanline(u32 line) void GPU2D::VBlank() { +#ifdef OGLRENDERER_ENABLED + if (Accelerated) + { + if ((Num == 0) && (CaptureCnt & (1<<31))) + { + GPU::GLCompositor::DoCapture(CaptureCnt); + } + } +#endif + CaptureCnt &= ~(1<<31); DispFIFOReadPtr = 0; @@ -950,13 +960,13 @@ void GPU2D::VBlankEnd() //OBJMosaicYCount = 0; #ifdef OGLRENDERER_ENABLED - if (Accelerated) + /*if (Accelerated) { if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1)) { GPU3D::GLRenderer::PrepareCaptureFrame(); } - } + }*/ #endif } diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 359e9cd4..372e5199 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -45,6 +45,9 @@ GLuint CompScreenInputTex; GLuint CompScreenOutputTex; GLuint CompScreenOutputFB; +GLuint CaptureTex[2][4]; +GLuint CaptureFB[2][4]; + bool Init() { @@ -121,6 +124,17 @@ bool Init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glGenFramebuffers(8, &CaptureFB[0][0]); + glGenTextures(8, &CaptureTex[0][0]); + for (int i = 0; i < 8; i++) + { + glBindTexture(GL_TEXTURE_2D, CaptureTex[i>>2][i&0x3]); + 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); + } + glBindFramebuffer(GL_FRAMEBUFFER, 0); return true; @@ -128,6 +142,9 @@ bool Init() void DeInit() { + glDeleteFramebuffers(8, &CaptureFB[0][0]); + glDeleteTextures(8, &CaptureTex[0][0]); + glDeleteFramebuffers(1, &CompScreenOutputFB); glDeleteTextures(1, &CompScreenInputTex); glDeleteTextures(1, &CompScreenOutputTex); @@ -160,10 +177,36 @@ void SetRenderSettings(RenderSettings& settings) glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, CompScreenOutputTex, 0); glDrawBuffers(1, fbassign); + for (int i = 0; i < 8; i++) + { + glBindTexture(GL_TEXTURE_2D, CaptureTex[i>>2][i&0x3]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenW, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindFramebuffer(GL_FRAMEBUFFER, CaptureFB[i>>2][i&0x3]); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, CaptureTex[i>>2][i&0x3], 0); + } + glBindFramebuffer(GL_FRAMEBUFFER, 0); } +void DoCapture(u32 capcnt) +{ + u32 dstvram = (capcnt >> 16) & 0x3; + + // TODO: blank out destination buffer? + if (!(GPU::VRAMMap_LCDC & (1<