Merge pull request #790 from lioncash/ogl-cleanup

Small OGL cleanup
This commit is contained in:
Lioncash 2014-08-17 15:17:04 -04:00
commit 15a3b30e27
16 changed files with 225 additions and 94 deletions

View File

@ -42,7 +42,8 @@
// There may be multiple XFBs in GameCube RAM. This is the maximum number to
// virtualize.
namespace OGL {
namespace OGL
{
struct XFBSource : public XFBSourceBase
{

View File

@ -54,13 +54,20 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade
GLsizei stringBufferUsage = 0;
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer);
if (Result && stringBufferUsage) {
if (Result && stringBufferUsage)
{
ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader);
} else if (!Result) {
}
else if (!Result)
{
ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader);
} else {
}
else
{
DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader);
}
bool shader_errors = !Result;
#endif
@ -70,13 +77,20 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
if (Result && stringBufferUsage) {
if (Result && stringBufferUsage)
{
ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader);
} else if (!Result) {
}
else if (!Result)
{
ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader);
} else {
}
else
{
DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader);
}
shader_errors |= !Result;
#endif
@ -87,9 +101,13 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
glGetProgramiv(programID, GL_LINK_STATUS, &Result);
glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer);
if (Result && stringBufferUsage) {
if (Result && stringBufferUsage)
{
ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
} else if (!Result && !shader_errors) {
}
else if (!Result && !shader_errors)
{
ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
}
#endif

View File

@ -35,7 +35,7 @@ GLVertexFormat::~GLVertexFormat()
glDeleteVertexArrays(1, &VAO);
}
inline GLuint VarToGL(VarType t)
static inline GLuint VarToGL(VarType t)
{
static const GLuint lookup[5] = {
GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT
@ -75,24 +75,22 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position);
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++)
SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, vtx_decl.normals[i]);
}
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++)
SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, vtx_decl.colors[i]);
}
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++)
SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]);
}
SetPointer(SHADER_POSMTX_ATTRIB, vertex_stride, vtx_decl.posmtx);
vm->m_last_vao = VAO;
}
void GLVertexFormat::SetupVertexPointers() {
void GLVertexFormat::SetupVertexPointers()
{
}
}

View File

