implement display capture for compute renderer

it's actually just all stolen from the regular OpenGL renderer
This commit is contained in:
RSDuck 2023-04-13 23:14:20 +02:00
parent 91bea108ea
commit 5984c78588
6 changed files with 42 additions and 3 deletions

View File

@ -367,7 +367,7 @@ void SoftRenderer::VBlankEnd(Unit* unitA, Unit* unitB)
{
if ((unitA->CaptureCnt & (1<<31)) && (((unitA->CaptureCnt >> 29) & 0x3) != 1))
{
//reinterpret_cast<GPU3D::GLRenderer*>(GPU3D::CurrentRenderer.get())->PrepareCaptureFrame();
reinterpret_cast<GPU3D::GLRenderer*>(GPU3D::CurrentRenderer.get())->PrepareCaptureFrame();
}
}
#endif

View File

@ -158,8 +158,10 @@ public:
virtual u32* GetLine(int line) = 0;
virtual void SetupAccelFrame() {}
protected:
Renderer3D(bool Accelerated);
virtual void PrepareCaptureFrame() {}
};
extern int Renderer;

View File

@ -154,12 +154,15 @@ bool ComputeRenderer::Init()
}
}
glGenBuffers(1, &PixelBuffer);
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelBuffer);
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
return true;
}
void ComputeRenderer::DeInit()
{
}
void ComputeRenderer::Reset()
@ -1395,7 +1398,26 @@ void ComputeRenderer::RestartFrame()
u32* ComputeRenderer::GetLine(int line)
{
return DummyLine;
int stride = 256;
if (line == 0)
{
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelBuffer);
u8* data = (u8*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
if (data) memcpy(&FramebufferCPU[0], data, 4*stride*192);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
}
u64* ptr = (u64*)&FramebufferCPU[stride * line];
for (int i = 0; i < stride; i+=2)
{
u64 rgb = *ptr & 0x00FCFCFC00FCFCFC;
u64 a = *ptr & 0xF8000000F8000000;
*ptr++ = (rgb >> 2) | (a >> 3);
}
return &FramebufferCPU[stride * line];
}
void ComputeRenderer::SetupAccelFrame()
@ -1403,4 +1425,11 @@ void ComputeRenderer::SetupAccelFrame()
glBindTexture(GL_TEXTURE_2D, Framebuffer);
}
void ComputeRenderer::PrepareCaptureFrame()
{
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelBuffer);
glBindTexture(GL_TEXTURE_2D, Framebuffer);
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
}
}

View File

@ -49,6 +49,7 @@ public:
u32* GetLine(int line) override;
void SetupAccelFrame() override;
void PrepareCaptureFrame() override;
private:
GLuint ShaderInterpXSpans[2];
GLuint ShaderBinCombined;
@ -240,6 +241,9 @@ private:
u32 TextureDecodingBuffer[1024*1024];
GLuint Framebuffer;
GLuint PixelBuffer;
u32 FramebufferCPU[256*192];
TexCacheEntry& GetTexture(u32 textureParam, u32 paletteParam);

View File

@ -1278,6 +1278,7 @@ void GLRenderer::PrepareCaptureFrame()
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, DownscaleFramebuffer);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
}
@ -1288,6 +1289,7 @@ u32* GLRenderer::GetLine(int line)
if (line == 0)
{
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
u8* data = (u8*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
if (data) memcpy(&Framebuffer[stride*0], data, 4*stride*192);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);

View File

@ -40,6 +40,8 @@ public:
void SetupAccelFrame() override;
void PrepareCaptureFrame();
void PrepareCaptureFrame() override;
static std::unique_ptr<GLRenderer> New() noexcept;
private:
// Used by New()