diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp index 57346b2632..67403b3084 100644 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ b/src/gl/dynlights/gl_shadowmap.cpp @@ -54,9 +54,9 @@ void FShadowMap::Update() GLRenderer->mShadowMapShader->Bind(NOQUEUE); GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; GLRenderer->mShadowMapShader->Uniforms.Set(); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, mLightList); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, mNodesBuffer); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mLinesBuffer); + mLightList->BindBase(); + mNodesBuffer->BindBase(); + mLinesBuffer->BindBase(); glViewport(0, 0, gl_shadowmap_quality, 1024); GLRenderer->RenderScreenQuad(); @@ -64,10 +64,6 @@ void FShadowMap::Update() const auto &viewport = screen->mScreenViewport; glViewport(viewport.left, viewport.top, viewport.width, viewport.height); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, 0); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, 0); - GLRenderer->mBuffers->BindShadowMapTexture(16); FGLDebug::PopGroup(); @@ -75,56 +71,34 @@ void FShadowMap::Update() UpdateCycles.Unclock(); } + void FShadowMap::UploadLights() { CollectLights(); - if (mLightList == 0) - glGenBuffers(1, (GLuint*)&mLightList); + if (mLightList == nullptr) + mLightList = screen->CreateDataBuffer(4, true); - int oldBinding = 0; - glGetIntegerv(GL_SHADER_STORAGE_BUFFER_BINDING, &oldBinding); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, mLightList); - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * mLights.Size(), &mLights[0], GL_STATIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, oldBinding); + mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]); } + void FShadowMap::UploadAABBTree() { if (!ValidateAABBTree()) { - int oldBinding = 0; - glGetIntegerv(GL_SHADER_STORAGE_BUFFER_BINDING, &oldBinding); + mNodesBuffer = screen->CreateDataBuffer(2, true); + mNodesBuffer->SetData(sizeof(hwrenderer::AABBTreeNode) * mAABBTree->nodes.Size(), &mAABBTree->nodes[0]); - glGenBuffers(1, (GLuint*)&mNodesBuffer); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, mNodesBuffer); - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(hwrenderer::AABBTreeNode) * mAABBTree->nodes.Size(), &mAABBTree->nodes[0], GL_STATIC_DRAW); - - glGenBuffers(1, (GLuint*)&mLinesBuffer); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, mLinesBuffer); - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(hwrenderer::AABBTreeLine) * mAABBTree->lines.Size(), &mAABBTree->lines[0], GL_STATIC_DRAW); - - glBindBuffer(GL_SHADER_STORAGE_BUFFER, oldBinding); + mLinesBuffer = screen->CreateDataBuffer(3, true); + mLinesBuffer->SetData(sizeof(hwrenderer::AABBTreeLine) * mAABBTree->lines.Size(), &mAABBTree->lines[0]); } } void FShadowMap::Clear() { - if (mLightList != 0) - { - glDeleteBuffers(1, (GLuint*)&mLightList); - mLightList = 0; - } - - if (mNodesBuffer != 0) - { - glDeleteBuffers(1, (GLuint*)&mNodesBuffer); - mNodesBuffer = 0; - } - - if (mLinesBuffer != 0) - { - glDeleteBuffers(1, (GLuint*)&mLinesBuffer); - mLinesBuffer = 0; - } + if (mLightList) delete mLightList; + if (mNodesBuffer) delete mNodesBuffer; + if (mLinesBuffer) delete mLinesBuffer; } + diff --git a/src/gl/dynlights/gl_shadowmap.h b/src/gl/dynlights/gl_shadowmap.h index ee43abef82..e415bf23d7 100644 --- a/src/gl/dynlights/gl_shadowmap.h +++ b/src/gl/dynlights/gl_shadowmap.h @@ -3,6 +3,8 @@ #include "hwrenderer/dynlights/hw_shadowmap.h" +class IDataBuffer; + class FShadowMap : public IShadowMap { public: @@ -22,9 +24,9 @@ private: void UploadLights(); // OpenGL storage buffer with the list of lights in the shadow map texture - int mLightList = 0; + IDataBuffer *mLightList = nullptr; // OpenGL storage buffers for the AABB tree - int mNodesBuffer = 0; - int mLinesBuffer = 0; + IDataBuffer *mNodesBuffer = nullptr; + IDataBuffer *mLinesBuffer = nullptr; };