@ -3,7 +3,8 @@
#include <array>
#include "VideoCommon/PerfQueryBase.h"
namespace OGL {
namespace OGL
{
class PerfQuery : public PerfQueryBase
{

View File

@ -164,24 +164,28 @@ void OpenGLPostProcessing::Update(u32 width, u32 height)
void OpenGLPostProcessing::ApplyShader()
{
// shader didn't changed
if (m_config.GetShader() == g_ActiveConfig.sPostProcessingShader) return;
if (m_config.GetShader() == g_ActiveConfig.sPostProcessingShader)
return;
m_enable = false;
m_shader.Destroy();
m_uniform_bindings.clear();
// shader disabled
if (g_ActiveConfig.sPostProcessingShader == "") return;
if (g_ActiveConfig.sPostProcessingShader == "")
return;
// so need to compile shader
std::string code = m_config.LoadShader();
if (code == "") return;
if (code == "")
return;
code = LoadShaderOptions(code);
// and compile it
if (!ProgramShaderCache::CompileShader(m_shader, s_vertex_shader, code.c_str())) {
if (!ProgramShaderCache::CompileShader(m_shader, s_vertex_shader, code.c_str()))
{
ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", m_config.GetShader().c_str());
return;
}

View File

@ -111,7 +111,8 @@ void SHADER::SetProgramBindings()
glBindAttribLocation(glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
for (int i=0; i<8; i++) {
for (int i = 0; i < 8; i++)
{
char attrib_name[8];
snprintf(attrib_name, 8, "tex%d", i);
glBindAttribLocation(glprogid, SHADER_TEXTURE0_ATTRIB+i, attrib_name);
@ -153,12 +154,12 @@ void ProgramShaderCache::UploadConstants()
}
}
GLuint ProgramShaderCache::GetCurrentProgram(void)
GLuint ProgramShaderCache::GetCurrentProgram()
{
return CurrentProgram;
}
SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 components )
SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{
SHADERUID uid;
GetShaderId(&uid, dstAlphaMode, components);
@ -216,7 +217,8 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen
}
#endif
if (!CompileShader(newentry.shader, vcode.GetBuffer(), pcode.GetBuffer())) {
if (!CompileShader(newentry.shader, vcode.GetBuffer(), pcode.GetBuffer()))
{
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return nullptr;
}
@ -229,7 +231,7 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen
return &last_entry->shader;
}
bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, const char* pcode )
bool ProgramShaderCache::CompileShader(SHADER& shader, const char* vcode, const char* pcode)
{
GLuint vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode);
GLuint psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode);
@ -275,12 +277,14 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons
file.close();
if (linkStatus != GL_TRUE)
{
PanicAlert("Failed to link shaders!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%s, %s, %s):\n%s",
filename.c_str(),
g_ogl_config.gl_vendor,
g_ogl_config.gl_renderer,
g_ogl_config.gl_version,
infoLog);
}
delete [] infoLog;
}
@ -299,7 +303,7 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons
return true;
}
GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code )
GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const char* code)
{
GLuint result = glCreateShader(type);
@ -332,13 +336,15 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code )
file.close();
if (compileStatus != GL_TRUE)
{
PanicAlert("Failed to compile %s shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%s, %s, %s):\n%s",
type==GL_VERTEX_SHADER ? "vertex" : "pixel",
type == GL_VERTEX_SHADER ? "vertex" : "pixel",
filename.c_str(),
g_ogl_config.gl_vendor,
g_ogl_config.gl_renderer,
g_ogl_config.gl_version,
infoLog);
}
delete[] infoLog;
}
@ -372,12 +378,12 @@ void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode,
}
}
ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void)
ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram()
{
return *last_entry;
}
void ProgramShaderCache::Init(void)
void ProgramShaderCache::Init()
{
// We have to get the UBO alignment here because
// if we generate a buffer that isn't aligned
@ -421,7 +427,7 @@ void ProgramShaderCache::Init(void)
last_entry = nullptr;
}
void ProgramShaderCache::Shutdown(void)
void ProgramShaderCache::Shutdown()
{
// store all shaders in cache on disk
if (g_ogl_config.bSupportsGLSLCache && !g_Config.bEnableShaderDebugging)
@ -468,7 +474,7 @@ void ProgramShaderCache::Shutdown(void)
s_buffer = nullptr;
}
void ProgramShaderCache::CreateHeader ( void )
void ProgramShaderCache::CreateHeader()
{
GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
snprintf(s_glsl_header, sizeof(s_glsl_header),
@ -520,7 +526,7 @@ void ProgramShaderCache::CreateHeader ( void )
}
void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key, const u8* value, u32 value_size )
void ProgramShaderCache::ProgramShaderCacheInserter::Read(const SHADERUID& key, const u8* value, u32 value_size)
{
const u8 *binary = value+sizeof(GLenum);
GLenum *prog_format = (GLenum*)value;
@ -540,7 +546,9 @@ void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key
entry.shader.SetProgramVariables();
}
else
{
glDeleteProgram(entry.shader.glprogid);
}
}

View File

@ -25,9 +25,15 @@ public:
bool operator <(const SHADERUID& r) const
{
if (puid < r.puid) return true;
if (r.puid < puid) return false;
if (vuid < r.vuid) return true;
if (puid < r.puid)
return true;
if (r.puid < puid)
return false;
if (vuid < r.vuid)
return true;
return false;
}
@ -72,8 +78,8 @@ public:
typedef std::map<SHADERUID, PCacheEntry> PCache;
static PCacheEntry GetShaderProgram(void);
static GLuint GetCurrentProgram(void);
static PCacheEntry GetShaderProgram();
static GLuint GetCurrentProgram();
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
@ -81,9 +87,9 @@ public:
static GLuint CompileSingleShader(GLuint type, const char *code);
static void UploadConstants();
static void Init(void);
static void Shutdown(void);
static void CreateHeader(void);
static void Init();
static void Shutdown();
static void CreateHeader();
private:
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>

