This commit is contained in:
Ryan Houdek 2013-01-07 13:47:34 -06:00
parent 5240e75be2
commit d0301ca89d
13 changed files with 242 additions and 627 deletions

1
.gitignore vendored
View File

@ -35,4 +35,3 @@ Source/Core/Common/Src/scmrev.h
*.ipch *.ipch
.sconsign.dblite .sconsign.dblite
Externals/scons-local/* Externals/scons-local/*
*~

View File

@ -117,8 +117,6 @@ struct Rectangle
Rectangle(T theLeft, T theTop, T theRight, T theBottom) Rectangle(T theLeft, T theTop, T theRight, T theBottom)
: left(theLeft), top(theTop), right(theRight), bottom(theBottom) : left(theLeft), top(theTop), right(theRight), bottom(theBottom)
{ } { }
bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; }
T GetWidth() const { return abs(right - left); } T GetWidth() const { return abs(right - left); }
T GetHeight() const { return abs(bottom - top); } T GetHeight() const { return abs(bottom - top); }

View File

@ -236,7 +236,7 @@ bool GetConfig(const int &type)
case CONFIG_DISABLEFOG: case CONFIG_DISABLEFOG:
return g_ActiveConfig.bDisableFog; return g_ActiveConfig.bDisableFog;
case CONFIG_SHOWEFBREGIONS: case CONFIG_SHOWEFBREGIONS:
return g_ActiveConfig.bShowEFBCopyRegions; return false;
default: default:
PanicAlert("GetConfig Error: Unknown Config Type!"); PanicAlert("GetConfig Error: Unknown Config Type!");
return false; return false;

View File

@ -17,7 +17,6 @@
#include "Globals.h" #include "Globals.h"
#include "FramebufferManager.h" #include "FramebufferManager.h"
#include "VertexShaderGen.h"
#include "TextureConverter.h" #include "TextureConverter.h"
#include "Render.h" #include "Render.h"
@ -28,11 +27,6 @@ namespace OGL
extern bool s_bHaveFramebufferBlit; // comes from Render.cpp. ugly. extern bool s_bHaveFramebufferBlit; // comes from Render.cpp. ugly.
static GLuint s_VBO = 0;
static GLuint s_VAO = 0;
static MathUtil::Rectangle<float> s_cached_sourcerc;
static MathUtil::Rectangle<float> s_cached_drawrc;
int FramebufferManager::m_targetWidth; int FramebufferManager::m_targetWidth;
int FramebufferManager::m_targetHeight; int FramebufferManager::m_targetHeight;
int FramebufferManager::m_msaaSamples; int FramebufferManager::m_msaaSamples;
@ -59,15 +53,6 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
m_resolvedDepthTexture = 0; m_resolvedDepthTexture = 0;
m_xfbFramebuffer = 0; m_xfbFramebuffer = 0;
s_cached_sourcerc.bottom = -1;
s_cached_sourcerc.left = -1;
s_cached_sourcerc.right = -1;
s_cached_sourcerc.top = -1;
s_cached_drawrc.bottom = -1;
s_cached_drawrc.left = -1;
s_cached_drawrc.right = -1;
s_cached_drawrc.top = -1;
m_targetWidth = targetWidth; m_targetWidth = targetWidth;
m_targetHeight = targetHeight; m_targetHeight = targetHeight;
@ -184,28 +169,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
// Create XFB framebuffer; targets will be created elsewhere. // Create XFB framebuffer; targets will be created elsewhere.
glGenFramebuffersEXT(1, &m_xfbFramebuffer); glGenFramebuffersEXT(1, &m_xfbFramebuffer);
// Generate VBO & VAO - and initialize the VAO for "Draw"
glGenBuffers(1, &s_VBO);
glGenVertexArrays(1, &s_VAO);
glBindBuffer(GL_ARRAY_BUFFER, s_VBO);
glBindVertexArray(s_VAO);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 6*sizeof(GLfloat), NULL);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+2);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+4);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f
glViewport(0, 0, m_targetWidth, m_targetHeight); glViewport(0, 0, m_targetWidth, m_targetHeight);
glScissor(0, 0, m_targetWidth, m_targetHeight); glScissor(0, 0, m_targetWidth, m_targetHeight);
@ -217,8 +181,6 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
FramebufferManager::~FramebufferManager() FramebufferManager::~FramebufferManager()
{ {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteBuffers(1, &s_VBO);
glDeleteVertexArrays(1, &s_VAO);
GLuint glObj[3]; GLuint glObj[3];
@ -343,35 +305,24 @@ void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
if(!(s_cached_sourcerc == sourcerc) || !(s_cached_drawrc == drawrc)) { glBegin(GL_QUADS);
GLfloat vertices[] = { glTexCoord2f(sourcerc.left, sourcerc.bottom);
drawrc.left, drawrc.bottom, glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0);
sourcerc.left, sourcerc.bottom, glVertex2f(drawrc.left, drawrc.bottom);
0.0f, 0.0f,
drawrc.left, drawrc.top, glTexCoord2f(sourcerc.left, sourcerc.top);
sourcerc.left, sourcerc.top, glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1);
0.0f, 1.0f, glVertex2f(drawrc.left, drawrc.top);
drawrc.right, drawrc.top,
sourcerc.right, sourcerc.top, glTexCoord2f(sourcerc.right, sourcerc.top);
1.0f, 1.0f, glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1);
drawrc.right, drawrc.bottom, glVertex2f(drawrc.right, drawrc.top);
sourcerc.right, sourcerc.bottom,
1.0f, 0.0f glTexCoord2f(sourcerc.right, sourcerc.bottom);
}; glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0);
glBindBuffer(GL_ARRAY_BUFFER, s_VBO); glVertex2f(drawrc.right, drawrc.bottom);
glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); glEnd();
s_cached_sourcerc = sourcerc;
s_cached_drawrc = drawrc;
}
glBindVertexArray(s_VAO);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }

View File

@ -27,9 +27,8 @@
#define COMPILED_CODE_SIZE 4096 #define COMPILED_CODE_SIZE 4096
// TODO: Use this again for performance, but without VAO we never know exactly the last configuration // TODO: this guy is never initialized
static u32 s_prevcomponents; // previous state set u32 s_prevcomponents; // previous state set
/* /*
#ifdef _WIN32 #ifdef _WIN32
#ifdef _M_IX86 #ifdef _M_IX86
@ -65,6 +64,7 @@ public:
virtual void Initialize(const PortableVertexDeclaration &_vtx_decl); virtual void Initialize(const PortableVertexDeclaration &_vtx_decl);
virtual void SetupVertexPointers(); virtual void SetupVertexPointers();
virtual void EnableComponents(u32 components);
}; };
namespace OGL namespace OGL
@ -187,7 +187,6 @@ void GLVertexFormat::SetupVertexPointers() {
#ifdef USE_JIT #ifdef USE_JIT
((void (*)())(void*)m_compiledCode)(); ((void (*)())(void*)m_compiledCode)();
#else #else
glVertexPointer(3, GL_FLOAT, vtx_decl.stride, VertexManager::s_pBaseBufferPointer); glVertexPointer(3, GL_FLOAT, vtx_decl.stride, VertexManager::s_pBaseBufferPointer);
if (vtx_decl.num_normals >= 1) { if (vtx_decl.num_normals >= 1) {
glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0])); glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0]));
@ -220,32 +219,34 @@ void GLVertexFormat::SetupVertexPointers() {
glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset)); glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset));
} }
#endif #endif
}
if (s_prevcomponents != m_components) void GLVertexFormat::EnableComponents(u32 components)
{
if (s_prevcomponents != components)
{ {
// vertices VertexManager::Flush();
glEnableClientState(GL_VERTEX_ARRAY);
// matrices // matrices
if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) if ((components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX))
{ {
if (m_components & VB_HAS_POSMTXIDX) if (components & VB_HAS_POSMTXIDX)
glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
else else
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
} }
// normals // normals
if ((m_components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) if ((components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0))
{ {
if (m_components & VB_HAS_NRM0) if (components & VB_HAS_NRM0)
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
else else
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
} }
if ((m_components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) if ((components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1))
{ {
if (m_components & VB_HAS_NRM1) { if (components & VB_HAS_NRM1) {
glEnableVertexAttribArray(SHADER_NORM1_ATTRIB); glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
glEnableVertexAttribArray(SHADER_NORM2_ATTRIB); glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
} }
@ -258,9 +259,9 @@ void GLVertexFormat::SetupVertexPointers() {
// color // color
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
if ((m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) if ((components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i)))
{ {
if (m_components & (VB_HAS_COL0 << i)) if (components & (VB_HAS_COL0 << i))
glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
else else
glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
@ -270,16 +271,16 @@ void GLVertexFormat::SetupVertexPointers() {
// tex // tex
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
if ((m_components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) if ((components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i)))
{ {
glClientActiveTexture(GL_TEXTURE0 + i); glClientActiveTexture(GL_TEXTURE0 + i);
if (m_components & (VB_HAS_UV0 << i)) if (components & (VB_HAS_UV0 << i))
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else else
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} }
} }
s_prevcomponents = m_components; s_prevcomponents = components;
} }
} }

View File

@ -17,16 +17,12 @@
#include "GLUtil.h" #include "GLUtil.h"
#include <string.h>
#include "RasterFont.h" #include "RasterFont.h"
// globals // globals
const GLubyte rasters[][13] = {
static const u32 char_width = 8;
static const u32 char_height = 13;
static const u32 char_offset = 32;
static const u32 char_count = 95;
const u8 rasters[char_count][char_height] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
@ -124,160 +120,104 @@ const u8 rasters[char_count][char_height] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00} {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00}
}; };
static const char *s_vertex_shader =
"attribute vec2 vertexPosition;\n"
"attribute vec2 texturePosition;\n"
"varying vec2 tpos;\n"
"void main(void) {\n"
" gl_Position = vec4(vertexPosition,0,1);\n"
" tpos = texturePosition;\n"
"}\n";
static const char *s_fragment_shader =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect textureSampler;\n"
"uniform vec4 color;\n"
"varying vec2 tpos;\n"
"void main(void) {\n"
" gl_FragColor = texture2DRect(textureSampler,tpos) * color;\n"
"}\n";
RasterFont::RasterFont() RasterFont::RasterFont()
{ {
// generate the texture // set GL modes
glGenTextures(1, &texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_RECTANGLE, texture); // create the raster font
u32* texture_data = new u32[char_width*char_count*char_height]; fontOffset = glGenLists(128);
for(u32 y=0; y<char_height; y++) { for (int i = 32; i < 127; i++) {
for(u32 c=0; c<char_count; c++) { glNewList(i + fontOffset, GL_COMPILE);
for(u32 x=0; x<char_width; x++) { glBitmap(8, 13, 0.0f, 2.0f, 10.0f, 0.0f, rasters[i - 32]);
bool pixel = rasters[c][y] & (1<<(char_width-x-1)); glEndList();
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
}
}
} }
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
delete [] texture_data; temp_buffer = new char[TEMP_BUFFER_SIZE];
// generate shader
shader_program = OpenGL_CompileProgram(s_vertex_shader, s_fragment_shader);
// bound uniforms
glUseProgram(shader_program);
glUniform1i(glGetUniformLocation(shader_program,"textureSampler"), 0); // GL_TEXTURE0
uniform_color_id = glGetUniformLocation(shader_program,"color");
glUniform4f(uniform_color_id, 1, 1, 1, 1);
cached_color = -1;
glUseProgram(0);
// generate VBO & VAO
glGenBuffers(1, &VBO);
glGenVertexArrays(1, &VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindVertexArray(VAO);
glEnableVertexAttribArray(glGetAttribLocation(shader_program, "vertexPosition"));
glVertexAttribPointer(glGetAttribLocation(shader_program, "vertexPosition"), 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL);
glEnableVertexAttribArray(glGetAttribLocation(shader_program, "texturePosition"));
glVertexAttribPointer(glGetAttribLocation(shader_program, "texturePosition"), 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
RasterFont::~RasterFont() RasterFont::~RasterFont()
{ {
glDeleteTextures(1, &texture); glDeleteLists(fontOffset, 128);
glDeleteBuffers(1, &VBO); delete [] temp_buffer;
glDeleteVertexArrays(1, &VAO);
glDeleteProgram(shader_program);
} }
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color) void RasterFont::printString(const char *s, double x, double y, double z)
{ {
int length = (int)strlen(text); int length = (int)strlen(s);
if (!length) if (!length)
return; // nothing to do return;
if (length >= TEMP_BUFFER_SIZE)
glBindVertexArray(VAO); length = TEMP_BUFFER_SIZE - 1;
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, length*4*6*sizeof(GLfloat), NULL, GL_STREAM_DRAW);
GLfloat *vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
int usage = 0;
GLfloat delta_x = 2*char_width/GLfloat(bbWidth);
GLfloat delta_y = 2*char_height/GLfloat(bbHeight);
GLfloat border_x = 1*2/GLfloat(bbWidth);
GLfloat border_y = 2*2/GLfloat(bbHeight);
GLfloat x = start_x;
GLfloat y = start_y;
for(int i=0; i<length; i++) {
u8 c = text[i];
if(c == '\n') {
x = start_x;
y -= delta_y + border_y;
continue;
}
// do not print spaces, they can be skipped easyly
if(c == ' ') {
x += delta_x + border_x;
continue;
}
if(c < char_offset || c >= char_count+char_offset) continue;
vertices[usage++] = x;
vertices[usage++] = y;
vertices[usage++] = (c-char_offset)*char_width;
vertices[usage++] = 0;
vertices[usage++] = x+delta_x;
vertices[usage++] = y;
vertices[usage++] = (c-char_offset+1)*char_width;
vertices[usage++] = 0;
vertices[usage++] = x+delta_x;
vertices[usage++] = y+delta_y;
vertices[usage++] = (c-char_offset+1)*char_width;
vertices[usage++] = char_height;
vertices[usage++] = x;
vertices[usage++] = y;
vertices[usage++] = (c-char_offset)*char_width;
vertices[usage++] = 0;
vertices[usage++] = x+delta_x;
vertices[usage++] = y+delta_y;
vertices[usage++] = (c-char_offset+1)*char_width;
vertices[usage++] = char_height;
vertices[usage++] = x;
vertices[usage++] = y+delta_y;
vertices[usage++] = (c-char_offset)*char_width;
vertices[usage++] = char_height;
x += delta_x + border_x;
}
glUnmapBuffer(GL_ARRAY_BUFFER);
glUseProgram(shader_program); // Sanitize string to avoid GL errors.
char *s2 = temp_buffer;
if(color != cached_color) { memcpy(s2, s, length);
glUniform4f(uniform_color_id, ((color>>16)&0xff)/255.f,((color>>8)&0xff)/255.f,((color>>0)&0xff)/255.f,((color>>24)&0xff)/255.f); s2[length] = 0;
cached_color = color; for (int i = 0; i < length; i++) {
if (s2[i] < 32 || s2[i] > 126)
s2[i] = '!';
}
// go to the right spot
glRasterPos3d(x, y, z);
GL_REPORT_ERRORD();
glPushAttrib (GL_LIST_BIT);
glListBase(fontOffset);
glCallLists((GLsizei)strlen(s2), GL_UNSIGNED_BYTE, (GLubyte *) s2);
GL_REPORT_ERRORD();
glPopAttrib();
GL_REPORT_ERRORD();
}
void RasterFont::printCenteredString(const char *s, double y, int screen_width, double z)
{
int length = (int)strlen(s);
int x = (int)(screen_width/2.0 - (length/2.0)*char_width);
printString(s, x, y, z);
}
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight)
{
double x = start_x;
double y = start_y;
char temp[1024];
char *t = temp;
while (*text)
{
if (*text == '\n')
{
*t = 0;
printString(temp, x, y, z);
y -= char_height * 2.0f / bbHeight;
x = start_x;
t = temp;
}
else if (*text == '\r')
{
t = temp;
}
else if (*text == '\t')
{
//todo: add tabs every something like 4*char_width
*t = 0;
int cpos = (int)strlen(temp);
int newpos = (cpos + 4) & (~3);
printString(temp, x, y, z);
x = start_x + (char_width*newpos) * 2.0f / bbWidth;
t = temp;
*t++ = ' ';
}
else
*t++ = *text;
text++;
}
// ????
if (t != text)
{
*t = 0;
printString(temp, x, y, z);
} }
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE, texture);
glDrawArrays(GL_TRIANGLES, 0, usage/4);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
} }

View File

@ -23,16 +23,20 @@ public:
RasterFont(); RasterFont();
~RasterFont(void); ~RasterFont(void);
static int debug; static int debug;
// some useful constants
enum {char_width = 10};
enum {char_height = 15};
// and the happy helper functions
void printString(const char *s, double x, double y, double z=0.0);
void printCenteredString(const char *s, double y, int screen_width, double z=0.0);
void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight, u32 color); void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight);
private: private:
int fontOffset;
u32 VBO; char *temp_buffer;
u32 VAO; enum {TEMP_BUFFER_SIZE = 64 * 1024};
u32 texture;
u32 shader_program;
u32 uniform_color_id;
u32 cached_color;
}; };
#endif // _RASTERFONT_H_ #endif // _RASTERFONT_H_

View File

@ -107,14 +107,10 @@ namespace OGL
// Declarations and definitions // Declarations and definitions
// ---------------------------- // ----------------------------
static int s_fps = 0; int s_fps=0;
static GLuint s_ShowEFBCopyRegions_VBO = 0;
static GLuint s_ShowEFBCopyRegions_VAO = 0;
static GLuint s_Swap_VBO = 0;
static GLuint s_Swap_VAO[2];
static TargetRectangle s_cached_targetRc;
static RasterFont* s_pfont = NULL;
RasterFont* s_pfont = NULL;
// 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA. // 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA.
static int s_MSAASamples = 1; static int s_MSAASamples = 1;
@ -130,9 +126,9 @@ static std::thread scrshotThread;
#endif #endif
// EFB cache related // EFB cache related
static const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks. const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks.
static const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up
static const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE;
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
@ -255,16 +251,7 @@ Renderer::Renderer()
OSDInternalH = 0; OSDInternalH = 0;
s_fps=0; s_fps=0;
s_ShowEFBCopyRegions_VBO = 0;
s_Swap_VBO = 0;
s_blendMode = 0; s_blendMode = 0;
// should be invalid, so there will be an upload on the first call
s_cached_targetRc.bottom = -1;
s_cached_targetRc.top = -1;
s_cached_targetRc.left = -1;
s_cached_targetRc.right = -1;
InitFPSCounter(); InitFPSCounter();
@ -325,13 +312,6 @@ Renderer::Renderer()
bSuccess = false; bSuccess = false;
} }
if (!GLEW_ARB_vertex_array_object)
{
ERROR_LOG(VIDEO, "GPU: OGL ERROR: Need GL_ARB_vertex_array_object.\n"
"GPU: Does your video card support OpenGL 3.0?");
bSuccess = false;
}
s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL; s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL;
s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL; s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL;
@ -471,46 +451,17 @@ Renderer::Renderer()
cgGLSetDebugMode(GL_FALSE); cgGLSetDebugMode(GL_FALSE);
#endif #endif
#endif #endif
// creating buffers
glGenBuffers(1, &s_ShowEFBCopyRegions_VBO);
glGenVertexArrays(1, &s_ShowEFBCopyRegions_VAO);
glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO);
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, (GLfloat*)NULL+2);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, NULL);
glGenBuffers(1, &s_Swap_VBO);
glGenVertexArrays(2, s_Swap_VAO);
glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO);
glBindVertexArray(s_Swap_VAO[0]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3);
glBindVertexArray(s_Swap_VAO[1]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glStencilFunc(GL_ALWAYS, 0, 0); glStencilFunc(GL_ALWAYS, 0, 0);
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);
glViewport(0, 0, GetTargetWidth(), GetTargetHeight()); // Reset The Current Viewport glViewport(0, 0, GetTargetWidth(), GetTargetHeight()); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f); glClearDepth(1.0f);
@ -527,6 +478,11 @@ Renderer::Renderer()
glBlendColorEXT(0, 0, 0, 0.5f); glBlendColorEXT(0, 0, 0, 0.5f);
glClearDepth(1.0f); glClearDepth(1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// legacy multitexturing: select texture channel only. // legacy multitexturing: select texture channel only.
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0);
@ -542,13 +498,6 @@ Renderer::~Renderer()
{ {
g_Config.bRunning = false; g_Config.bRunning = false;
UpdateActiveConfig(); UpdateActiveConfig();
glDeleteBuffers(1, &s_ShowEFBCopyRegions_VBO);
glDeleteVertexArrays(1, &s_ShowEFBCopyRegions_VAO);
glDeleteBuffers(1, &s_Swap_VBO);
glDeleteVertexArrays(2, s_Swap_VAO);
s_ShowEFBCopyRegions_VBO = 0;
delete s_pfont; delete s_pfont;
s_pfont = 0; s_pfont = 0;
@ -596,15 +545,9 @@ void Renderer::DrawDebugInfo()
// Set Line Size // Set Line Size
glLineWidth(3.0f); glLineWidth(3.0f);
// 2*Coords + 3*Color glBegin(GL_LINES);
glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO);
glBufferData(GL_ARRAY_BUFFER, stats.efb_regions.size() * sizeof(GLfloat) * (2+3)*2*6, NULL, GL_STREAM_DRAW);
GLfloat *Vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
// Draw EFB copy regions rectangles // Draw EFB copy regions rectangles
int a = 0;
GLfloat color[3] = {0.0f, 1.0f, 1.0f};
for (std::vector<EFBRectangle>::const_iterator it = stats.efb_regions.begin(); for (std::vector<EFBRectangle>::const_iterator it = stats.efb_regions.begin();
it != stats.efb_regions.end(); ++it) it != stats.efb_regions.end(); ++it)
{ {
@ -615,97 +558,22 @@ void Renderer::DrawDebugInfo()
GLfloat x2 = (GLfloat) -1.0f + ((GLfloat)it->right / halfWidth); GLfloat x2 = (GLfloat) -1.0f + ((GLfloat)it->right / halfWidth);
GLfloat y2 = (GLfloat) 1.0f - ((GLfloat)it->bottom / halfHeight); GLfloat y2 = (GLfloat) 1.0f - ((GLfloat)it->bottom / halfHeight);
Vertices[a++] = x; // Draw shadow of rect
Vertices[a++] = y; glColor3f(0.0f, 0.0f, 0.0f);
Vertices[a++] = color[0]; glVertex2f(x, y - 0.01); glVertex2f(x2, y - 0.01);
Vertices[a++] = color[1]; glVertex2f(x, y2 - 0.01); glVertex2f(x2, y2 - 0.01);
Vertices[a++] = color[2]; glVertex2f(x + 0.005, y); glVertex2f(x + 0.005, y2);
glVertex2f(x2 + 0.005, y); glVertex2f(x2 + 0.005, y2);
Vertices[a++] = x2;
Vertices[a++] = y; // Draw rect
Vertices[a++] = color[0]; glColor3f(0.0f, 1.0f, 1.0f);
Vertices[a++] = color[1]; glVertex2f(x, y); glVertex2f(x2, y);
Vertices[a++] = color[2]; glVertex2f(x, y2); glVertex2f(x2, y2);
glVertex2f(x, y); glVertex2f(x, y2);
glVertex2f(x2, y); glVertex2f(x2, y2);
Vertices[a++] = x2;
Vertices[a++] = y;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x2;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x2;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x;
Vertices[a++] = y;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x;
Vertices[a++] = y;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x2;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x2;
Vertices[a++] = y;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
Vertices[a++] = x;
Vertices[a++] = y2;
Vertices[a++] = color[0];
Vertices[a++] = color[1];
Vertices[a++] = color[2];
// TO DO: build something nicer here
GLfloat temp = color[0];
color[0] = color[1];
color[1] = color[2];
color[2] = temp;
} }
glUnmapBuffer(GL_ARRAY_BUFFER);
glEnd();
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Restore Line Size // Restore Line Size
glLineWidth(lSize); glLineWidth(lSize);
@ -733,13 +601,16 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color)
const int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth(); const int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
const int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight(); const 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);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
s_pfont->printMultilineText(text, s_pfont->printMultilineText(text,
left * 2.0f / (float)nBackbufferWidth - 1, left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight, 1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight, color); 0, nBackbufferWidth, nBackbufferHeight);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
@ -1264,42 +1135,43 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// Render to the real buffer now. // Render to the real buffer now.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
if (applyShader)
{
glBegin(GL_QUADS);
glTexCoord2f(targetRc.left, targetRc.bottom);
glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0);
glVertex2f(-1, -1);
if(!( s_cached_targetRc == targetRc)) { glTexCoord2f(targetRc.left, targetRc.top);
GLfloat vertices[] = { glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1);
-1.0f, -1.0f, 1.0f, glVertex2f(-1, 1);
(GLfloat)targetRc.left, (GLfloat)targetRc.bottom,
0.0f, 0.0f,
-1.0f, 1.0f, 1.0f,
(GLfloat)targetRc.left, (GLfloat)targetRc.top,
0.0f, 1.0f,
1.0f, 1.0f, 1.0f,
(GLfloat)targetRc.right, (GLfloat)targetRc.top,
1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
(GLfloat)targetRc.right, (GLfloat)targetRc.bottom,
1.0f, 0.0f
};
glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO);
glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
s_cached_targetRc = targetRc;
}
glBindVertexArray(s_Swap_VAO[applyShader]);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glTexCoord2f(targetRc.right, targetRc.top);
// TODO: this after merging with graphic_update glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1);
glBindVertexArray(0); glVertex2f( 1, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glTexCoord2f(targetRc.right, targetRc.bottom);
if(applyShader) glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0);
glVertex2f( 1, -1);
glEnd();
PixelShaderCache::DisableShader(); PixelShaderCache::DisableShader();
}
else
{
glBegin(GL_QUADS);
glTexCoord2f(targetRc.left, targetRc.bottom);
glVertex2f(-1, -1);
glTexCoord2f(targetRc.left, targetRc.top);
glVertex2f(-1, 1);
glTexCoord2f(targetRc.right, targetRc.top);
glVertex2f( 1, 1);
glTexCoord2f(targetRc.right, targetRc.bottom);
glVertex2f( 1, -1);
glEnd();
}
} }
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

View File

@ -56,13 +56,6 @@
namespace OGL namespace OGL
{ {
struct VBOCache {
GLuint vbo;
GLuint vao;
TargetRectangle targetSource;
};
static std::map<u64,VBOCache> s_VBO;
static u32 s_TempFramebuffer = 0; static u32 s_TempFramebuffer = 0;
static const GLint c_MinLinearFilter[8] = { static const GLint c_MinLinearFilter[8] = {
@ -113,8 +106,6 @@ TextureCache::TCacheEntry::~TCacheEntry()
TextureCache::TCacheEntry::TCacheEntry() TextureCache::TCacheEntry::TCacheEntry()
{ {
glGenTextures(1, &texture); glGenTextures(1, &texture);
currmode.hex = 0;
currmode1.hex = 0;
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
@ -127,9 +118,7 @@ void TextureCache::TCacheEntry::Bind(unsigned int stage)
// TODO: is this already done somewhere else? // TODO: is this already done somewhere else?
TexMode0 &tm0 = bpmem.tex[stage >> 2].texMode0[stage & 3]; TexMode0 &tm0 = bpmem.tex[stage >> 2].texMode0[stage & 3];
TexMode1 &tm1 = bpmem.tex[stage >> 2].texMode1[stage & 3]; TexMode1 &tm1 = bpmem.tex[stage >> 2].texMode1[stage & 3];
SetTextureParameters(tm0, tm1);
if(currmode.hex != tm0.hex || currmode1.hex != tm1.hex)
SetTextureParameters(tm0, tm1);
} }
bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level) bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
@ -315,57 +304,13 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect); TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);
GL_REPORT_ERRORD();
// should be unique enough, if not, vbo will "only" be uploaded to much
u64 targetSourceHash = u64(targetSource.left)<<48 | u64(targetSource.top)<<32 | u64(targetSource.right)<<16 | u64(targetSource.bottom);
std::map<u64, VBOCache>::iterator vbo_it = s_VBO.find(targetSourceHash);
if(vbo_it == s_VBO.end()) {
VBOCache item;
item.targetSource.bottom = -1;
item.targetSource.top = -1;
item.targetSource.left = -1;
item.targetSource.right = -1;
glGenBuffers(1, &item.vbo);
glGenVertexArrays(1, &item.vao);
glBindBuffer(GL_ARRAY_BUFFER, item.vbo);
glBindVertexArray(item.vao);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, 0);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL + 2);
vbo_it = s_VBO.insert(std::pair<u64,VBOCache>(targetSourceHash, item)).first;
}
if(!(vbo_it->second.targetSource == targetSource)) {
GLfloat vertices[] = {
-1.f, 1.f,
(GLfloat)targetSource.left, (GLfloat)targetSource.bottom,
-1.f, -1.f,
(GLfloat)targetSource.left, (GLfloat)targetSource.top,
1.f, -1.f,
(GLfloat)targetSource.right, (GLfloat)targetSource.top,
1.f, 1.f,
(GLfloat)targetSource.right, (GLfloat)targetSource.bottom
};
glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo);
glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
vbo_it->second.targetSource = targetSource;
}
glBindVertexArray(vbo_it->second.vao); glBegin(GL_QUADS);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.bottom); glVertex2f(-1, 1);
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.top ); glVertex2f(-1, -1);
// TODO: this after merging with graphic_update glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.top ); glVertex2f( 1, -1);
glBindVertexArray(0); glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.bottom); glVertex2f( 1, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0); glEnd();
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
@ -412,9 +357,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1) void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1)
{ {
currmode = newmode;
currmode1 = newmode1;
// TODO: not used anywhere // TODO: not used anywhere
TexMode0 mode = newmode; TexMode0 mode = newmode;
//mode1 = newmode1; //mode1 = newmode1;
@ -446,24 +388,13 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co
(float)(1 << g_ActiveConfig.iMaxAnisotropy)); (float)(1 << g_ActiveConfig.iMaxAnisotropy));
} }
TextureCache::TextureCache()
{
}
TextureCache::~TextureCache() TextureCache::~TextureCache()
{ {
for(std::map<u64, VBOCache>::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { if (s_TempFramebuffer)
glDeleteBuffers(1, &it->second.vbo);
glDeleteVertexArrays(1, &it->second.vao);
}
s_VBO.clear();
if (s_TempFramebuffer)
{ {
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
s_TempFramebuffer = 0; s_TempFramebuffer = 0;
} }
} }
void TextureCache::DisableStage(unsigned int stage) void TextureCache::DisableStage(unsigned int stage)

View File

@ -32,7 +32,6 @@ namespace OGL
class TextureCache : public ::TextureCache class TextureCache : public ::TextureCache
{ {
public: public:
TextureCache();
static void DisableStage(unsigned int stage); static void DisableStage(unsigned int stage);
private: private:
@ -67,8 +66,6 @@ private:
private: private:
void SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1); void SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1);
TexMode0 currmode;
TexMode1 currmode1;
}; };
~TextureCache(); ~TextureCache();

View File

@ -57,14 +57,6 @@ static FRAGMENTSHADER s_yuyvToRgbProgram;
const u32 NUM_ENCODING_PROGRAMS = 64; const u32 NUM_ENCODING_PROGRAMS = 64;
static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
static GLuint s_encode_VBO = 0;
static GLuint s_encode_VAO = 0;
static GLuint s_decode_VBO = 0;
static GLuint s_decode_VAO = 0;
static TargetRectangle s_cached_sourceRc;
static int s_cached_srcWidth = 0;
static int s_cached_srcHeight = 0;
void CreateRgbToYuyvProgram() void CreateRgbToYuyvProgram()
{ {
// Output is BGRA because that is slightly faster than RGBA. // Output is BGRA because that is slightly faster than RGBA.
@ -148,40 +140,9 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)
void Init() void Init()
{ {
glGenFramebuffersEXT(1, &s_texConvFrameBuffer); glGenFramebuffersEXT(1, &s_texConvFrameBuffer);
glGenBuffers(1, &s_encode_VBO );
glGenVertexArrays(1, &s_encode_VAO );
glBindBuffer(GL_ARRAY_BUFFER, s_encode_VBO );
glBindVertexArray( s_encode_VAO );
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), NULL);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), (GLfloat*)NULL + 2);
s_cached_sourceRc.top = -1;
s_cached_sourceRc.bottom = -1;
s_cached_sourceRc.left = -1;
s_cached_sourceRc.right = -1;
glGenBuffers(1, &s_decode_VBO );
glGenVertexArrays(1, &s_decode_VAO );
glBindBuffer(GL_ARRAY_BUFFER, s_decode_VBO );
glBindVertexArray( s_decode_VAO );
s_cached_srcWidth = -1;
s_cached_srcHeight = -1;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, NULL);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL+2);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenRenderbuffersEXT(1, &s_dstRenderBuffer); glGenRenderbuffersEXT(1, &s_dstRenderBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, renderBufferWidth, renderBufferHeight); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, renderBufferWidth, renderBufferHeight);
s_srcTextureWidth = 0; s_srcTextureWidth = 0;
@ -201,10 +162,6 @@ void Shutdown()
glDeleteTextures(1, &s_srcTexture); glDeleteTextures(1, &s_srcTexture);
glDeleteRenderbuffersEXT(1, &s_dstRenderBuffer); glDeleteRenderbuffersEXT(1, &s_dstRenderBuffer);
glDeleteFramebuffersEXT(1, &s_texConvFrameBuffer); glDeleteFramebuffersEXT(1, &s_texConvFrameBuffer);
glDeleteBuffers(1, &s_encode_VBO );
glDeleteVertexArrays(1, &s_encode_VAO );
glDeleteBuffers(1, &s_decode_VBO );
glDeleteVertexArrays(1, &s_decode_VAO );
s_rgbToYuyvProgram.Destroy(); s_rgbToYuyvProgram.Destroy();
s_yuyvToRgbProgram.Destroy(); s_yuyvToRgbProgram.Destroy();
@ -256,31 +213,13 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar
PixelShaderCache::SetCurrentShader(shader.glprogid); PixelShaderCache::SetCurrentShader(shader.glprogid);
GL_REPORT_ERRORD(); // Draw...
if(!(s_cached_sourceRc == sourceRc)) { glBegin(GL_QUADS);
GLfloat vertices[] = { glTexCoord2f((float)sourceRc.left, (float)sourceRc.top); glVertex2f(-1,-1);
-1.f, -1.f, glTexCoord2f((float)sourceRc.left, (float)sourceRc.bottom); glVertex2f(-1,1);
(float)sourceRc.left, (float)sourceRc.top, glTexCoord2f((float)sourceRc.right, (float)sourceRc.bottom); glVertex2f(1,1);
-1.f, 1.f, glTexCoord2f((float)sourceRc.right, (float)sourceRc.top); glVertex2f(1,-1);
(float)sourceRc.left, (float)sourceRc.bottom, glEnd();
1.f, 1.f,
(float)sourceRc.right, (float)sourceRc.bottom,
1.f, -1.f,
(float)sourceRc.right, (float)sourceRc.top
};
glBindBuffer(GL_ARRAY_BUFFER, s_encode_VBO );
glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
s_cached_sourceRc = sourceRc;
}
glBindVertexArray( s_encode_VAO );
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
// .. and then read back the results. // .. and then read back the results.
@ -436,39 +375,18 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid); PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
if(s_cached_srcHeight != srcHeight || s_cached_srcWidth != srcWidth) { glBegin(GL_QUADS);
GLfloat vertices[] = { glTexCoord2f((float)srcFmtWidth, (float)srcHeight); glVertex2f(1,-1);
1.f, -1.f, glTexCoord2f((float)srcFmtWidth, 0); glVertex2f(1,1);
(float)srcFmtWidth, (float)srcHeight, glTexCoord2f(0, 0); glVertex2f(-1,1);
1.f, 1.f, glTexCoord2f(0, (float)srcHeight); glVertex2f(-1,-1);
(float)srcFmtWidth, 0.f, glEnd();
-1.f, 1.f,
0.f, 0.f,
-1.f, -1.f,
0.f, (float)srcHeight
};
glBindBuffer(GL_ARRAY_BUFFER, s_decode_VBO );
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*4*4, vertices, GL_STREAM_DRAW);
s_cached_srcHeight = srcHeight;
s_cached_srcWidth = srcWidth;
}
glBindVertexArray( s_decode_VAO );
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
// TODO: this after merging with graphic_update
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GL_REPORT_ERRORD();
// reset state // reset state
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, 0, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, 0, 0);
TextureCache::DisableStage(0); TextureCache::DisableStage(0);
VertexShaderManager::SetViewportChanged(); VertexShaderManager::SetViewportChanged();

View File

@ -64,6 +64,9 @@ VertexManager::VertexManager()
// max_Index_size = MAXIBUFFERSIZE; // max_Index_size = MAXIBUFFERSIZE;
// //
//GL_REPORT_ERRORD(); //GL_REPORT_ERRORD();
glEnableClientState(GL_VERTEX_ARRAY);
GL_REPORT_ERRORD();
} }
void VertexManager::CreateDeviceObjects() void VertexManager::CreateDeviceObjects()

View File

@ -96,11 +96,12 @@ void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
#ifndef USE_GLES #ifndef USE_GLES
int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth(); int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight(); 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, s_pfont->printMultilineText(pstr,
left * 2.0f / (float)nBackbufferWidth - 1, left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight, 1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight, color); 0, nBackbufferWidth, nBackbufferHeight);
#endif #endif
} }