mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-26 18:13:47 +00:00
ogl device buffer creation
now ogl mirrors dx side with ubo creation and clearing pushed up to the device level.
This commit is contained in:
parent
1e8841e6b5
commit
11d8604d8e
5 changed files with 52 additions and 17 deletions
|
|
@ -155,6 +155,14 @@ GFXD3D11ShaderConstBuffer::~GFXD3D11ShaderConstBuffer()
|
|||
}
|
||||
mBufferMap.clear(); // Clear the map
|
||||
|
||||
for (U32 i = 0; i < 6; i++)
|
||||
{
|
||||
for (U32 j = 0; j < 16; j++)
|
||||
{
|
||||
mBoundBuffers[i][j] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (mShader)
|
||||
mShader->_unlinkBuffer(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,6 +292,11 @@ GFXGLDevice::~GFXGLDevice()
|
|||
mTextureManager->kill();
|
||||
}
|
||||
|
||||
// Free device buffers
|
||||
DeviceBufferMap::Iterator bufferIter = mDeviceBufferMap.begin();
|
||||
for (; bufferIter != mDeviceBufferMap.end(); ++bufferIter)
|
||||
glDeleteBuffers(1, &bufferIter->value);
|
||||
|
||||
GFXResource* walk = mResourceListHead;
|
||||
while(walk)
|
||||
{
|
||||
|
|
@ -307,6 +312,23 @@ GFXGLDevice::~GFXGLDevice()
|
|||
SAFE_DELETE( mOpenglStateCache );
|
||||
}
|
||||
|
||||
GLuint GFXGLDevice::getDeviceBuffer(const GFXShaderConstDesc desc)
|
||||
{
|
||||
String name(desc.name + "_" + String::ToString(desc.size));
|
||||
DeviceBufferMap::Iterator buf = mDeviceBufferMap.find(name);
|
||||
if (buf != mDeviceBufferMap.end())
|
||||
{
|
||||
return mDeviceBufferMap[name];
|
||||
}
|
||||
|
||||
GLuint uboHandle;
|
||||
glGenBuffers(1, &uboHandle);
|
||||
|
||||
mDeviceBufferMap[name] = uboHandle;
|
||||
|
||||
return uboHandle;
|
||||
}
|
||||
|
||||
void GFXGLDevice::zombify()
|
||||
{
|
||||
mTextureManager->zombify();
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class GFXGLShaderConstBuffer;
|
|||
|
||||
class GFXGLDevice : public GFXDevice
|
||||
{
|
||||
|
||||
public:
|
||||
struct GLCapabilities
|
||||
{
|
||||
|
|
@ -60,6 +61,11 @@ public:
|
|||
};
|
||||
GLCapabilities mCapabilities;
|
||||
|
||||
// UBO map
|
||||
typedef Map<String, GLuint> DeviceBufferMap;
|
||||
// grab device buffer.
|
||||
GLuint getDeviceBuffer(const GFXShaderConstDesc desc);
|
||||
|
||||
void zombify();
|
||||
void resurrect();
|
||||
GFXGLDevice(U32 adapterIndex);
|
||||
|
|
@ -202,6 +208,8 @@ protected:
|
|||
virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer );
|
||||
virtual void setVertexStreamFrequency( U32 stream, U32 frequency );
|
||||
StrongRefPtr<GFXGLShaderConstBuffer> mCurrentConstBuffer;
|
||||
DeviceBufferMap mDeviceBufferMap;
|
||||
|
||||
private:
|
||||
typedef GFXDevice Parent;
|
||||
|
||||
|
|
|
|||
|
|
@ -434,30 +434,27 @@ void GFXGLShaderConstBuffer::activate(GFXGLShaderConstBuffer* prevShaderBuffer)
|
|||
mWasLost = false;
|
||||
}
|
||||
|
||||
void GFXGLShaderConstBuffer::addBuffer(S32 bufBindingPoint, U32 size)
|
||||
void GFXGLShaderConstBuffer::addBuffer(const GFXShaderConstDesc desc)
|
||||
{
|
||||
// if this is the global buffer set it to the highest.
|
||||
if (bufBindingPoint == -1)
|
||||
if (desc.bindPoint == -1)
|
||||
{
|
||||
// we dont create a bufferhandle for this one.
|
||||
U8* buf = new U8[size];
|
||||
dMemset(buf, 0, size);
|
||||
U8* buf = new U8[desc.size];
|
||||
dMemset(buf, 0, desc.size);
|
||||
mBufferMap[-1].data = buf;
|
||||
mBufferMap[-1].size = size;
|
||||
mBufferMap[-1].size = desc.size;
|
||||
mBufferMap[-1].isDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
U8* buf = new U8[size];
|
||||
dMemset(buf, 0, size);
|
||||
mBufferMap[bufBindingPoint].data = buf;
|
||||
mBufferMap[bufBindingPoint].size = size;
|
||||
mBufferMap[bufBindingPoint].isDirty = true;
|
||||
U8* buf = new U8[desc.size];
|
||||
dMemset(buf, 0, desc.size);
|
||||
mBufferMap[desc.bindPoint].data = buf;
|
||||
mBufferMap[desc.bindPoint].size = desc.size;
|
||||
mBufferMap[desc.bindPoint].isDirty = true;
|
||||
|
||||
GLuint uboHandle;
|
||||
glGenBuffers(1, &uboHandle);
|
||||
|
||||
mBufferMap[bufBindingPoint].bufHandle = uboHandle;
|
||||
mBufferMap[desc.bindPoint].bufHandle = GFXGL->getDeviceBuffer(desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -478,7 +475,7 @@ void GFXGLShaderConstBuffer::onShaderReload(GFXGLShader* shader)
|
|||
for (GFXGLShader::BufferMap::Iterator i = shader->mBuffers.begin(); i != shader->mBuffers.end(); ++i)
|
||||
{
|
||||
// add our buffer descriptions to the full const buffer.
|
||||
this->addBuffer(i->value.bindPoint, i->value.size);
|
||||
this->addBuffer(i->value);
|
||||
}
|
||||
|
||||
mWasLost = true;
|
||||
|
|
@ -1161,7 +1158,7 @@ GFXShaderConstBufferRef GFXGLShader::allocConstBuffer()
|
|||
for (BufferMap::Iterator i = mBuffers.begin(); i != mBuffers.end(); ++i)
|
||||
{
|
||||
// add our buffer descriptions to the full const buffer.
|
||||
buffer->addBuffer(i->value.bindPoint, i->value.size);
|
||||
buffer->addBuffer(i->value);
|
||||
}
|
||||
|
||||
buffer->registerResourceWithDevice(getOwningDevice());
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public:
|
|||
/// Called by GFXGLDevice to activate this buffer.
|
||||
void activate(GFXGLShaderConstBuffer* prevShaderBuffer);
|
||||
|
||||
void addBuffer(S32 bufBindingPoint, U32 size);
|
||||
void addBuffer(const GFXShaderConstDesc desc);
|
||||
|
||||
/// Called when the shader this buffer references is reloaded.
|
||||
void onShaderReload(GFXGLShader* shader);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue