VideoSW: Split up OGL window handling

This removes OSD support for video software, but it was already broken before.

This commit does not try to fix coding style issues, the rewrite of this presentation API is splitted up.
This commit is contained in:
degasus
2015-09-26 10:07:48 +02:00
parent b0bbe52cc9
commit 61c3a0d9e4
9 changed files with 206 additions and 413 deletions

View File

@ -9,25 +9,17 @@
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Common/GL/GLInterfaceBase.h"
#include "Common/GL/GLUtil.h"
#include "Core/Core.h"
#include "VideoBackends/Software/RasterFont.h"
#include "VideoBackends/Software/SWCommandProcessor.h"
#include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWRenderer.h"
#include "VideoBackends/Software/SWStatistics.h"
#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/OnScreenDisplay.h"
static GLuint s_RenderTarget = 0;
static GLint attr_pos = -1, attr_tex = -1;
static GLint uni_tex = -1;
static GLuint program;
static u8 *s_xfbColorTexture[2];
static int s_currentColorTexture = 0;
@ -35,11 +27,6 @@ static std::atomic<bool> s_bScreenshot;
static std::mutex s_criticalScreenshot;
static std::string s_sScreenshotName;
// Rasterfont isn't compatible with GLES
// degasus: I think it does, but I can't test it
static RasterFont* s_pfont = nullptr;
void SWRenderer::Init()
{
s_bScreenshot.store(false);
@ -49,45 +36,6 @@ void SWRenderer::Shutdown()
{
delete[] s_xfbColorTexture[0];
delete[] s_xfbColorTexture[1];
glDeleteProgram(program);
glDeleteTextures(1, &s_RenderTarget);
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
{
delete s_pfont;
s_pfont = nullptr;
}
}
static void CreateShaders()
{
static const char *fragShaderText =
"#ifdef GL_ES\n"
"precision highp float;\n"
"#endif\n"
"varying vec2 TexCoordOut;\n"
"uniform sampler2D Texture;\n"
"void main() {\n"
" gl_FragColor = texture2D(Texture, TexCoordOut);\n"
"}\n";
static const char *vertShaderText =
"#ifdef GL_ES\n"
"precision highp float;\n"
"#endif\n"
"attribute vec4 pos;\n"
"attribute vec2 TexCoordIn;\n "
"varying vec2 TexCoordOut;\n "
"void main() {\n"
" gl_Position = pos;\n"
" TexCoordOut = TexCoordIn;\n"
"}\n";
program = OpenGL_CompileProgram(vertShaderText, fragShaderText);
glUseProgram(program);
uni_tex = glGetUniformLocation(program, "Texture");
attr_pos = glGetAttribLocation(program, "pos");
attr_tex = glGetAttribLocation(program, "TexCoordIn");
}
void SWRenderer::Prepare()
@ -96,18 +44,6 @@ void SWRenderer::Prepare()
s_xfbColorTexture[1] = new u8[MAX_XFB_WIDTH * MAX_XFB_HEIGHT * 4];
s_currentColorTexture = 0;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
glGenTextures(1, &s_RenderTarget);
CreateShaders();
// TODO: Enable for GLES once RasterFont supports GLES
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
{
s_pfont = new RasterFont();
glEnable(GL_TEXTURE_2D);
}
}
void SWRenderer::SetScreenshot(const char *_szFilename)
@ -119,16 +55,7 @@ void SWRenderer::SetScreenshot(const char *_szFilename)
void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
{
if (GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL)
return;
int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
glColor4f(((color >> 16) & 0xff) / 255.0f, ((color >> 8) & 0xff) / 255.0f,
((color >> 0) & 0xff) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
s_pfont->printMultilineText(pstr,
left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight);
SWOGLWindow::s_instance->PrintText(pstr, left, top, color);
}
void SWRenderer::DrawDebugText()
@ -213,81 +140,23 @@ void SWRenderer::UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidt
// Called on the GPU thread
void SWRenderer::Swap(u32 fbWidth, u32 fbHeight)
{
GLInterface->Update(); // just updates the render window position and the backbuffer size
SWRenderer::DrawTexture(GetCurrentColorTexture(), fbWidth, fbHeight);
swstats.frameCount++;
SWRenderer::SwapBuffer();
Core::Callback_VideoCopiedToXFB(true); // FIXME: should this function be called FrameRendered?
}
void SWRenderer::DrawTexture(u8 *texture, int width, int height)
{
// FIXME: This should add black bars when the game has set the VI to render less than the full xfb.
// Save screenshot
if (s_bScreenshot.load())
{
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
TextureToPng(texture, width * 4, s_sScreenshotName, width, height, false);
TextureToPng(GetCurrentColorTexture(), fbWidth * 4, s_sScreenshotName, fbWidth, fbHeight, false);
// Reset settings
s_sScreenshotName.clear();
s_bScreenshot.store(false);
}
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
// Update GLViewPort
glViewport(0, 0, glWidth, glHeight);
glScissor(0, 0, glWidth, glHeight);
glBindTexture(GL_TEXTURE_2D, s_RenderTarget);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glUseProgram(program);
static const GLfloat verts[4][2] = {
{ -1, -1}, // Left top
{ -1, 1}, // left bottom
{ 1, 1}, // right bottom
{ 1, -1} // right top
};
static const GLfloat texverts[4][2] = {
{0, 1},
{0, 0},
{1, 0},
{1, 1}
};
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts);
glEnableVertexAttribArray(attr_pos);
glEnableVertexAttribArray(attr_tex);
glUniform1i(uni_tex, 0);
glActiveTexture(GL_TEXTURE0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(attr_pos);
glDisableVertexAttribArray(attr_tex);
glBindTexture(GL_TEXTURE_2D, 0);
}
void SWRenderer::SwapBuffer()
{
// Do our OSD callbacks
OSD::DoCallbacks(OSD::OSD_ONFRAME);
DrawDebugText();
glFlush();
GLInterface->Swap();
SWOGLWindow::s_instance->ShowImage(GetCurrentColorTexture(), fbWidth * 4, fbWidth, fbHeight, 1.0);
swstats.frameCount++;
swstats.ResetFrame();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Core::Callback_VideoCopiedToXFB(true); // FIXME: should this function be called FrameRendered?
}