View File

@ -8,7 +8,8 @@
// globals
namespace OGL {
namespace OGL
{
static const int char_width = 8;
static const int char_height = 13;

View File

@ -13,7 +13,7 @@ class RasterFont
{
public:
RasterFont();
~RasterFont(void);
~RasterFont();
static int debug;
void printMultilineText(const std::string& text, double x, double y, double z, int bbWidth, int bbHeight, u32 color);

View File

@ -64,7 +64,8 @@ static int OSDInternalW, OSDInternalH;
namespace OGL
{
enum MultisampleMode {
enum MultisampleMode
{
MULTISAMPLE_OFF,
MULTISAMPLE_2X,
MULTISAMPLE_4X,
@ -125,26 +126,34 @@ static int GetNumMSAASamples(int MSAAMode)
samples = 1;
}
if (samples <= g_ogl_config.max_samples) return samples;
if (samples <= g_ogl_config.max_samples)
return samples;
// TODO: move this to InitBackendInfo
OSD::AddMessage(StringFromFormat("%d Anti Aliasing samples selected, but only %d supported by your GPU.", samples, g_ogl_config.max_samples), 10000);
return g_ogl_config.max_samples;
}
static void ApplySSAASettings() {
static void ApplySSAASettings()
{
// GLES3 doesn't support SSAA
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
{
if (g_ActiveConfig.iMultisampleMode == MULTISAMPLE_SSAA_4X) {
if (g_ogl_config.bSupportSampleShading) {
if (g_ActiveConfig.iMultisampleMode == MULTISAMPLE_SSAA_4X)
{
if (g_ogl_config.bSupportSampleShading)
{
glEnable(GL_SAMPLE_SHADING_ARB);
glMinSampleShadingARB(s_MSAASamples);
} else {
}
else
{
// TODO: move this to InitBackendInfo
OSD::AddMessage("SSAA Anti Aliasing isn't supported by your GPU.", 10000);
}
} else if (g_ogl_config.bSupportSampleShading) {
}
else if (g_ogl_config.bSupportSampleShading)
{
glDisable(GL_SAMPLE_SHADING_ARB);
}
}
@ -208,28 +217,46 @@ static void InitDriverInfo()
// Get the vendor first
if (svendor == "NVIDIA Corporation" && srenderer != "NVIDIA Tegra")
{
vendor = DriverDetails::VENDOR_NVIDIA;
}
else if (svendor == "ATI Technologies Inc." || svendor == "Advanced Micro Devices, Inc.")
{
vendor = DriverDetails::VENDOR_ATI;
}
else if (std::string::npos != sversion.find("Mesa"))
{
vendor = DriverDetails::VENDOR_MESA;
}
else if (std::string::npos != svendor.find("Intel"))
{
vendor = DriverDetails::VENDOR_INTEL;
}
else if (svendor == "ARM")
{
vendor = DriverDetails::VENDOR_ARM;
}
else if (svendor == "http://limadriver.org/")
{
vendor = DriverDetails::VENDOR_ARM;
driver = DriverDetails::DRIVER_LIMA;
}
else if (svendor == "Qualcomm")
{
vendor = DriverDetails::VENDOR_QUALCOMM;
}
else if (svendor == "Imagination Technologies")
{
vendor = DriverDetails::VENDOR_IMGTEC;
}
else if (svendor == "NVIDIA Corporation" && srenderer == "NVIDIA Tegra")
{
vendor = DriverDetails::VENDOR_TEGRA;
}
else if (svendor == "Vivante Corporation")
{
vendor = DriverDetails::VENDOR_VIVANTE;
}
// Get device family and driver version...if we care about it
switch (vendor)
@ -588,8 +615,11 @@ Renderer::Renderer()
if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
{
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
{
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
}
else
{
if (g_ogl_config.bSupportOGL31)
{
glEnable(GL_PRIMITIVE_RESTART);
@ -601,6 +631,7 @@ Renderer::Renderer()
glPrimitiveRestartIndexNV(65535);
}
}
}
UpdateActiveConfig();
ClearEFBCache();
}
@ -1045,9 +1076,21 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
{
color |= 0xFF000000;
}
if (alpha_read_mode.ReadMode == 2) return color; // GX_READ_NONE
else if (alpha_read_mode.ReadMode == 1) return (color | 0xFF000000); // GX_READ_FF
else /*if(alpha_read_mode.ReadMode == 0)*/ return (color & 0x00FFFFFF); // GX_READ_00
if (alpha_read_mode.ReadMode == 2)
{
// GX_READ_NONE
return color;
}
else if (alpha_read_mode.ReadMode == 1)
{
// GX_READ_FF
return (color | 0xFF000000);
}
else /*if(alpha_read_mode.ReadMode == 0)*/
{
// GX_READ_00
return (color & 0x00FFFFFF);
}
}
case POKE_COLOR:
@ -1232,7 +1275,9 @@ void Renderer::SetBlendMode(bool forceUpdate)
newval |= bpmem.blendmode.subtract << 2;
if (bpmem.blendmode.subtract)
{
newval |= 0x0049; // enable blending src 1 dst 1
}
else if (bpmem.blendmode.blendenable)
{
newval |= 1; // enable blending
@ -1243,8 +1288,10 @@ void Renderer::SetBlendMode(bool forceUpdate)
u32 changes = forceUpdate ? 0xFFFFFFFF : newval ^ s_blendMode;
if (changes & 1)
{
// blend enable change
(newval & 1) ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
}
if (changes & 4)
{
@ -1271,12 +1318,16 @@ void Renderer::SetBlendMode(bool forceUpdate)
else
{
// we can't use GL_DST_COLOR or GL_ONE_MINUS_DST_COLOR for source in alpha channel so use their alpha equivalent instead
if (srcidx == BlendMode::DSTCLR) srcidx = BlendMode::DSTALPHA;
if (srcidx == BlendMode::INVDSTCLR) srcidx = BlendMode::INVDSTALPHA;
if (srcidx == BlendMode::DSTCLR)
srcidx = BlendMode::DSTALPHA;
else if (srcidx == BlendMode::INVDSTCLR)
srcidx = BlendMode::INVDSTALPHA;
// we can't use GL_SRC_COLOR or GL_ONE_MINUS_SRC_COLOR for destination in alpha channel so use their alpha equivalent instead
if (dstidx == BlendMode::SRCCLR) dstidx = BlendMode::SRCALPHA;
if (dstidx == BlendMode::INVSRCCLR) dstidx = BlendMode::INVSRCALPHA;
if (dstidx == BlendMode::SRCCLR)
dstidx = BlendMode::SRCALPHA;
else if (dstidx == BlendMode::INVSRCCLR)
dstidx = BlendMode::INVSRCALPHA;
}
GLenum srcFactorAlpha = glSrcFactors[srcidx];
GLenum dstFactorAlpha = glDestFactors[dstidx];
@ -1452,7 +1503,9 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
bAVIDumping = AVIDump::Start(w, h);
#endif
if (!bAVIDumping)
{
OSD::AddMessage("AVIDump Start failed", 2000);
}
else
{
OSD::AddMessage(StringFromFormat(
@ -1472,8 +1525,10 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
bLastFrameDumped = true;
}
else
{
NOTICE_LOG(VIDEO, "Error reading framebuffer");
}
}
else
{
if (bLastFrameDumped && bAVIDumping)
@ -1503,7 +1558,9 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
movie_file_name = File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump.raw";
pFrameDump.Open(movie_file_name, "wb");
if (!pFrameDump)
{
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
}
else
{
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h), 2000);
@ -1679,7 +1736,9 @@ void Renderer::SetGenerationMode()
glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
}
else
{
glDisable(GL_CULL_FACE);
}
}
void Renderer::SetDepthMode()

View File

@ -8,7 +8,8 @@ namespace OGL
void ClearEFBCache();
enum GLSL_VERSION {
enum GLSL_VERSION
{
GLSL_130,
GLSL_140,
GLSL_150, // and above
@ -17,7 +18,8 @@ enum GLSL_VERSION {
};
// ogl-only config, so not in VideoConfig.h
struct VideoConfig {
struct VideoConfig
{
bool bSupportsGLSLCache;
bool bSupportsGLPinnedMemory;
bool bSupportsGLSync;

View File

@ -95,8 +95,8 @@ void StreamBuffer::AllocMemory(u32 size)
m_free_iterator = m_iterator + size;
// if buffer is full
if (m_iterator + size >= m_size) {
if (m_iterator + size >= m_size)
{
// insert waiting slots in unused space at the end of the buffer
for (int i = SLOT(m_used_iterator); i < SYNC_POINTS; i++)
{
@ -126,16 +126,20 @@ void StreamBuffer::AllocMemory(u32 size)
class MapAndOrphan : public StreamBuffer
{
public:
MapAndOrphan(u32 type, u32 size) : StreamBuffer(type, size) {
MapAndOrphan(u32 type, u32 size) : StreamBuffer(type, size)
{
glBindBuffer(m_buffertype, m_buffer);
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
}
~MapAndOrphan() {
~MapAndOrphan()
{
}
std::pair<u8*, u32> Map(u32 size) override {
if (m_iterator + size >= m_size) {
std::pair<u8*, u32> Map(u32 size) override
{
if (m_iterator + size >= m_size)
{
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
m_iterator = 0;
}
@ -144,7 +148,8 @@ public:
return std::make_pair(pointer, m_iterator);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
glFlushMappedBufferRange(m_buffertype, 0, used_size);
glUnmapBuffer(m_buffertype);
m_iterator += used_size;
@ -161,24 +166,28 @@ public:
class MapAndSync : public StreamBuffer
{
public:
MapAndSync(u32 type, u32 size) : StreamBuffer(type, size) {
MapAndSync(u32 type, u32 size) : StreamBuffer(type, size)
{
CreateFences();
glBindBuffer(m_buffertype, m_buffer);
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
}
~MapAndSync() {
~MapAndSync()
{
DeleteFences();
}
std::pair<u8*, u32> Map(u32 size) override {
std::pair<u8*, u32> Map(u32 size) override
{
AllocMemory(size);
u8* pointer = (u8*)glMapBufferRange(m_buffertype, m_iterator, size,
GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
return std::make_pair(pointer, m_iterator);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
glFlushMappedBufferRange(m_buffertype, 0, used_size);
glUnmapBuffer(m_buffertype);
m_iterator += used_size;
@ -201,7 +210,8 @@ public:
class BufferStorage : public StreamBuffer
{
public:
BufferStorage(u32 type, u32 size) : StreamBuffer(type, size) {
BufferStorage(u32 type, u32 size) : StreamBuffer(type, size)
{
CreateFences();
glBindBuffer(m_buffertype, m_buffer);
@ -214,18 +224,21 @@ public:
GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
}
~BufferStorage() {
~BufferStorage()
{
DeleteFences();
glUnmapBuffer(m_buffertype);
glBindBuffer(m_buffertype, 0);
}
std::pair<u8*, u32> Map(u32 size) override {
std::pair<u8*, u32> Map(u32 size) override
{
AllocMemory(size);
return std::make_pair(m_pointer + m_iterator, m_iterator);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
glFlushMappedBufferRange(m_buffertype, m_iterator, used_size);
m_iterator += used_size;
}
@ -243,7 +256,8 @@ public:
class PinnedMemory : public StreamBuffer
{
public:
PinnedMemory(u32 type, u32 size) : StreamBuffer(type, size) {
PinnedMemory(u32 type, u32 size) : StreamBuffer(type, size)
{
CreateFences();
m_pointer = (u8*)AllocateAlignedMemory(ROUND_UP(m_size,ALIGN_PINNED_MEMORY), ALIGN_PINNED_MEMORY );
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_buffer);
@ -252,7 +266,8 @@ public:
glBindBuffer(m_buffertype, m_buffer);
}
~PinnedMemory() {
~PinnedMemory()
{
DeleteFences();
glBindBuffer(m_buffertype, 0);
glFinish(); // ogl pipeline must be flushed, else this buffer can be in use
@ -260,12 +275,14 @@ public:
m_pointer = nullptr;
}
std::pair<u8*, u32> Map(u32 size) override {
std::pair<u8*, u32> Map(u32 size) override
{
AllocMemory(size);
return std::make_pair(m_pointer + m_iterator, m_iterator);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
m_iterator += used_size;
}
@ -281,21 +298,25 @@ public:
class BufferSubData : public StreamBuffer
{
public:
BufferSubData(u32 type, u32 size) : StreamBuffer(type, size) {
BufferSubData(u32 type, u32 size) : StreamBuffer(type, size)
{
glBindBuffer(m_buffertype, m_buffer);
glBufferData(m_buffertype, size, nullptr, GL_STATIC_DRAW);
m_pointer = new u8[m_size];
}
~BufferSubData() {
~BufferSubData()
{
delete [] m_pointer;
}
std::pair<u8*, u32> Map(u32 size) override {
std::pair<u8*, u32> Map(u32 size) override
{
return std::make_pair(m_pointer, 0);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
glBufferSubData(m_buffertype, 0, used_size, m_pointer);
}
@ -310,20 +331,24 @@ public:
class BufferData : public StreamBuffer
{
public:
BufferData(u32 type, u32 size) : StreamBuffer(type, size) {
BufferData(u32 type, u32 size) : StreamBuffer(type, size)
{
glBindBuffer(m_buffertype, m_buffer);
m_pointer = new u8[m_size];
}
~BufferData() {
~BufferData()
{
delete [] m_pointer;
}
std::pair<u8*, u32> Map(u32 size) override {
std::pair<u8*, u32> Map(u32 size) override
{
return std::make_pair(m_pointer, 0);
}
void Unmap(u32 used_size) override {
void Unmap(u32 used_size) override
{
glBufferData(m_buffertype, used_size, m_pointer, GL_STREAM_DRAW);
}

View File

@ -12,7 +12,8 @@
namespace OGL
{
class StreamBuffer {
class StreamBuffer
{
public:
static StreamBuffer* Create(u32 type, u32 size);

View File

@ -298,8 +298,10 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
format |= _GX_TF_CTF;
}
else
{
if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
format |= _GX_TF_CTF;
}
SHADER& texconv_shader = GetOrCreateEncodingShader(format);

View File

@ -116,11 +116,15 @@ void VertexManager::Draw(u32 stride)
break;
}
if (g_ogl_config.bSupportsGLBaseVertex) {
if (g_ogl_config.bSupportsGLBaseVertex)
{
glDrawRangeElementsBaseVertex(primitive_mode, 0, max_index, index_size, GL_UNSIGNED_SHORT, (u8*)nullptr+s_index_offset, (GLint)s_baseVertex);
} else {
}
else
{
glDrawRangeElements(primitive_mode, 0, max_index, index_size, GL_UNSIGNED_SHORT, (u8*)nullptr+s_index_offset);
}
INCSTAT(stats.thisFrame.numDrawCalls);
}
@ -129,7 +133,8 @@ void VertexManager::vFlush(bool useDstAlpha)
GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
u32 stride = nativeVertexFmt->GetVertexStride();
if (m_last_vao != nativeVertexFmt->VAO) {
if (m_last_vao != nativeVertexFmt->VAO)
{
glBindVertexArray(nativeVertexFmt->VAO);
m_last_vao = nativeVertexFmt->VAO;
}

View File

@ -226,8 +226,8 @@ void VideoBackend::Shutdown()
GLInterface->Shutdown();
}
void VideoBackend::Video_Cleanup() {
void VideoBackend::Video_Cleanup()
{
if (g_renderer)
{
s_efbAccessRequested = false;