diff options
| author | skidau <skidau@gmail.com> | 2013-03-27 13:19:23 +1100 |
|---|---|---|
| committer | skidau <skidau@gmail.com> | 2013-03-27 13:19:23 +1100 |
| commit | 7784fa4c67cc8d2545f45694d83805e7e89cd583 (patch) | |
| tree | 7724133aabe971ec417d1dea0977a525bb8debfb /Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp | |
| parent | d33c19b0cd2bae982c8d35e86a9d3551f9e5c72f (diff) | |
| parent | 5cea0d9defeaa23e7af94adf7615a44fb2c9c173 (diff) | |
Merge branch 'master' into wii-network
# By Ryan Houdek (185) and others
# Via degasus (12) and others
* master: (625 commits)
Revert "Don't open/close file for every file operation." as it was crashing PokePark in Windows builds.
Array overrun fixed in VertexShaderCache for the DX11 plugin.
Fixed DSPTool build.
Windows build fix
Go back to assuming every HID device is a wiimote on Windows. Fixed issue 6117. Unfixed issue 6031.
VideoSoftware: Improve fog range adjustment by using less magic and more comments.
revert RasterFont for VideoSoftware
ogl: fix virtual xfb
Windows build fix from web interface...
Adjusted the audio loop criteria, using >= on the Wii and == on GC. This fixes the audio static that occurred in Wii games after hours of play.
Forced the exception check only for ARAM DMA transfers. Removed the Eternal Darkness boot hack and replaced it with an exception check.
VideoSoftware: Implement fog range adjustment, fixing issue 6147.
implement 4xSSAA for OGL
move ogl-only settings into backend
Fix description of disable fog, and move it to enhancements tab.
Reverted rd76ca5783743 as it was made obsolete by r1d550f4496e4.
Removed the tracking of the FIFO Writes as it was made obsolete by r1d550f4496e4.
Forced the external exception check to occur sooner by changing the downcount.
Mark the Direct3D9 backend deprecated.
Prefer D3D11 and OpenGL over D3D9 by default.
...
Conflicts:
CMakeLists.txt
Source/Core/Common/Common.vcxproj.filters
Source/Core/Common/Src/CommonPaths.h
Source/Core/Core/Core.vcxproj.filters
Source/Core/Core/Src/Core.cpp
Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
Source/VSProps/Dolphin.Win32.props
Source/VSProps/Dolphin.x64.props
Diffstat (limited to 'Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp')
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp | 242 |
1 files changed, 34 insertions, 208 deletions
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index ae20649433..acfdb7ee2e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -17,56 +17,18 @@ #include "GLUtil.h" #include "x64Emitter.h" -#include "ABI.h" +#include "x64ABI.h" #include "MemoryUtil.h" +#include "ProgramShaderCache.h" #include "VertexShaderGen.h" #include "CPMemory.h" #include "NativeVertexFormat.h" #include "VertexManager.h" -#define COMPILED_CODE_SIZE 4096 - -// TODO: this guy is never initialized -u32 s_prevcomponents; // previous state set -/* -#ifdef _WIN32 -#ifdef _M_IX86 -#define USE_JIT -#endif -#endif -*/ -// Note the use of CallCdeclFunction3I etc. -// This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit -// address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we -// want to grab the function pointers from the import table instead. - -// This problem does not apply to glew functions, only core opengl32 functions. - // Here's some global state. We only use this to keep track of what we've sent to the OpenGL state // machine. -#ifdef USE_JIT -DECLARE_IMPORT(glNormalPointer); -DECLARE_IMPORT(glVertexPointer); -DECLARE_IMPORT(glColorPointer); -DECLARE_IMPORT(glTexCoordPointer); -#endif - -class GLVertexFormat : public NativeVertexFormat -{ - u8 *m_compiledCode; - PortableVertexDeclaration vtx_decl; - -public: - GLVertexFormat(); - ~GLVertexFormat(); - - virtual void Initialize(const PortableVertexDeclaration &_vtx_decl); - virtual void SetupVertexPointers(); - virtual void EnableComponents(u32 components); -}; - namespace OGL { @@ -75,23 +37,14 @@ NativeVertexFormat* VertexManager::CreateNativeVertexFormat() return new GLVertexFormat(); } -} - GLVertexFormat::GLVertexFormat() { -#ifdef USE_JIT - m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false); - if (m_compiledCode) - memset(m_compiledCode, 0, COMPILED_CODE_SIZE); -#endif + } GLVertexFormat::~GLVertexFormat() { -#ifdef USE_JIT - FreeMemoryPages(m_compiledCode, COMPILED_CODE_SIZE); - m_compiledCode = 0; -#endif + glDeleteVertexArrays(1, &VAO); } inline GLuint VarToGL(VarType t) @@ -104,183 +57,56 @@ inline GLuint VarToGL(VarType t) void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) { - s_prevcomponents = 0; - - vertex_stride = _vtx_decl.stride; - using namespace Gen; + this->vtx_decl = _vtx_decl; + vertex_stride = vtx_decl.stride; // We will not allow vertex components causing uneven strides. - if (_vtx_decl.stride & 3) - PanicAlert("Uneven vertex stride: %i", _vtx_decl.stride); - -#ifdef USE_JIT - Gen::XEmitter emit(m_compiledCode); - // Alright, we have our vertex declaration. Compile some crazy code to set it quickly using GL. - emit.ABI_EmitPrologue(6); + if (vertex_stride & 3) + PanicAlert("Uneven vertex stride: %i", vertex_stride); - emit.CallCdeclFunction4_I(glVertexPointer, 3, GL_FLOAT, _vtx_decl.stride, 0); - - if (_vtx_decl.num_normals >= 1) - { - emit.CallCdeclFunction3_I(glNormalPointer, VarToGL(_vtx_decl.normal_gl_type), _vtx_decl.stride, _vtx_decl.normal_offset[0]); - if (_vtx_decl.num_normals == 3) { - emit.CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, _vtx_decl.normal_gl_size, VarToGL(_vtx_decl.normal_gl_type), GL_TRUE, _vtx_decl.stride, _vtx_decl.normal_offset[1]); - emit.CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, _vtx_decl.normal_gl_size, VarToGL(_vtx_decl.normal_gl_type), GL_TRUE, _vtx_decl.stride, _vtx_decl.normal_offset[2]); - } - } - - for (int i = 0; i < 2; i++) - { - if (_vtx_decl.color_offset[i] != -1) - { - if (i == 0) - emit.CallCdeclFunction4_I(glColorPointer, 4, GL_UNSIGNED_BYTE, _vtx_decl.stride, _vtx_decl.color_offset[i]); - else - emit.CallCdeclFunction4((void *)glSecondaryColorPointer, 4, GL_UNSIGNED_BYTE, _vtx_decl.stride, _vtx_decl.color_offset[i]); - } - } - - for (int i = 0; i < 8; i++) - { - if (_vtx_decl.texcoord_offset[i] != -1) - { - int id = GL_TEXTURE0 + i; -#ifdef _M_X64 -#ifdef _MSC_VER - emit.MOV(32, R(RCX), Imm32(id)); -#else - emit.MOV(32, R(RDI), Imm32(id)); -#endif -#else - emit.ABI_AlignStack(1 * 4); - emit.PUSH(32, Imm32(id)); -#endif - emit.CALL((void *)glClientActiveTexture); -#ifndef _M_X64 -#ifdef _WIN32 - // don't inc stack on windows, stdcall -#else - emit.ABI_RestoreStack(1 * 4); -#endif -#endif - emit.CallCdeclFunction4_I( - glTexCoordPointer, _vtx_decl.texcoord_size[i], VarToGL(_vtx_decl.texcoord_gl_type[i]), - _vtx_decl.stride, _vtx_decl.texcoord_offset[i]); - } - } - - if (_vtx_decl.posmtx_offset != -1) - emit.CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, _vtx_decl.stride, _vtx_decl.posmtx_offset); - - emit.ABI_EmitEpilogue(6); - - if (emit.GetCodePtr() - (u8*)m_compiledCode > COMPILED_CODE_SIZE) - Crash(); - -#endif - this->vtx_decl = _vtx_decl; -} + VertexManager *vm = (OGL::VertexManager*)g_vertex_manager; + + glGenVertexArrays(1, &VAO); + glBindVertexArray(VAO); + + // the element buffer is bound directly to the vao, so we must it set for every vao + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vm->m_index_buffers); + glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers); -void GLVertexFormat::SetupVertexPointers() { - // Cast a pointer to compiled code to a pointer to a function taking no parameters, through a (void *) cast first to - // get around type checking errors, and call it. -#ifdef USE_JIT - ((void (*)())(void*)m_compiledCode)(); -#else - glVertexPointer(3, GL_FLOAT, vtx_decl.stride, VertexManager::s_pBaseBufferPointer); - 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])); - if (vtx_decl.num_normals == 3) { - glVertexAttribPointer(SHADER_NORM1_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[1])); - glVertexAttribPointer(SHADER_NORM2_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[2])); + glEnableVertexAttribArray(SHADER_POSITION_ATTRIB); + glVertexAttribPointer(SHADER_POSITION_ATTRIB, 3, GL_FLOAT, GL_FALSE, vtx_decl.stride, (u8*)NULL); + + for (int i = 0; i < 3; i++) { + if (vtx_decl.num_normals > i) { + glEnableVertexAttribArray(SHADER_NORM0_ATTRIB+i); + glVertexAttribPointer(SHADER_NORM0_ATTRIB+i, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.normal_offset[i]); } } for (int i = 0; i < 2; i++) { if (vtx_decl.color_offset[i] != -1) { - if (i == 0) - glColorPointer(4, GL_UNSIGNED_BYTE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.color_offset[i])); - else { - glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.color_offset[i])); - } + glEnableVertexAttribArray(SHADER_COLOR0_ATTRIB+i); + glVertexAttribPointer(SHADER_COLOR0_ATTRIB+i, 4, GL_UNSIGNED_BYTE, GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.color_offset[i]); } } for (int i = 0; i < 8; i++) { if (vtx_decl.texcoord_offset[i] != -1) { - int id = GL_TEXTURE0 + i; - glClientActiveTexture(id); - glTexCoordPointer(vtx_decl.texcoord_size[i], VarToGL(vtx_decl.texcoord_gl_type[i]), - vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.texcoord_offset[i])); + glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB+i); + glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB+i, vtx_decl.texcoord_size[i], VarToGL(vtx_decl.texcoord_gl_type[i]), + GL_FALSE, vtx_decl.stride, (u8*)NULL + vtx_decl.texcoord_offset[i]); } } if (vtx_decl.posmtx_offset != -1) { - glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset)); + glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glVertexAttribIPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, vtx_decl.stride, (u8*)NULL + vtx_decl.posmtx_offset); } -#endif -} - -void GLVertexFormat::EnableComponents(u32 components) -{ - if (s_prevcomponents != components) - { - VertexManager::Flush(); - // matrices - if ((components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) - { - if (components & VB_HAS_POSMTXIDX) - glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); - else - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - } - - // normals - if ((components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) - { - if (components & VB_HAS_NRM0) - glEnableClientState(GL_NORMAL_ARRAY); - else - glDisableClientState(GL_NORMAL_ARRAY); - } - if ((components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) - { - if (components & VB_HAS_NRM1) { - glEnableVertexAttribArray(SHADER_NORM1_ATTRIB); - glEnableVertexAttribArray(SHADER_NORM2_ATTRIB); - } - else { - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - } - } - - // color - for (int i = 0; i < 2; ++i) - { - if ((components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) - { - if (components & (VB_HAS_COL0 << i)) - glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); - else - glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); - } - } + vm->m_last_vao = VAO; +} - // tex - for (int i = 0; i < 8; ++i) - { - if ((components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) - { - glClientActiveTexture(GL_TEXTURE0 + i); - if (components & (VB_HAS_UV0 << i)) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - else - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } +void GLVertexFormat::SetupVertexPointers() { +} - s_prevcomponents = components; - } } |
