mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 09:39:46 -06:00
Remove old XFB logic
This commit is contained in:
@ -33,7 +33,6 @@ bool FramebufferManager::m_enable_stencil_buffer;
|
||||
|
||||
GLenum FramebufferManager::m_textureType;
|
||||
std::vector<GLuint> FramebufferManager::m_efbFramebuffer;
|
||||
GLuint FramebufferManager::m_xfbFramebuffer;
|
||||
GLuint FramebufferManager::m_efbColor;
|
||||
GLuint FramebufferManager::m_efbDepth;
|
||||
GLuint FramebufferManager::m_efbColorSwap; // for hot swap when reinterpreting EFB pixel formats
|
||||
@ -110,7 +109,6 @@ bool FramebufferManager::HasStencilBuffer()
|
||||
FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int msaaSamples,
|
||||
bool enable_stencil_buffer)
|
||||
{
|
||||
m_xfbFramebuffer = 0;
|
||||
m_efbColor = 0;
|
||||
m_efbDepth = 0;
|
||||
m_efbColorSwap = 0;
|
||||
@ -189,9 +187,6 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
|
||||
CreateTexture(m_textureType, depth_internal_format, depth_pixel_format, depth_data_type);
|
||||
m_efbColorSwap = CreateTexture(m_textureType, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||
|
||||
// Create XFB framebuffer; targets will be created elsewhere.
|
||||
glGenFramebuffers(1, &m_xfbFramebuffer);
|
||||
|
||||
// Bind target textures to EFB framebuffer.
|
||||
glGenFramebuffers(m_EFBLayers, m_efbFramebuffer.data());
|
||||
BindLayeredTexture(m_efbColor, m_efbFramebuffer, GL_COLOR_ATTACHMENT0, m_textureType);
|
||||
@ -419,9 +414,6 @@ FramebufferManager::~FramebufferManager()
|
||||
m_efbFramebuffer.clear();
|
||||
m_resolvedFramebuffer.clear();
|
||||
|
||||
glDeleteFramebuffers(1, &m_xfbFramebuffer);
|
||||
m_xfbFramebuffer = 0;
|
||||
|
||||
glObj[0] = m_resolvedColorTexture;
|
||||
glObj[1] = m_resolvedDepthTexture;
|
||||
glDeleteTextures(2, glObj);
|
||||
@ -527,21 +519,6 @@ void FramebufferManager::ResolveEFBStencilTexture()
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer[0]);
|
||||
}
|
||||
|
||||
void FramebufferManager::CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight,
|
||||
const EFBRectangle& sourceRc, float Gamma)
|
||||
{
|
||||
/* u8* xfb_in_ram = Memory::GetPointer(xfbAddr);
|
||||
if (!xfb_in_ram)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Tried to copy to invalid XFB address");
|
||||
return;
|
||||
}
|
||||
|
||||
TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
|
||||
TextureConverter::EncodeToRamYUYV(ResolveAndGetRenderTarget(sourceRc), targetRc, xfb_in_ram,
|
||||
sourceRc.GetWidth(), fbStride, fbHeight);*/
|
||||
}
|
||||
|
||||
GLuint FramebufferManager::GetResolvedFramebuffer()
|
||||
{
|
||||
if (m_msaaSamples <= 1)
|
||||
@ -610,56 +587,6 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype)
|
||||
g_renderer->RestoreAPIState();
|
||||
}
|
||||
|
||||
XFBSource::~XFBSource()
|
||||
{
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
void XFBSource::CopyEFB(float Gamma)
|
||||
{
|
||||
g_renderer->ResetAPIState();
|
||||
|
||||
// Copy EFB data to XFB and restore render target again
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());
|
||||
|
||||
for (int i = 0; i < m_layers; i++)
|
||||
{
|
||||
// Bind EFB and texture layer
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferManager::GetEFBFramebuffer(i));
|
||||
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, i);
|
||||
|
||||
glBlitFramebuffer(0, 0, texWidth, texHeight, 0, 0, texWidth, texHeight, GL_COLOR_BUFFER_BIT,
|
||||
GL_NEAREST);
|
||||
}
|
||||
|
||||
// Return to EFB.
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
|
||||
g_renderer->RestoreAPIState();
|
||||
}
|
||||
|
||||
std::unique_ptr<XFBSourceBase> FramebufferManager::CreateXFBSource(unsigned int target_width,
|
||||
unsigned int target_height,
|
||||
unsigned int layers)
|
||||
{
|
||||
GLuint texture;
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
|
||||
glActiveTexture(GL_TEXTURE9);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, target_width, target_height, layers, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, nullptr);
|
||||
|
||||
return std::make_unique<XFBSource>(texture, layers);
|
||||
}
|
||||
|
||||
std::pair<u32, u32> FramebufferManager::GetTargetSize() const
|
||||
{
|
||||
return std::make_pair(m_targetWidth, m_targetHeight);
|
||||
}
|
||||
|
||||
void FramebufferManager::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points)
|
||||
{
|
||||
g_renderer->ResetAPIState();
|
||||
|
@ -48,17 +48,6 @@
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
struct XFBSource : public XFBSourceBase
|
||||
{
|
||||
XFBSource(GLuint tex, int layers) : texture(tex), m_layers(layers) {}
|
||||
~XFBSource();
|
||||
|
||||
void CopyEFB(float Gamma) override;
|
||||
|
||||
const GLuint texture;
|
||||
const int m_layers;
|
||||
};
|
||||
|
||||
class FramebufferManager : public FramebufferManagerBase
|
||||
{
|
||||
public:
|
||||
@ -76,7 +65,6 @@ public:
|
||||
{
|
||||
return (layer < m_EFBLayers) ? m_efbFramebuffer[layer] : m_efbFramebuffer.back();
|
||||
}
|
||||
static GLuint GetXFBFramebuffer() { return m_xfbFramebuffer; }
|
||||
// Resolved framebuffer is only used in MSAA mode.
|
||||
static GLuint GetResolvedFramebuffer();
|
||||
static void SetFramebuffer(GLuint fb);
|
||||
@ -108,13 +96,6 @@ private:
|
||||
GLenum data_type);
|
||||
void BindLayeredTexture(GLuint texture, const std::vector<GLuint>& framebuffers,
|
||||
GLenum attachment, GLenum texture_type);
|
||||
std::unique_ptr<XFBSourceBase> CreateXFBSource(unsigned int target_width,
|
||||
unsigned int target_height,
|
||||
unsigned int layers) override;
|
||||
std::pair<u32, u32> GetTargetSize() const override;
|
||||
|
||||
void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,
|
||||
float Gamma) override;
|
||||
|
||||
static int m_targetWidth;
|
||||
static int m_targetHeight;
|
||||
@ -122,7 +103,6 @@ private:
|
||||
|
||||
static GLenum m_textureType;
|
||||
static std::vector<GLuint> m_efbFramebuffer;
|
||||
static GLuint m_xfbFramebuffer;
|
||||
static GLuint m_efbColor;
|
||||
static GLuint m_efbDepth;
|
||||
static GLuint
|
||||
|
@ -790,12 +790,7 @@ Renderer::Renderer()
|
||||
ClearEFBCache();
|
||||
}
|
||||
|
||||
Renderer::~Renderer()
|
||||
{
|
||||
FlushFrameDump();
|
||||
//FinishFrameData();
|
||||
DestroyFrameDumpResources();
|
||||
}
|
||||
Renderer::~Renderer() = default;
|
||||
|
||||
void Renderer::Shutdown()
|
||||
{
|
||||
@ -1360,27 +1355,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
BlitScreen(sourceRc, flipped_trc, xfb_texture->GetRawTexIdentifier(), xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
|
||||
|
||||
// The FlushFrameDump call here is necessary even after frame dumping is stopped.
|
||||
// If left out, screenshots are "one frame" behind, as an extra frame is dumped and buffered.
|
||||
/*FlushFrameDump();
|
||||
if (IsFrameDumping())
|
||||
{
|
||||
// Currently, we only use the off-screen buffer as a frame dump source if full-resolution
|
||||
// frame dumping is enabled, saving the need for an extra copy. In the future, this could
|
||||
// be extended to be used for surfaceless contexts as well.
|
||||
bool use_offscreen_buffer = g_ActiveConfig.bInternalResolutionFrameDumps;
|
||||
if (use_offscreen_buffer)
|
||||
{
|
||||
// DumpFrameUsingFBO resets GL_FRAMEBUFFER, so change back to the window for drawing OSD.
|
||||
DumpFrameUsingFBO(sourceRc, ticks);
|
||||
}
|
||||
else
|
||||
{
|
||||
// GL_READ_FRAMEBUFFER is set by GL_FRAMEBUFFER in DrawFrame -> Draw{EFB,VirtualXFB,RealXFB}.
|
||||
DumpFrame(flipped_trc, ticks);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Finish up the current frame, print some stats
|
||||
|
||||
SetWindowSize(xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
|
||||
@ -1509,134 +1483,6 @@ void Renderer::DrawEFB(GLuint framebuffer, const TargetRectangle& target_rc,
|
||||
BlitScreen(source_rc, target_rc, tex, m_target_width, m_target_height);
|
||||
}
|
||||
|
||||
void Renderer::FlushFrameDump()
|
||||
{
|
||||
/*if (!m_last_frame_exported)
|
||||
return;
|
||||
|
||||
FinishFrameData();
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_frame_dumping_pbo[0]);
|
||||
m_frame_pbo_is_mapped[0] = true;
|
||||
void* data = glMapBufferRange(
|
||||
GL_PIXEL_PACK_BUFFER, 0, m_last_frame_width[0] * m_last_frame_height[0] * 4, GL_MAP_READ_BIT);
|
||||
DumpFrameData(reinterpret_cast<u8*>(data), m_last_frame_width[0], m_last_frame_height[0],
|
||||
m_last_frame_width[0] * 4, m_last_frame_state, true);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
m_last_frame_exported = false;*/
|
||||
}
|
||||
|
||||
void Renderer::DumpFrame(const TargetRectangle& flipped_trc, u64 ticks)
|
||||
{
|
||||
if (!m_frame_dumping_pbo[0])
|
||||
{
|
||||
glGenBuffers(2, m_frame_dumping_pbo.data());
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_frame_dumping_pbo[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
FlushFrameDump();
|
||||
std::swap(m_frame_dumping_pbo[0], m_frame_dumping_pbo[1]);
|
||||
std::swap(m_frame_pbo_is_mapped[0], m_frame_pbo_is_mapped[1]);
|
||||
std::swap(m_last_frame_width[0], m_last_frame_width[1]);
|
||||
std::swap(m_last_frame_height[0], m_last_frame_height[1]);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_frame_dumping_pbo[0]);
|
||||
if (m_frame_pbo_is_mapped[0])
|
||||
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||
m_frame_pbo_is_mapped[0] = false;
|
||||
}
|
||||
|
||||
if (flipped_trc.GetWidth() != m_last_frame_width[0] ||
|
||||
flipped_trc.GetHeight() != m_last_frame_height[0])
|
||||
{
|
||||
m_last_frame_width[0] = flipped_trc.GetWidth();
|
||||
m_last_frame_height[0] = flipped_trc.GetHeight();
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, m_last_frame_width[0] * m_last_frame_height[0] * 4, nullptr,
|
||||
GL_STREAM_READ);
|
||||
}
|
||||
|
||||
m_last_frame_state = AVIDump::FetchState(ticks);
|
||||
m_last_frame_exported = true;
|
||||
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(flipped_trc.left, flipped_trc.bottom, m_last_frame_width[0], m_last_frame_height[0],
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
}
|
||||
|
||||
void Renderer::DumpFrameUsingFBO(const TargetRectangle& source_rc, u64 ticks)
|
||||
{
|
||||
// This needs to be converted to the GL bottom-up window coordinate system.
|
||||
TargetRectangle render_rc = CalculateFrameDumpDrawRectangle();
|
||||
std::swap(render_rc.top, render_rc.bottom);
|
||||
|
||||
// Ensure the render texture meets the size requirements of the draw area.
|
||||
u32 render_width = static_cast<u32>(render_rc.GetWidth());
|
||||
u32 render_height = static_cast<u32>(render_rc.GetHeight());
|
||||
PrepareFrameDumpRenderTexture(render_width, render_height);
|
||||
|
||||
// Ensure the alpha channel of the render texture is blank. The frame dump backend expects
|
||||
// that the alpha is set to 1.0 for all pixels.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_frame_dump_render_framebuffer);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Render the frame into the frame dump render texture. Disable alpha writes in case the
|
||||
// post-processing shader writes a non-1.0 value.
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
|
||||
DrawEFB(m_frame_dump_render_framebuffer, render_rc, source_rc);
|
||||
|
||||
// Copy frame to output buffer. This assumes that GL_FRAMEBUFFER has been set.
|
||||
DumpFrame(render_rc, ticks);
|
||||
|
||||
// Restore state after drawing. This isn't the game state, it's the state set by ResetAPIState.
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void Renderer::PrepareFrameDumpRenderTexture(u32 width, u32 height)
|
||||
{
|
||||
// Ensure framebuffer exists (we lazily allocate it in case frame dumping isn't used).
|
||||
// Or, resize texture if it isn't large enough to accommodate the current frame.
|
||||
if (m_frame_dump_render_texture != 0 && m_frame_dump_render_framebuffer != 0 &&
|
||||
m_frame_dump_render_texture_width >= width && m_frame_dump_render_texture_height >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Recreate texture objects.
|
||||
if (m_frame_dump_render_texture != 0)
|
||||
glDeleteTextures(1, &m_frame_dump_render_texture);
|
||||
if (m_frame_dump_render_framebuffer != 0)
|
||||
glDeleteFramebuffers(1, &m_frame_dump_render_framebuffer);
|
||||
|
||||
glGenTextures(1, &m_frame_dump_render_texture);
|
||||
glActiveTexture(GL_TEXTURE9);
|
||||
glBindTexture(GL_TEXTURE_2D, m_frame_dump_render_texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
|
||||
glGenFramebuffers(1, &m_frame_dump_render_framebuffer);
|
||||
FramebufferManager::SetFramebuffer(m_frame_dump_render_framebuffer);
|
||||
FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
m_frame_dump_render_texture, 0);
|
||||
|
||||
m_frame_dump_render_texture_width = width;
|
||||
m_frame_dump_render_texture_height = height;
|
||||
OGLTexture::SetStage();
|
||||
}
|
||||
|
||||
void Renderer::DestroyFrameDumpResources()
|
||||
{
|
||||
if (m_frame_dump_render_framebuffer)
|
||||
glDeleteFramebuffers(1, &m_frame_dump_render_framebuffer);
|
||||
if (m_frame_dump_render_texture)
|
||||
glDeleteTextures(1, &m_frame_dump_render_texture);
|
||||
if (m_frame_dumping_pbo[0])
|
||||
glDeleteBuffers(2, m_frame_dumping_pbo.data());
|
||||
}
|
||||
|
||||
// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
|
||||
void Renderer::ResetAPIState()
|
||||
{
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
@ -116,25 +115,5 @@ private:
|
||||
|
||||
void BlitScreen(TargetRectangle src, TargetRectangle dst, GLuint src_texture, int src_width,
|
||||
int src_height);
|
||||
|
||||
void FlushFrameDump();
|
||||
void DumpFrame(const TargetRectangle& flipped_trc, u64 ticks);
|
||||
void DumpFrameUsingFBO(const TargetRectangle& source_rc, u64 ticks);
|
||||
|
||||
// Frame dumping framebuffer, we render to this, then read it back
|
||||
void PrepareFrameDumpRenderTexture(u32 width, u32 height);
|
||||
void DestroyFrameDumpResources();
|
||||
GLuint m_frame_dump_render_texture = 0;
|
||||
GLuint m_frame_dump_render_framebuffer = 0;
|
||||
u32 m_frame_dump_render_texture_width = 0;
|
||||
u32 m_frame_dump_render_texture_height = 0;
|
||||
|
||||
// avi dumping state to delay one frame
|
||||
std::array<u32, 2> m_frame_dumping_pbo = {};
|
||||
std::array<bool, 2> m_frame_pbo_is_mapped = {};
|
||||
std::array<int, 2> m_last_frame_width = {};
|
||||
std::array<int, 2> m_last_frame_height = {};
|
||||
bool m_last_frame_exported = false;
|
||||
AVIDump::Frame m_last_frame_state;
|
||||
};
|
||||
}
|
||||
|
@ -41,11 +41,6 @@ static GLuint s_dstTexture = 0; // for encoding to RAM
|
||||
const int renderBufferWidth = EFB_WIDTH * 4;
|
||||
const int renderBufferHeight = 1024;
|
||||
|
||||
static SHADER s_rgbToYuyvProgram;
|
||||
static int s_rgbToYuyvUniform_loc;
|
||||
|
||||
static SHADER s_yuyvToRgbProgram;
|
||||
|
||||
struct EncodingProgram
|
||||
{
|
||||
SHADER program;
|
||||
@ -56,87 +51,6 @@ static std::map<EFBCopyParams, EncodingProgram> s_encoding_programs;
|
||||
|
||||
static GLuint s_PBO = 0; // for readback with different strides
|
||||
|
||||
static void CreatePrograms()
|
||||
{
|
||||
/* TODO: Accuracy Improvements
|
||||
*
|
||||
* This shader doesn't really match what the GameCube does internally in the
|
||||
* copy pipeline.
|
||||
* 1. It uses OpenGL's built in filtering when yscaling, someone could work
|
||||
* out how the copypipeline does it's filtering and implement it correctly
|
||||
* in this shader.
|
||||
* 2. Deflickering isn't implemented, a futher filtering over 3 lines.
|
||||
* Isn't really needed on non-interlaced monitors (and would lower quality;
|
||||
* But hey, accuracy!)
|
||||
* 3. Flipper's YUYV conversion implements a 3 pixel horizontal blur on the
|
||||
* UV channels, centering the U channel on the Left pixel and the V channel
|
||||
* on the Right pixel.
|
||||
* The current implementation Centers both UV channels at the same place
|
||||
* inbetween the two Pixels, and only blurs over these two pixels.
|
||||
*/
|
||||
// Output is BGRA because that is slightly faster than RGBA.
|
||||
const char* VProgramRgbToYuyv =
|
||||
"out vec2 uv0;\n"
|
||||
"uniform vec4 copy_position;\n" // left, top, right, bottom
|
||||
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
|
||||
" gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
|
||||
" uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy);\n"
|
||||
"}\n";
|
||||
const char* FProgramRgbToYuyv =
|
||||
"SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n"
|
||||
"in vec2 uv0;\n"
|
||||
"out vec4 ocol0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec3 c0 = texture(samp9, vec3(uv0 - dFdx(uv0) * 0.25, 0.0)).rgb;\n"
|
||||
" vec3 c1 = texture(samp9, vec3(uv0 + dFdx(uv0) * 0.25, 0.0)).rgb;\n"
|
||||
" vec3 c01 = (c0 + c1) * 0.5;\n"
|
||||
" vec3 y_const = vec3(0.257,0.504,0.098);\n"
|
||||
" vec3 u_const = vec3(-0.148,-0.291,0.439);\n"
|
||||
" vec3 v_const = vec3(0.439,-0.368,-0.071);\n"
|
||||
" vec4 const3 = vec4(0.0625,0.5,0.0625,0.5);\n"
|
||||
" ocol0 = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + "
|
||||
"const3;\n"
|
||||
"}\n";
|
||||
ProgramShaderCache::CompileShader(s_rgbToYuyvProgram, VProgramRgbToYuyv, FProgramRgbToYuyv);
|
||||
s_rgbToYuyvUniform_loc = glGetUniformLocation(s_rgbToYuyvProgram.glprogid, "copy_position");
|
||||
|
||||
/* TODO: Accuracy Improvements
|
||||
*
|
||||
* The YVYU to RGB conversion here matches the RGB to YUYV done above, but
|
||||
* if a game modifies or adds images to the XFB then it should be using the
|
||||
* same algorithm as the flipper, and could result in slight color inaccuracies
|
||||
* when run back through this shader.
|
||||
*/
|
||||
const char* VProgramYuyvToRgb = "void main()\n"
|
||||
"{\n"
|
||||
" vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
|
||||
" gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
const char* FProgramYuyvToRgb = "SAMPLER_BINDING(9) uniform sampler2D samp9;\n"
|
||||
"in vec2 uv0;\n"
|
||||
"out vec4 ocol0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" ivec2 uv = ivec2(gl_FragCoord.xy);\n"
|
||||
// We switch top/bottom here. TODO: move this to screen blit.
|
||||
" ivec2 ts = textureSize(samp9, 0);\n"
|
||||
" vec4 c0 = texelFetch(samp9, ivec2(uv.x>>1, ts.y-uv.y-1), 0);\n"
|
||||
" float y = mix(c0.r, c0.b, (uv.x & 1) == 1);\n"
|
||||
" float yComp = 1.164 * (y - 0.0625);\n"
|
||||
" float uComp = c0.g - 0.5;\n"
|
||||
" float vComp = c0.a - 0.5;\n"
|
||||
" ocol0 = vec4(yComp + (1.596 * vComp),\n"
|
||||
" yComp - (0.813 * vComp) - (0.391 * uComp),\n"
|
||||
" yComp + (2.018 * uComp),\n"
|
||||
" 1.0);\n"
|
||||
"}\n";
|
||||
ProgramShaderCache::CompileShader(s_yuyvToRgbProgram, VProgramYuyvToRgb, FProgramYuyvToRgb);
|
||||
}
|
||||
|
||||
static EncodingProgram& GetOrCreateEncodingShader(const EFBCopyParams& params)
|
||||
{
|
||||
auto iter = s_encoding_programs.find(params);
|
||||
@ -191,8 +105,6 @@ void Init()
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
|
||||
glGenBuffers(1, &s_PBO);
|
||||
|
||||
CreatePrograms();
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
@ -202,9 +114,6 @@ void Shutdown()
|
||||
glDeleteBuffers(1, &s_PBO);
|
||||
glDeleteFramebuffers(2, s_texConvFrameBuffer);
|
||||
|
||||
s_rgbToYuyvProgram.Destroy();
|
||||
s_yuyvToRgbProgram.Destroy();
|
||||
|
||||
for (auto& program : s_encoding_programs)
|
||||
program.second.program.Destroy();
|
||||
s_encoding_programs.clear();
|
||||
@ -297,64 +206,6 @@ void EncodeToRamFromTexture(u8* dest_ptr, const EFBCopyParams& params, u32 nativ
|
||||
g_renderer->RestoreAPIState();
|
||||
}
|
||||
|
||||
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, u32 dstWidth,
|
||||
u32 dstStride, u32 dstHeight)
|
||||
{
|
||||
g_renderer->ResetAPIState();
|
||||
|
||||
s_rgbToYuyvProgram.Bind();
|
||||
|
||||
glUniform4f(s_rgbToYuyvUniform_loc, static_cast<float>(sourceRc.left),
|
||||
static_cast<float>(sourceRc.top), static_cast<float>(sourceRc.right),
|
||||
static_cast<float>(sourceRc.bottom));
|
||||
|
||||
// We enable linear filtering, because the GameCube does filtering in the vertical direction when
|
||||
// yscale is enabled.
|
||||
// Otherwise we get jaggies when a game uses yscaling (most PAL games)
|
||||
EncodeToRamUsingShader(srcTexture, destAddr, dstWidth * 2, dstHeight, dstStride, true, 1.0f);
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
OGLTexture::DisableStage(0);
|
||||
g_renderer->RestoreAPIState();
|
||||
}
|
||||
|
||||
// Should be scale free.
|
||||
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture)
|
||||
{
|
||||
u8* srcAddr = Memory::GetPointer(xfbAddr);
|
||||
if (!srcAddr)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Tried to decode from invalid memory address");
|
||||
return;
|
||||
}
|
||||
|
||||
g_renderer->ResetAPIState(); // reset any game specific settings
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
|
||||
// switch to texture converter frame buffer
|
||||
// attach destTexture as color destination
|
||||
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[1]);
|
||||
FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY,
|
||||
destTexture, 0);
|
||||
|
||||
// activate source texture
|
||||
// set srcAddr as data for source texture
|
||||
glActiveTexture(GL_TEXTURE9);
|
||||
glBindTexture(GL_TEXTURE_2D, s_srcTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcWidth / 2, srcHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
srcAddr);
|
||||
g_sampler_cache->BindNearestSampler(9);
|
||||
|
||||
glViewport(0, 0, srcWidth, srcHeight);
|
||||
s_yuyvToRgbProgram.Bind();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
|
||||
g_renderer->RestoreAPIState();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace OGL
|
||||
|
@ -20,11 +20,6 @@ namespace TextureConverter
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, u32 dstWidth,
|
||||
u32 dstStride, u32 dstHeight);
|
||||
|
||||
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture);
|
||||
|
||||
// returns size of the encoded data (in bytes)
|
||||
void EncodeToRamFromTexture(u8* dest_ptr, const EFBCopyParams& params, u32 native_width,
|
||||
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
|
||||
|
Reference in New Issue
Block a user