Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 826 vs 827 for /trunk/Source Code/Platform/Video/OpenGL/Buffers/ShaderBuffer/glUniformBuffer.cpp

Diff revisions: vs.
  @@ -1,6 +1,7 @@
1 1 #include "Headers/glUniformBuffer.h"
2 2
3 3 #include "Platform/Video/Headers/GFXDevice.h"
4 + #include "Platform/Video/OpenGL/Headers/GLWrapper.h"
4 5 #include "Platform/Video/OpenGL/Headers/glResources.h"
5 6 #include "Platform/Video/Shaders/Headers/ShaderProgram.h"
6 7 #include "Platform/Video/OpenGL/Buffers/Headers/glBufferImpl.h"
  @@ -34,19 +35,24 @@
34 35 class AtomicCounter : public RingBuffer
35 36 {
36 37 public:
37 - AtomicCounter(U32 sizeFactor, bool persistenMapped, const char* name);
38 + AtomicCounter(U32 sizeFactor, const char* name);
38 39 ~AtomicCounter();
39 40 glGenericBuffer* _buffer;
40 41 };
41 42
42 - AtomicCounter::AtomicCounter(U32 sizeFactor, bool persistenMapped, const char* name)
43 + AtomicCounter::AtomicCounter(U32 sizeFactor, const char* name)
43 44 : RingBuffer(sizeFactor)
44 45 {
45 - _buffer = MemoryManager_NEW glGenericBuffer(GL_ATOMIC_COUNTER_BUFFER,
46 - persistenMapped,
47 - sizeFactor);
46 + BufferParams params;
47 + params._usage = GL_ATOMIC_COUNTER_BUFFER;
48 + params._elementCount = 1;
49 + params._elementSizeInBytes = sizeof(GLuint);
50 + params._frequency = BufferUpdateFrequency::ONCE;
51 + params._name = name;
52 + params._ringSizeFactor = sizeFactor;
53 + params._data = NULL;
48 54
49 - _buffer->create(1, sizeof(GLuint), BufferUpdateFrequency::ONCE, NULL, name);
55 + _buffer = MemoryManager_NEW glGenericBuffer(params);
50 56 }
51 57
52 58 AtomicCounter::~AtomicCounter()
  @@ -56,27 +62,22 @@
56 62
57 63 IMPLEMENT_CUSTOM_ALLOCATOR(glUniformBuffer, 0, 0)
58 64 glUniformBuffer::glUniformBuffer(GFXDevice& context,
59 - const U32 ringBufferLength,
60 - bool unbound,
61 - bool persistentMapped,
62 - BufferUpdateFrequency frequency)
63 - : ShaderBuffer(context, ringBufferLength, unbound, persistentMapped, frequency),
64 - _alignment(0),
65 - _allignedBufferSize(0),
66 - _target(_unbound ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER)
65 + const ShaderBufferParams& params)
66 + : ShaderBuffer(context, params)
67 67 {
68 - _updated = false;
69 - _alignmentRequirement = _unbound ? ParamHandler::instance().getParam<I32>(_ID("rendering.SSBOAligment"), 32)
70 - : ParamHandler::instance().getParam<I32>(_ID("rendering.UBOAligment"), 32);
71 -
72 - _maxSize = _unbound ? ParamHandler::instance().getParam<I32>(_ID("rendering.SSBOMaxSize"), 2 * 1024 * 1024)
73 - : ParamHandler::instance().getParam<I32>(_ID("rendering.UBOMaxSize"), 64 * 1024);
74 -
75 - if (persistentMapped) {
76 - _buffer = MemoryManager_NEW glPersistentBuffer(_target);
77 - } else {
78 - _buffer = MemoryManager_NEW glRegularBuffer(_target);
79 - }
68 + _maxSize = _unbound ? GL_API::s_SSBMaxSize : GL_API::s_UBMaxSize;
69 +
70 + _allignedBufferSize = realign_offset(_bufferSize, alignmentRequirement(_unbound));
71 +
72 + assert(_allignedBufferSize < _maxSize);
73 +
74 + BufferImplParams implParams;
75 + implParams._dataSizeInBytes = _allignedBufferSize * queueLength();
76 + implParams._frequency = _frequency;
77 + implParams._initialData = params._initialData;
78 + implParams._target = _unbound ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER;
79 +
80 + _buffer = MemoryManager_NEW glBufferImpl(implParams);
80 81 }
81 82
82 83 glUniformBuffer::~glUniformBuffer()
  @@ -89,12 +90,6 @@
89 90 return _buffer->bufferID();
90 91 }
91 92
92 - void glUniformBuffer::create(U32 primitiveCount, ptrdiff_t primitiveSize, U32 sizeFactor) {
93 - ShaderBuffer::create(primitiveCount, primitiveSize, sizeFactor);
94 - _allignedBufferSize = realign_offset(_bufferSize, _alignmentRequirement);
95 - _buffer->create(_frequency, _allignedBufferSize * sizeFactor * queueLength());
96 - }
97 -
98 93 void glUniformBuffer::getData(ptrdiff_t offsetElementCount,
99 94 ptrdiff_t rangeElementCount,
100 95 bufferPtr result) const {
  @@ -155,7 +150,7 @@
155 150
156 151 void glUniformBuffer::addAtomicCounter(U32 sizeFactor) {
157 152 const char* name = Util::StringFormat("DVD_ATOMIC_BUFFER_%d_%d", getGUID(), _atomicCounters.size()).c_str();
158 - _atomicCounters.emplace_back(MemoryManager_NEW AtomicCounter(std::max(sizeFactor, 1u), true || _persistentMapped, name));
153 + _atomicCounters.emplace_back(MemoryManager_NEW AtomicCounter(std::max(sizeFactor, 1u), name));
159 154 }
160 155
161 156 U32 glUniformBuffer::getAtomicCounter(U32 counterIndex) {
  @@ -284,4 +279,9 @@
284 279 }
285 280 }
286 281
282 + void glUniformBuffer::onGLInit() {
283 + ShaderBuffer::_boundAlignmentRequirement = GL_API::s_UBOffsetAlignment;
284 + ShaderBuffer::_unboundAlignmentRequirement = GL_API::s_SSBOffsetAlignment;
285 + }
286 +
287 287 }; // namespace Divide