diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp index a506acadfc..f32e5dfeee 100644 --- a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp @@ -23,7 +23,7 @@ int GetLightingShaderId(u32* out) { - for (int i = 0; i < xfregs.numChan.numColorChans; ++i) + for (u32 i = 0; i < xfregs.numChan.numColorChans; ++i) { out[i] = xfregs.color[i].enablelighting ? (u32)xfregs.color[i].hex : diff --git a/Source/Core/VideoCommon/Src/NativeVertexFormat.h b/Source/Core/VideoCommon/Src/NativeVertexFormat.h index 02184fde1c..1340991b21 100644 --- a/Source/Core/VideoCommon/Src/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/Src/NativeVertexFormat.h @@ -102,7 +102,7 @@ public: virtual void SetupVertexPointers() = 0; virtual void EnableComponents(u32 components) {} - int GetVertexStride() const { return vertex_stride; } + u32 GetVertexStride() const { return vertex_stride; } // TODO: move this under private: u32 m_components; // VB_HAS_X. Bitmask telling what vertex components are present. diff --git a/Source/Core/VideoCommon/Src/OpcodeDecoding.cpp b/Source/Core/VideoCommon/Src/OpcodeDecoding.cpp index 4f7f86d655..a1ff1a9985 100644 --- a/Source/Core/VideoCommon/Src/OpcodeDecoding.cpp +++ b/Source/Core/VideoCommon/Src/OpcodeDecoding.cpp @@ -346,7 +346,7 @@ static void Decode() // Display lists get added directly into the FIFO stream if (g_bRecordFifoData && cmd_byte != GX_CMD_CALL_DL) - FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, g_pVideoData - opcodeStart); + FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, u32(g_pVideoData - opcodeStart)); } static void DecodeSemiNop() @@ -429,7 +429,7 @@ static void DecodeSemiNop() } if (g_bRecordFifoData && cmd_byte != GX_CMD_CALL_DL) - FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, g_pVideoData - opcodeStart); + FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, u32(g_pVideoData - opcodeStart)); } void OpcodeDecoder_Init() diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index bc7a12304f..3d5e676c61 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -196,7 +196,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo *ptr++ = components; } - uid->num_values = ptr - uid->values; + uid->num_values = int(ptr - uid->values); } void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u32 components) @@ -229,7 +229,7 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u *ptr++ = bpmem.tevindref.hex; // 32 - for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times + for (u32 i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times { *ptr++ = bpmem.combiners[i].colorC.hex; // 33+5*i *ptr++ = bpmem.combiners[i].alphaC.hex; // 34+5*i diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp index 7026522cf6..48f84b9aca 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp @@ -41,39 +41,39 @@ namespace DX11 // TODO: Find sensible values for these two const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16 * sizeof(u16); const UINT VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16; -const UINT MAXVBUFFER_COUNT = 2; +const UINT MAX_VBUFFER_COUNT = 2; void VertexManager::CreateDeviceObjects() { D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(IBUFFER_SIZE, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); - m_vertexDrawOffset = 0; - m_triangleDrawIndex = 0; - m_lineDrawIndex = 0; - m_pointDrawIndex = 0; - m_indexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT]; - m_vertexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT]; - for (m_activeIndexBuffer = 0; m_activeIndexBuffer < MAXVBUFFER_COUNT; m_activeIndexBuffer++) + m_vertex_draw_offset = 0; + m_triangle_draw_index = 0; + m_line_draw_index = 0; + m_point_draw_index = 0; + m_index_buffers = new PID3D11Buffer[MAX_VBUFFER_COUNT]; + m_vertex_buffers = new PID3D11Buffer[MAX_VBUFFER_COUNT]; + for (m_current_index_buffer = 0; m_current_index_buffer < MAX_VBUFFER_COUNT; m_current_index_buffer++) { - m_indexBuffers[m_activeIndexBuffer] = NULL; - CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_indexBuffers[m_activeIndexBuffer])), + m_index_buffers[m_current_index_buffer] = NULL; + CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_index_buffers[m_current_index_buffer])), "Failed to create index buffer."); - D3D::SetDebugObjectName((ID3D11DeviceChild*)m_indexBuffers[m_activeIndexBuffer], "index buffer of VertexManager"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_index_buffers[m_current_index_buffer], "index buffer of VertexManager"); } bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufdesc.ByteWidth = VBUFFER_SIZE; - for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++) + for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++) { - m_vertexBuffers[m_activeVertexBuffer] = NULL; - CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertexBuffers[m_activeVertexBuffer])), + m_vertex_buffers[m_current_vertex_buffer] = NULL; + CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertex_buffers[m_current_vertex_buffer])), "Failed to create vertex buffer."); - D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertexBuffers[m_activeVertexBuffer], "Vertex buffer of VertexManager"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertex_buffers[m_current_vertex_buffer], "Vertex buffer of VertexManager"); } - m_activeVertexBuffer = 0; - m_activeIndexBuffer = 0; - m_indexBufferCursor = IBUFFER_SIZE; - m_vertexBufferCursor = VBUFFER_SIZE; + m_current_vertex_buffer = 0; + m_current_index_buffer = 0; + m_index_buffer_cursor = IBUFFER_SIZE; + m_vertex_buffer_cursor = VBUFFER_SIZE; m_lineShader.Init(); m_pointShader.Init(); } @@ -82,10 +82,10 @@ void VertexManager::DestroyDeviceObjects() { m_pointShader.Shutdown(); m_lineShader.Shutdown(); - for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++) + for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++) { - SAFE_RELEASE(m_vertexBuffers[m_activeVertexBuffer]); - SAFE_RELEASE(m_indexBuffers[m_activeVertexBuffer]); + SAFE_RELEASE(m_vertex_buffers[m_current_vertex_buffer]); + SAFE_RELEASE(m_index_buffers[m_current_vertex_buffer]); } } @@ -100,47 +100,47 @@ VertexManager::~VertexManager() DestroyDeviceObjects(); } -void VertexManager::LoadBuffers() +void VertexManager::PrepareDrawBuffers() { D3D11_MAPPED_SUBRESOURCE map; UINT vSize = UINT(s_pCurBufferPointer - LocalVBuffer); D3D11_MAP MapType = D3D11_MAP_WRITE_NO_OVERWRITE; - if (m_vertexBufferCursor + vSize >= VBUFFER_SIZE) + if (m_vertex_buffer_cursor + vSize >= VBUFFER_SIZE) { // Wrap around - m_activeVertexBuffer = (m_activeVertexBuffer + 1) % MAXVBUFFER_COUNT; - m_vertexBufferCursor = 0; + m_current_vertex_buffer = (m_current_vertex_buffer + 1) % MAX_VBUFFER_COUNT; + m_vertex_buffer_cursor = 0; MapType = D3D11_MAP_WRITE_DISCARD; } - D3D::context->Map(m_vertexBuffers[m_activeVertexBuffer], 0, MapType, 0, &map); + D3D::context->Map(m_vertex_buffers[m_current_vertex_buffer], 0, MapType, 0, &map); - memcpy((u8*)map.pData + m_vertexBufferCursor, LocalVBuffer, vSize); - D3D::context->Unmap(m_vertexBuffers[m_activeVertexBuffer], 0); - m_vertexDrawOffset = m_vertexBufferCursor; - m_vertexBufferCursor += vSize; + memcpy((u8*)map.pData + m_vertex_buffer_cursor, LocalVBuffer, vSize); + D3D::context->Unmap(m_vertex_buffers[m_current_vertex_buffer], 0); + m_vertex_draw_offset = m_vertex_buffer_cursor; + m_vertex_buffer_cursor += vSize; UINT iCount = IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen(); MapType = D3D11_MAP_WRITE_NO_OVERWRITE; - if (m_indexBufferCursor + iCount >= (IBUFFER_SIZE / sizeof(u16))) + if (m_index_buffer_cursor + iCount >= (IBUFFER_SIZE / sizeof(u16))) { // Wrap around - m_activeIndexBuffer = (m_activeIndexBuffer + 1) % MAXVBUFFER_COUNT; - m_indexBufferCursor = 0; + m_current_index_buffer = (m_current_index_buffer + 1) % MAX_VBUFFER_COUNT; + m_index_buffer_cursor = 0; MapType = D3D11_MAP_WRITE_DISCARD; } - D3D::context->Map(m_indexBuffers[m_activeIndexBuffer], 0, MapType, 0, &map); + D3D::context->Map(m_index_buffers[m_current_index_buffer], 0, MapType, 0, &map); - m_triangleDrawIndex = m_indexBufferCursor; - m_lineDrawIndex = m_triangleDrawIndex + IndexGenerator::GetTriangleindexLen(); - m_pointDrawIndex = m_lineDrawIndex + IndexGenerator::GetLineindexLen(); - memcpy((u16*)map.pData + m_triangleDrawIndex, TIBuffer, sizeof(u16) * IndexGenerator::GetTriangleindexLen()); - memcpy((u16*)map.pData + m_lineDrawIndex, LIBuffer, sizeof(u16) * IndexGenerator::GetLineindexLen()); - memcpy((u16*)map.pData + m_pointDrawIndex, PIBuffer, sizeof(u16) * IndexGenerator::GetPointindexLen()); - D3D::context->Unmap(m_indexBuffers[m_activeIndexBuffer], 0); - m_indexBufferCursor += iCount; + m_triangle_draw_index = m_index_buffer_cursor; + m_line_draw_index = m_triangle_draw_index + IndexGenerator::GetTriangleindexLen(); + m_point_draw_index = m_line_draw_index + IndexGenerator::GetLineindexLen(); + memcpy((u16*)map.pData + m_triangle_draw_index, TIBuffer, sizeof(u16) * IndexGenerator::GetTriangleindexLen()); + memcpy((u16*)map.pData + m_line_draw_index, LIBuffer, sizeof(u16) * IndexGenerator::GetLineindexLen()); + memcpy((u16*)map.pData + m_point_draw_index, PIBuffer, sizeof(u16) * IndexGenerator::GetPointindexLen()); + D3D::context->Unmap(m_index_buffers[m_current_index_buffer], 0); + m_index_buffer_cursor += iCount; } static const float LINE_PT_TEX_OFFSETS[8] = { @@ -149,13 +149,13 @@ static const float LINE_PT_TEX_OFFSETS[8] = { void VertexManager::Draw(UINT stride) { - D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffers[m_activeVertexBuffer], &stride, &m_vertexDrawOffset); - D3D::context->IASetIndexBuffer(m_indexBuffers[m_activeIndexBuffer], DXGI_FORMAT_R16_UINT, 0); + D3D::context->IASetVertexBuffers(0, 1, &m_vertex_buffers[m_current_vertex_buffer], &stride, &m_vertex_draw_offset); + D3D::context->IASetIndexBuffer(m_index_buffers[m_current_index_buffer], DXGI_FORMAT_R16_UINT, 0); if (IndexGenerator::GetNumTriangles() > 0) { D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - D3D::context->DrawIndexed(IndexGenerator::GetTriangleindexLen(), m_triangleDrawIndex, 0); + D3D::context->DrawIndexed(IndexGenerator::GetTriangleindexLen(), m_triangle_draw_index, 0); INCSTAT(stats.thisFrame.numIndexedDrawCalls); } // Disable culling for lines and points @@ -177,7 +177,7 @@ void VertexManager::Draw(UINT stride) texOffset, vpWidth, vpHeight, texOffsetEnable)) { D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); - D3D::context->DrawIndexed(IndexGenerator::GetLineindexLen(), m_lineDrawIndex, 0); + D3D::context->DrawIndexed(IndexGenerator::GetLineindexLen(), m_line_draw_index, 0); INCSTAT(stats.thisFrame.numIndexedDrawCalls); D3D::context->GSSetShader(NULL, NULL, 0); @@ -199,7 +199,7 @@ void VertexManager::Draw(UINT stride) texOffset, vpWidth, vpHeight, texOffsetEnable)) { D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); - D3D::context->DrawIndexed(IndexGenerator::GetPointindexLen(), m_pointDrawIndex, 0); + D3D::context->DrawIndexed(IndexGenerator::GetPointindexLen(), m_point_draw_index, 0); INCSTAT(stats.thisFrame.numIndexedDrawCalls); D3D::context->GSSetShader(NULL, NULL, 0); @@ -270,7 +270,7 @@ void VertexManager::vFlush() GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");}); goto shader_fail; } - LoadBuffers(); + PrepareDrawBuffers(); unsigned int stride = g_nativeVertexFmt->GetVertexStride(); g_nativeVertexFmt->SetupVertexPointers(); g_renderer->ApplyState(useDstAlpha); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h index 9e6b7f2dca..b5d0d21757 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h @@ -37,22 +37,22 @@ public: private: - void LoadBuffers(); - void Draw(UINT stride); + void PrepareDrawBuffers(); + void Draw(u32 stride); // temp void vFlush(); - UINT m_indexBufferCursor; - UINT m_vertexBufferCursor; - UINT m_vertexDrawOffset; - UINT m_triangleDrawIndex; - UINT m_lineDrawIndex; - UINT m_pointDrawIndex; - UINT m_activeVertexBuffer; - UINT m_activeIndexBuffer; + u32 m_vertex_buffer_cursor; + u32 m_vertex_draw_offset; + u32 m_index_buffer_cursor; + u32 m_current_vertex_buffer; + u32 m_current_index_buffer; + u32 m_triangle_draw_index; + u32 m_line_draw_index; + u32 m_point_draw_index; typedef ID3D11Buffer* PID3D11Buffer; - PID3D11Buffer* m_indexBuffers; - PID3D11Buffer* m_vertexBuffers; + PID3D11Buffer* m_index_buffers; + PID3D11Buffer* m_vertex_buffers; LineGeometryShader m_lineShader; PointGeometryShader m_pointShader; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index 17a7aa1498..884f16f826 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -44,7 +44,7 @@ namespace DX9 //This are the initially requeted size for the buffers expresed in elements const u32 IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16; const u32 VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16; -const u32 MAXVBUFFER_COUNT = 2; +const u32 MAX_VBUFFER_COUNT = 2; inline void DumpBadShaders() { @@ -67,52 +67,52 @@ inline void DumpBadShaders() void VertexManager::CreateDeviceObjects() { - NumVBuffers = 0; - VBuffers = NULL; - IBuffers = NULL; + m_buffers_count = 0; + m_vertex_buffers = NULL; + m_index_buffers = NULL; D3DCAPS9 DeviceCaps = D3D::GetCaps(); u32 devicevMaxBufferSize = DeviceCaps.MaxPrimitiveCount * 3 * DeviceCaps.MaxStreamStride; //Calculate Device Dependant size - CurrentVBufferSize = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE; - CurrentIBufferSize = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE; + m_vertex_buffer_size = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE; + m_index_buffer_size = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE; //if device caps are not enough for Vbuffer fall back to vertex arrays - if (CurrentIBufferSize < MAXIBUFFERSIZE || CurrentVBufferSize < MAXVBUFFERSIZE) return; + if (m_index_buffer_size < MAXIBUFFERSIZE || m_vertex_buffer_size < MAXVBUFFERSIZE) return; - VBuffers = new LPDIRECT3DVERTEXBUFFER9[MAXVBUFFER_COUNT]; - IBuffers = new LPDIRECT3DINDEXBUFFER9[MAXVBUFFER_COUNT]; + m_vertex_buffers = new LPDIRECT3DVERTEXBUFFER9[MAX_VBUFFER_COUNT]; + m_index_buffers = new LPDIRECT3DINDEXBUFFER9[MAX_VBUFFER_COUNT]; bool Fail = false; - for (CurrentVBuffer = 0; CurrentVBuffer < MAXVBUFFER_COUNT; CurrentVBuffer++) + for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++) { - VBuffers[CurrentVBuffer] = NULL; - IBuffers[CurrentVBuffer] = NULL; + m_vertex_buffers[m_current_vertex_buffer] = NULL; + m_index_buffers[m_current_vertex_buffer] = NULL; } - for (CurrentVBuffer = 0; CurrentVBuffer < MAXVBUFFER_COUNT; CurrentVBuffer++) + for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++) { - if(FAILED( D3D::dev->CreateVertexBuffer( CurrentVBufferSize, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &VBuffers[CurrentVBuffer], NULL ) ) ) + if(FAILED( D3D::dev->CreateVertexBuffer( m_vertex_buffer_size, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_vertex_buffers[m_current_vertex_buffer], NULL ) ) ) { Fail = true; break; } - if( FAILED( D3D::dev->CreateIndexBuffer( CurrentIBufferSize * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &IBuffers[CurrentVBuffer], NULL ) ) ) + if( FAILED( D3D::dev->CreateIndexBuffer( m_index_buffer_size * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_index_buffers[m_current_vertex_buffer], NULL ) ) ) { Fail = true; return; } } - NumVBuffers = CurrentVBuffer; - CurrentVBuffer = 0; - CurrentIBuffer = 0; - CurrentIBufferIndex = CurrentIBufferSize; - CurrentVBufferIndex = CurrentVBufferSize; + m_buffers_count = m_current_vertex_buffer; + m_current_vertex_buffer = 0; + m_current_index_buffer = 0; + m_index_buffer_cursor = m_index_buffer_size; + m_vertex_buffer_cursor = m_vertex_buffer_size; if (Fail) { - NumVBuffers--; - if (NumVBuffers < 2) + m_buffers_count--; + if (m_buffers_count < 2) { //Error creating Vertex buffers. clean and fall to Vertex arrays - NumVBuffers = MAXVBUFFER_COUNT; + m_buffers_count = MAX_VBUFFER_COUNT; DestroyDeviceObjects(); } } @@ -121,34 +121,34 @@ void VertexManager::DestroyDeviceObjects() { D3D::dev->SetStreamSource( 0, NULL, 0, 0); D3D::dev->SetIndices(NULL); - for (int i = 0; i < MAXVBUFFER_COUNT; i++) + for (int i = 0; i < MAX_VBUFFER_COUNT; i++) { - if(VBuffers) + if(m_vertex_buffers) { - if (VBuffers[i]) + if (m_vertex_buffers[i]) { - VBuffers[i]->Release(); - VBuffers[i] = NULL; + m_vertex_buffers[i]->Release(); + m_vertex_buffers[i] = NULL; } } - if (IBuffers[i]) + if (m_index_buffers[i]) { - IBuffers[i]->Release(); - IBuffers[i] = NULL; + m_index_buffers[i]->Release(); + m_index_buffers[i] = NULL; } } - if(VBuffers) - delete [] VBuffers; - if(IBuffers) - delete [] IBuffers; - VBuffers = NULL; - IBuffers = NULL; + if(m_vertex_buffers) + delete [] m_vertex_buffers; + if(m_index_buffers) + delete [] m_index_buffers; + m_vertex_buffers = NULL; + m_index_buffers = NULL; } -void VertexManager::PrepareVBuffers(int stride) +void VertexManager::PrepareDrawBuffers(u32 stride) { - if (!NumVBuffers) + if (!m_buffers_count) { return; } @@ -161,31 +161,31 @@ void VertexManager::PrepareVBuffers(int stride) int IndexDataSize = TdataSize + LDataSize + PDataSize; DWORD LockMode = D3DLOCK_NOOVERWRITE; - if (CurrentVBufferIndex > CurrentVBufferSize - datasize) + if (m_vertex_buffer_cursor > m_vertex_buffer_size - datasize) { LockMode = D3DLOCK_DISCARD; - CurrentVBufferIndex = 0; - CurrentVBuffer = (CurrentVBuffer + 1) % NumVBuffers; + m_vertex_buffer_cursor = 0; + m_current_vertex_buffer = (m_current_vertex_buffer + 1) % m_buffers_count; } - if(FAILED(VBuffers[CurrentVBuffer]->Lock(CurrentVBufferIndex, datasize,(VOID**)(&pVertices), LockMode))) + if(FAILED(m_vertex_buffers[m_current_vertex_buffer]->Lock(m_vertex_buffer_cursor, datasize,(VOID**)(&pVertices), LockMode))) { DestroyDeviceObjects(); return; } memcpy(pVertices, LocalVBuffer, datasize); - VBuffers[CurrentVBuffer]->Unlock(); + m_vertex_buffers[m_current_vertex_buffer]->Unlock(); LockMode = D3DLOCK_NOOVERWRITE; - if (CurrentIBufferIndex > CurrentIBufferSize - IndexDataSize) + if (m_index_buffer_cursor > m_index_buffer_size - IndexDataSize) { LockMode = D3DLOCK_DISCARD; - CurrentIBufferIndex = 0; - CurrentIBuffer = (CurrentIBuffer + 1) % NumVBuffers; + m_index_buffer_cursor = 0; + m_current_index_buffer = (m_current_index_buffer + 1) % m_buffers_count; } - if(FAILED(IBuffers[CurrentIBuffer]->Lock(CurrentIBufferIndex * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode ))) + if(FAILED(m_index_buffers[m_current_index_buffer]->Lock(m_index_buffer_cursor * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode ))) { DestroyDeviceObjects(); return; @@ -204,15 +204,15 @@ void VertexManager::PrepareVBuffers(int stride) { memcpy(pIndices, PIBuffer, PDataSize * sizeof(u16)); } - IBuffers[CurrentIBuffer]->Unlock(); - D3D::dev->SetStreamSource( 0, VBuffers[CurrentVBuffer], CurrentVBufferIndex, stride); - if(CurrentIBufferIndex == 0) + m_index_buffers[m_current_index_buffer]->Unlock(); + D3D::dev->SetStreamSource( 0, m_vertex_buffers[m_current_vertex_buffer], m_vertex_buffer_cursor, stride); + if(m_index_buffer_cursor == 0) { - D3D::dev->SetIndices(IBuffers[CurrentIBuffer]); + D3D::dev->SetIndices(m_index_buffers[m_current_index_buffer]); } } -void VertexManager::DrawVB(int stride) +void VertexManager::DrawVertexBuffer(int stride) { if (IndexGenerator::GetNumTriangles() > 0) { @@ -221,7 +221,7 @@ void VertexManager::DrawVB(int stride) 0, 0, IndexGenerator::GetNumVerts(), - CurrentIBufferIndex, + m_index_buffer_cursor, IndexGenerator::GetNumTriangles()))) { DumpBadShaders(); @@ -235,7 +235,7 @@ void VertexManager::DrawVB(int stride) 0, 0, IndexGenerator::GetNumVerts(), - CurrentIBufferIndex + IndexGenerator::GetTriangleindexLen(), + m_index_buffer_cursor + IndexGenerator::GetTriangleindexLen(), IndexGenerator::GetNumLines()))) { DumpBadShaders(); @@ -249,7 +249,7 @@ void VertexManager::DrawVB(int stride) 0, 0, IndexGenerator::GetNumVerts(), - CurrentIBufferIndex + IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen(), + m_index_buffer_cursor + IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen(), IndexGenerator::GetNumPoints()))) { DumpBadShaders(); @@ -259,7 +259,7 @@ void VertexManager::DrawVB(int stride) } -void VertexManager::DrawVA(int stride) +void VertexManager::DrawVertexArray(int stride) { if (IndexGenerator::GetNumTriangles() > 0) { @@ -350,7 +350,7 @@ void VertexManager::vFlush() // set global constants VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); - int stride = g_nativeVertexFmt->GetVertexStride(); + u32 stride = g_nativeVertexFmt->GetVertexStride(); if (!PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components)) { GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");}); @@ -362,9 +362,9 @@ void VertexManager::vFlush() goto shader_fail; } - PrepareVBuffers(stride); + PrepareDrawBuffers(stride); g_nativeVertexFmt->SetupVertexPointers(); - if(NumVBuffers){ DrawVB(stride);} else { DrawVA(stride);} + if(m_buffers_count){ DrawVertexBuffer(stride);} else { DrawVertexArray(stride);} bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; @@ -377,16 +377,16 @@ void VertexManager::vFlush() } // update alpha only g_renderer->ApplyState(true); - if(NumVBuffers){ DrawVB(stride);} else { DrawVA(stride);} + if(m_buffers_count){ DrawVertexBuffer(stride);} else { DrawVertexArray(stride);} g_renderer->RestoreState(); } GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); shader_fail: - if(NumVBuffers) + if(m_buffers_count) { - CurrentIBufferIndex += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen(); - CurrentVBufferIndex += IndexGenerator::GetNumVerts() * stride; + m_index_buffer_cursor += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen(); + m_vertex_buffer_cursor += IndexGenerator::GetNumVerts() * stride; } ResetBuffer(); } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h index aa4e9ed57b..51cf9b953d 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h @@ -34,18 +34,18 @@ public: void CreateDeviceObjects(); void DestroyDeviceObjects(); private: - u32 CurrentVBufferIndex; - u32 CurrentVBufferSize; - u32 CurrentIBufferIndex; - u32 CurrentIBufferSize; - u32 NumVBuffers; - u32 CurrentVBuffer; - u32 CurrentIBuffer; - LPDIRECT3DVERTEXBUFFER9 *VBuffers; - LPDIRECT3DINDEXBUFFER9 *IBuffers; - void PrepareVBuffers(int stride); - void DrawVB(int stride); - void DrawVA(int stride); + u32 m_vertex_buffer_cursor; + u32 m_vertex_buffer_size; + u32 m_index_buffer_cursor; + u32 m_index_buffer_size; + u32 m_buffers_count; + u32 m_current_vertex_buffer; + u32 m_current_index_buffer; + LPDIRECT3DVERTEXBUFFER9 *m_vertex_buffers; + LPDIRECT3DINDEXBUFFER9 *m_index_buffers; + void PrepareDrawBuffers(u32 stride); + void DrawVertexBuffer(int stride); + void DrawVertexArray(int stride); // temp void vFlush(); }; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index ae20649433..3a98332562 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -53,20 +53,6 @@ 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,8 +61,6 @@ NativeVertexFormat* VertexManager::CreateNativeVertexFormat() return new GLVertexFormat(); } -} - GLVertexFormat::GLVertexFormat() { #ifdef USE_JIT @@ -221,6 +205,46 @@ void GLVertexFormat::SetupVertexPointers() { #endif } +void GLVertexFormat::SetupVertexPointersOffset(u32 offset) { + // 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, (GLvoid*)offset); + if (vtx_decl.num_normals >= 1) { + glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (GLvoid*)(offset + 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, (GLvoid*)(offset + 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, (GLvoid*)(offset + vtx_decl.normal_offset[2])); + } + } + + 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, (GLvoid*)(offset + vtx_decl.color_offset[i])); + else { + glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, vtx_decl.stride, (GLvoid*)(offset + 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, (GLvoid*)(offset + vtx_decl.texcoord_offset[i])); + } + } + + if (vtx_decl.posmtx_offset != -1) { + glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (GLvoid*)(offset + vtx_decl.posmtx_offset)); + } +#endif +} + void GLVertexFormat::EnableComponents(u32 components) { if (s_prevcomponents != components) @@ -284,3 +308,7 @@ void GLVertexFormat::EnableComponents(u32 components) s_prevcomponents = components; } } + + +} + diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index 501c4969e5..03927413d8 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -48,38 +48,194 @@ extern NativeVertexFormat *g_nativeVertexFmt; namespace OGL { - -//static GLint max_Index_size = 0; - -//static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0}; -//static int s_nCurVBOIndex = 0; // current free buffer +//This are the initially requeted size for the buffers expresed in bytes +const u32 IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16 * sizeof(u16); +const u32 VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16; +const u32 MAX_VBUFFER_COUNT = 2; VertexManager::VertexManager() { - // TODO: doesn't seem to be used anywhere + CreateDeviceObjects(); +} - //glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*)&max_Index_size); - // - //if (max_Index_size > MAXIBUFFERSIZE) - // max_Index_size = MAXIBUFFERSIZE; - // - //GL_REPORT_ERRORD(); - - glEnableClientState(GL_VERTEX_ARRAY); - GL_REPORT_ERRORD(); +VertexManager::~VertexManager() +{ + DestroyDeviceObjects(); } void VertexManager::CreateDeviceObjects() { - + m_buffers_count = 0; + m_vertex_buffers = NULL; + m_index_buffers = NULL; + glEnableClientState(GL_VERTEX_ARRAY); + GL_REPORT_ERRORD(); + int max_Index_size = 0; + int max_Vertex_size = 0; + glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*)&max_Index_size); + glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*)&max_Vertex_size); + max_Index_size *= sizeof(u16); + GL_REPORT_ERROR(); + m_index_buffer_size = IBUFFER_SIZE; + if (max_Index_size > 0 && max_Index_size < m_index_buffer_size) + m_index_buffer_size = max_Index_size; + + m_vertex_buffer_size = VBUFFER_SIZE; + if (max_Vertex_size > 0 && max_Vertex_size < m_vertex_buffer_size) + m_vertex_buffer_size = max_Vertex_size; + + if (m_index_buffer_size < VertexManager::MAXIBUFFERSIZE || m_vertex_buffer_size < VertexManager::MAXVBUFFERSIZE) + { + return; + } + + m_vertex_buffers = new GLuint[MAX_VBUFFER_COUNT]; + m_index_buffers = new GLuint[MAX_VBUFFER_COUNT]; + + glGenBuffers(MAX_VBUFFER_COUNT, m_vertex_buffers); + GL_REPORT_ERROR(); + glGenBuffers(MAX_VBUFFER_COUNT, m_index_buffers); + GL_REPORT_ERROR(); + for (u32 i = 0; i < MAX_VBUFFER_COUNT; i++) + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffers[i] ); + GL_REPORT_ERROR(); + glBufferData(GL_ARRAY_BUFFER, m_vertex_buffer_size, NULL, GL_STREAM_DRAW ); + GL_REPORT_ERROR(); + } + for (u32 i = 0; i < MAX_VBUFFER_COUNT; i++) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffers[i] ); + GL_REPORT_ERROR(); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer_size, NULL, GL_STREAM_DRAW ); + GL_REPORT_ERROR(); + } + m_buffers_count = MAX_VBUFFER_COUNT; + m_current_index_buffer = 0; + m_current_vertex_buffer = 0; + m_index_buffer_cursor = 0; + m_vertex_buffer_cursor = 0; } void VertexManager::DestroyDeviceObjects() { - + glDisableClientState(GL_VERTEX_ARRAY); + GL_REPORT_ERRORD(); + glBindBuffer(GL_ARRAY_BUFFER, NULL ); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL ); + GL_REPORT_ERROR(); + if(m_vertex_buffers) + { + glDeleteBuffers(MAX_VBUFFER_COUNT, m_vertex_buffers); + GL_REPORT_ERROR(); + delete [] m_vertex_buffers; + } + if(m_index_buffers) + { + glDeleteBuffers(MAX_VBUFFER_COUNT, m_index_buffers); + GL_REPORT_ERROR(); + delete [] m_index_buffers; + } + m_vertex_buffers = NULL; + m_index_buffers = NULL; } -void VertexManager::Draw() +void VertexManager::PrepareDrawBuffers(u32 stride) +{ + if (!m_buffers_count) + { + return; + } + u8* pVertices = NULL; + u16* pIndices = NULL; + int vertex_data_size = IndexGenerator::GetNumVerts() * stride; + int triangle_index_size = IndexGenerator::GetTriangleindexLen() * sizeof(u16); + int line_index_size = IndexGenerator::GetLineindexLen() * sizeof(u16); + int point_index_size = IndexGenerator::GetPointindexLen() * sizeof(u16); + int index_data_size = triangle_index_size + line_index_size + point_index_size; + GLbitfield LockMode = GL_MAP_WRITE_BIT; + if (m_vertex_buffer_cursor > m_vertex_buffer_size - vertex_data_size) + { + LockMode |= GL_MAP_INVALIDATE_BUFFER_BIT; + m_vertex_buffer_cursor = 0; + m_current_vertex_buffer = (m_current_vertex_buffer + 1) % m_buffers_count; + } + else + { + LockMode |= GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT; + } + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffers[m_current_vertex_buffer]); + if(GLEW_ARB_map_buffer_range) + { + pVertices = (u8*)glMapBufferRange(GL_ARRAY_BUFFER, m_vertex_buffer_cursor, vertex_data_size, LockMode); + if(pVertices) + { + memcpy(pVertices, LocalVBuffer, vertex_data_size); + glUnmapBuffer(GL_ARRAY_BUFFER); + } + else + { + glBufferSubData(GL_ARRAY_BUFFER, m_vertex_buffer_cursor, vertex_data_size, LocalVBuffer); + } + } + else + { + glBufferSubData(GL_ARRAY_BUFFER, m_vertex_buffer_cursor, vertex_data_size, LocalVBuffer); + } + + LockMode = GL_MAP_WRITE_BIT; + + if (m_index_buffer_cursor > m_index_buffer_size - index_data_size) + { + LockMode |= GL_MAP_INVALIDATE_BUFFER_BIT; + m_index_buffer_cursor = 0; + m_current_index_buffer = (m_current_index_buffer + 1) % m_buffers_count; + } + else + { + LockMode |= GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT; + } + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffers[m_current_index_buffer]); + if(GLEW_ARB_map_buffer_range) + { + pIndices = (u16*)glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer_cursor , index_data_size, LockMode); + if(pIndices) + { + if(triangle_index_size) + { + memcpy(pIndices, TIBuffer, triangle_index_size); + pIndices += triangle_index_size; + } + if(line_index_size) + { + memcpy(pIndices, LIBuffer, line_index_size); + pIndices += line_index_size; + } + if(point_index_size) + { + memcpy(pIndices, PIBuffer, point_index_size); + } + glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); + } + else + { + if(triangle_index_size) + { + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer_cursor, triangle_index_size, TIBuffer); + } + if(line_index_size) + { + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer_cursor + triangle_index_size, line_index_size, LIBuffer); + } + if(point_index_size) + { + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer_cursor + triangle_index_size + line_index_size, point_index_size, PIBuffer); + } + } + } +} + +void VertexManager::DrawVertexArray() { if (IndexGenerator::GetNumTriangles() > 0) { @@ -98,6 +254,31 @@ void VertexManager::Draw() } } +void VertexManager::DrawVertexBufferObject() +{ + int triangle_index_size = IndexGenerator::GetTriangleindexLen(); + int line_index_size = IndexGenerator::GetLineindexLen(); + int point_index_size = IndexGenerator::GetPointindexLen(); + int StartIndex = m_index_buffer_cursor; + if (triangle_index_size > 0) + { + glDrawElements(GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (GLvoid*)StartIndex); + INCSTAT(stats.thisFrame.numIndexedDrawCalls); + } + if (line_index_size > 0) + { + StartIndex += triangle_index_size * sizeof(u16); + glDrawElements(GL_LINES, line_index_size, GL_UNSIGNED_SHORT, (GLvoid*)StartIndex); + INCSTAT(stats.thisFrame.numIndexedDrawCalls); + } + if (point_index_size > 0) + { + StartIndex += line_index_size * sizeof(u16); + glDrawElements(GL_POINTS, point_index_size, GL_UNSIGNED_SHORT, (GLvoid*)StartIndex); + INCSTAT(stats.thisFrame.numIndexedDrawCalls); + } +} + void VertexManager::vFlush() { if (LocalVBuffer == s_pCurBufferPointer) return; @@ -134,13 +315,17 @@ void VertexManager::vFlush() (void)GL_REPORT_ERROR(); - //glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[s_nCurVBOIndex]); - //glBufferData(GL_ARRAY_BUFFER, s_pCurBufferPointer - LocalVBuffer, LocalVBuffer, GL_STREAM_DRAW); - GL_REPORT_ERRORD(); + u32 stride = g_nativeVertexFmt->GetVertexStride(); - // setup the pointers - if (g_nativeVertexFmt) + PrepareDrawBuffers(stride); + if(m_buffers_count) + { + ((GLVertexFormat*)g_nativeVertexFmt)->SetupVertexPointersOffset(m_vertex_buffer_cursor); + } + else + { g_nativeVertexFmt->SetupVertexPointers(); + } GL_REPORT_ERRORD(); u32 usedtextures = 0; @@ -153,7 +338,7 @@ void VertexManager::vFlush() if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt); - for (int i = 0; i < 8; i++) + for (u32 i = 0; i < 8; i++) { if (usedtextures & (1 << i)) { @@ -217,7 +402,7 @@ void VertexManager::vFlush() if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here. if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid); - Draw(); + if(m_buffers_count) { DrawVertexBufferObject(); }else{ DrawVertexArray();}; // run through vertex groups again to set alpha if (useDstAlpha && !dualSourcePossible) @@ -230,7 +415,7 @@ void VertexManager::vFlush() glDisable(GL_BLEND); - Draw(); + if(m_buffers_count) { DrawVertexBufferObject(); }else{ DrawVertexArray();}; // restore color mask g_renderer->SetColorMask(); @@ -238,11 +423,12 @@ void VertexManager::vFlush() glEnable(GL_BLEND); } GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); - - //s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers); - s_pCurBufferPointer = LocalVBuffer; - IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer); - + if(m_buffers_count) + { + m_index_buffer_cursor += (IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen()) * sizeof(u16); + m_vertex_buffer_cursor += IndexGenerator::GetNumVerts() * stride; + } + ResetBuffer(); #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h index 5cec1bf97e..ac45151999 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h @@ -24,6 +24,20 @@ namespace OGL { + 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 SetupVertexPointersOffset(u32 offset); + virtual void EnableComponents(u32 components); + }; // Handles the OpenGL details of drawing lots of vertices quickly. // Other functionality is moving out. @@ -31,14 +45,24 @@ class VertexManager : public ::VertexManager { public: VertexManager(); - + ~VertexManager(); NativeVertexFormat* CreateNativeVertexFormat(); void CreateDeviceObjects(); void DestroyDeviceObjects(); private: - void Draw(); - // temp + void DrawVertexArray(); + void DrawVertexBufferObject(); void vFlush(); + void PrepareDrawBuffers(u32 stride); + u32 m_vertex_buffer_cursor; + u32 m_vertex_buffer_size; + u32 m_index_buffer_cursor; + u32 m_index_buffer_size; + u32 m_buffers_count; + u32 m_current_vertex_buffer; + u32 m_current_index_buffer; + GLuint* m_vertex_buffers; + GLuint* m_index_buffers; }; }