From 27d9440751e7952e288cc83d505d0dfd64b63236 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 15 Apr 2018 19:34:56 +0200 Subject: [PATCH] don't create buffers, if OpenGL 3.3 is not used --- src/engine/client/graphics_threaded.cpp | 175 ++++++++++-------------- src/engine/client/graphics_threaded.h | 1 + src/engine/graphics.h | 1 + 3 files changed, 73 insertions(+), 104 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 84de1f091..88d42d70b 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1209,6 +1209,60 @@ int CGraphics_Threaded::CreateQuadContainer() return Index; } +void CGraphics_Threaded::QuadContainerUpload(int ContainerIndex) +{ + if(m_UseOpenGL3_3) + { + SQuadContainer& Container = m_QuadContainers[ContainerIndex]; + if(Container.m_Quads.size() > 0) + { + if(Container.m_QuadBufferObjectIndex == -1) + { + size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); + Container.m_QuadBufferObjectIndex = CreateBufferObject(UploadDataSize, &Container.m_Quads[0]); + } + else + { + size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); + RecreateBufferObject(Container.m_QuadBufferObjectIndex, UploadDataSize, &Container.m_Quads[0]); + } + + if(Container.m_QuadBufferContainerIndex == -1) + { + SBufferContainerInfo Info; + Info.m_Stride = sizeof(CCommandBuffer::SVertex); + + Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); + SBufferContainerInfo::SAttribute* pAttr = &Info.m_Attributes.back(); + pAttr->m_DataTypeCount = 2; + pAttr->m_FuncType = 0; + pAttr->m_Normalized = false; + pAttr->m_pOffset = 0; + pAttr->m_Type = GRAPHICS_TYPE_FLOAT; + pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; + Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); + pAttr = &Info.m_Attributes.back(); + pAttr->m_DataTypeCount = 2; + pAttr->m_FuncType = 0; + pAttr->m_Normalized = false; + pAttr->m_pOffset = (void*)(sizeof(float) * 2); + pAttr->m_Type = GRAPHICS_TYPE_FLOAT; + pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; + Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); + pAttr = &Info.m_Attributes.back(); + pAttr->m_DataTypeCount = 4; + pAttr->m_FuncType = 0; + pAttr->m_Normalized = true; + pAttr->m_pOffset = (void*)(sizeof(float) * 2 + sizeof(float) * 2); + pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE; + pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; + + Container.m_QuadBufferContainerIndex = CreateBufferContainer(&Info); + } + } + } +} + void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CQuadItem *pArray, int Num) { SQuadContainer& Container = m_QuadContainers[ContainerIndex]; @@ -1251,52 +1305,7 @@ void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CQuadItem *pA } } - if(Container.m_Quads.size() > 0) - { - if(Container.m_QuadBufferObjectIndex == -1) - { - size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); - Container.m_QuadBufferObjectIndex = CreateBufferObject(UploadDataSize, &Container.m_Quads[0]); - } - else - { - size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); - RecreateBufferObject(Container.m_QuadBufferObjectIndex, UploadDataSize, &Container.m_Quads[0]); - } - - if(Container.m_QuadBufferContainerIndex == -1) - { - SBufferContainerInfo Info; - Info.m_Stride = sizeof(CCommandBuffer::SVertex); - - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - SBufferContainerInfo::SAttribute* pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 2; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = false; - pAttr->m_pOffset = 0; - pAttr->m_Type = GRAPHICS_TYPE_FLOAT; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 2; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = false; - pAttr->m_pOffset = (void*)(sizeof(float) * 2); - pAttr->m_Type = GRAPHICS_TYPE_FLOAT; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 4; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = true; - pAttr->m_pOffset = (void*)(sizeof(float) * 2 + sizeof(float) * 2); - pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - - Container.m_QuadBufferContainerIndex = CreateBufferContainer(&Info); - } - } + QuadContainerUpload(ContainerIndex); } void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CFreeformItem *pArray, int Num) @@ -1332,59 +1341,17 @@ void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CFreeformItem SetColor(&Quad.m_aVertices[3], 2); } - if(Container.m_Quads.size() > 0) - { - if(Container.m_QuadBufferObjectIndex == -1) - { - size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); - Container.m_QuadBufferObjectIndex = CreateBufferObject(UploadDataSize, &Container.m_Quads[0]); - } - else - { - size_t UploadDataSize = Container.m_Quads.size() * sizeof(SQuadContainer::SQuad); - RecreateBufferObject(Container.m_QuadBufferObjectIndex, UploadDataSize, &Container.m_Quads[0]); - } - - if(Container.m_QuadBufferContainerIndex == -1) - { - SBufferContainerInfo Info; - Info.m_Stride = sizeof(CCommandBuffer::SVertex); - - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - SBufferContainerInfo::SAttribute* pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 2; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = false; - pAttr->m_pOffset = 0; - pAttr->m_Type = GRAPHICS_TYPE_FLOAT; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 2; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = false; - pAttr->m_pOffset = (void*)(sizeof(float) * 2); - pAttr->m_Type = GRAPHICS_TYPE_FLOAT; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - Info.m_Attributes.push_back(SBufferContainerInfo::SAttribute()); - pAttr = &Info.m_Attributes.back(); - pAttr->m_DataTypeCount = 4; - pAttr->m_FuncType = 0; - pAttr->m_Normalized = true; - pAttr->m_pOffset = (void*)(sizeof(float) * 2 + sizeof(float) * 2); - pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE; - pAttr->m_VertBufferBindingIndex = Container.m_QuadBufferObjectIndex; - - Container.m_QuadBufferContainerIndex = CreateBufferContainer(&Info); - } - } + QuadContainerUpload(ContainerIndex); } void CGraphics_Threaded::QuadContainerReset(int ContainerIndex) { SQuadContainer& Container = m_QuadContainers[ContainerIndex]; - if(Container.m_QuadBufferContainerIndex != -1) - DeleteBufferContainer(Container.m_QuadBufferContainerIndex, true); + if(m_UseOpenGL3_3) + { + if(Container.m_QuadBufferContainerIndex != -1) + DeleteBufferContainer(Container.m_QuadBufferContainerIndex, true); + } Container.m_Quads.clear(); Container.m_QuadBufferContainerIndex = Container.m_QuadBufferObjectIndex = -1; } @@ -1412,12 +1379,12 @@ void CGraphics_Threaded::RenderQuadContainer(int ContainerIndex, int QuadOffset, if((int)Container.m_Quads.size() < QuadOffset + QuadDrawNum || QuadDrawNum == 0) return; - - if(Container.m_QuadBufferContainerIndex == -1) - return; - + if(m_UseOpenGL3_3) { + if(Container.m_QuadBufferContainerIndex == -1) + return; + CCommandBuffer::SCommand_RenderQuadContainer Cmd; Cmd.m_State = m_State; Cmd.m_DrawNum = (unsigned int)QuadDrawNum * 6; @@ -1471,11 +1438,11 @@ void CGraphics_Threaded::RenderQuadContainerAsSprite(int ContainerIndex, int Qua if((int)Container.m_Quads.size() < QuadOffset + 1) return; - if(Container.m_QuadBufferContainerIndex == -1) - return; - if(m_UseOpenGL3_3) { + if(Container.m_QuadBufferContainerIndex == -1) + return; + SQuadContainer::SQuad& Quad = Container.m_Quads[QuadOffset]; CCommandBuffer::SCommand_RenderQuadContainerAsSprite Cmd; @@ -1597,11 +1564,11 @@ void CGraphics_Threaded::RenderQuadContainerAsSpriteMultiple(int ContainerIndex, if(DrawCount == 0) return; - if(Container.m_QuadBufferContainerIndex == -1) - return; - if(m_UseOpenGL3_3) { + if(Container.m_QuadBufferContainerIndex == -1) + return; + SQuadContainer::SQuad& Quad = Container.m_Quads[0]; CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple Cmd; diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index ee36487d6..b2b4fe784 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -756,6 +756,7 @@ public: virtual void QuadsText(float x, float y, float Size, const char *pText); virtual int CreateQuadContainer(); + virtual void QuadContainerUpload(int ContainerIndex); virtual void QuadContainerAddQuads(int ContainerIndex, CQuadItem *pArray, int Num); virtual void QuadContainerAddQuads(int ContainerIndex, CFreeformItem *pArray, int Num); virtual void QuadContainerReset(int ContainerIndex); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 6c7a63ccb..3209de364 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -209,6 +209,7 @@ public: }; virtual int CreateQuadContainer() = 0; + virtual void QuadContainerUpload(int ContainerIndex) = 0; virtual void QuadContainerAddQuads(int ContainerIndex, CQuadItem *pArray, int Num) = 0; virtual void QuadContainerAddQuads(int ContainerIndex, CFreeformItem *pArray, int Num) = 0; virtual void QuadContainerReset(int ContainerIndex) = 0;