mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
PR feedback
This commit is contained in:
parent
eb84459f03
commit
9509e32928
8 changed files with 129 additions and 175 deletions
|
@ -267,7 +267,7 @@ void RenderableParticleEffectEntityItem::updateRenderItem() {
|
||||||
if (numBytes == 0) {
|
if (numBytes == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(particleBuffer->editData(), particlePrimitives->data(), numBytes);
|
particleBuffer->setData(numBytes, (const gpu::Byte*)particlePrimitives->data());
|
||||||
|
|
||||||
// Update transform and bounds
|
// Update transform and bounds
|
||||||
payload.setModelTransform(transform);
|
payload.setModelTransform(transform);
|
||||||
|
|
|
@ -69,10 +69,10 @@ public:
|
||||||
const GLuint _size;
|
const GLuint _size;
|
||||||
const Stamp _stamp;
|
const Stamp _stamp;
|
||||||
|
|
||||||
GLBuffer(const Buffer& buffer);
|
GLBuffer(const Buffer& buffer, GLBuffer* original = nullptr);
|
||||||
~GLBuffer();
|
~GLBuffer();
|
||||||
|
|
||||||
void transfer(bool forceAll = false);
|
void transfer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getNextTransferBlock(GLintptr& outOffset, GLsizeiptr& outSize, size_t& currentPage) const;
|
bool getNextTransferBlock(GLintptr& outOffset, GLsizeiptr& outSize, size_t& currentPage) const;
|
||||||
|
|
|
@ -12,43 +12,42 @@
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
static std::once_flag check_dsa;
|
|
||||||
static bool DSA_SUPPORTED { false };
|
|
||||||
|
|
||||||
GLuint allocateSingleBuffer() {
|
GLuint allocateSingleBuffer() {
|
||||||
std::call_once(check_dsa, [&] {
|
|
||||||
DSA_SUPPORTED = (GLEW_VERSION_4_5 || GLEW_ARB_direct_state_access);
|
|
||||||
});
|
|
||||||
GLuint result;
|
GLuint result;
|
||||||
if (DSA_SUPPORTED) {
|
glGenBuffers(1, &result);
|
||||||
glCreateBuffers(1, &result);
|
(void)CHECK_GL_ERROR();
|
||||||
} else {
|
|
||||||
glGenBuffers(1, &result);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLBackend::GLBuffer::GLBuffer(const Buffer& buffer) :
|
GLBackend::GLBuffer::GLBuffer(const Buffer& buffer, GLBuffer* original) :
|
||||||
_buffer(allocateSingleBuffer()),
|
_buffer(allocateSingleBuffer()),
|
||||||
_size(buffer._sysmem.getSize()),
|
_size((GLuint)buffer._sysmem.getSize()),
|
||||||
_stamp(buffer._sysmem.getStamp()),
|
_stamp(buffer._sysmem.getStamp()),
|
||||||
_gpuBuffer(buffer) {
|
_gpuBuffer(buffer) {
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
Backend::setGPUObject(buffer, this);
|
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
||||||
if (DSA_SUPPORTED) {
|
if (GLEW_VERSION_4_4 || GLEW_ARB_buffer_storage) {
|
||||||
glNamedBufferStorage(_buffer, _size, nullptr, GL_DYNAMIC_STORAGE_BIT);
|
glBufferStorage(GL_ARRAY_BUFFER, _size, nullptr, GL_DYNAMIC_STORAGE_BIT);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
} else {
|
} else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
glBufferData(GL_ARRAY_BUFFER, _size, nullptr, GL_DYNAMIC_DRAW);
|
||||||
if (GLEW_VERSION_4_4 || GLEW_ARB_buffer_storage) {
|
(void)CHECK_GL_ERROR();
|
||||||
glBufferStorage(GL_ARRAY_BUFFER, _size, nullptr, GL_DYNAMIC_STORAGE_BIT);
|
|
||||||
} else {
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, buffer.getSysmem().getSize(), buffer.getSysmem().readData(), GL_DYNAMIC_DRAW);
|
|
||||||
}
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
if (original) {
|
||||||
|
glBindBuffer(GL_COPY_WRITE_BUFFER, _buffer);
|
||||||
|
glBindBuffer(GL_COPY_READ_BUFFER, original->_buffer);
|
||||||
|
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, original->_size);
|
||||||
|
glBindBuffer(GL_COPY_WRITE_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_COPY_READ_BUFFER, 0);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
Backend::setGPUObject(buffer, this);
|
||||||
Backend::incrementBufferGPUCount();
|
Backend::incrementBufferGPUCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLBackend::GLBuffer::~GLBuffer() {
|
GLBackend::GLBuffer::~GLBuffer() {
|
||||||
if (_buffer != 0) {
|
if (_buffer != 0) {
|
||||||
glDeleteBuffers(1, &_buffer);
|
glDeleteBuffers(1, &_buffer);
|
||||||
|
@ -57,62 +56,20 @@ GLBackend::GLBuffer::~GLBuffer() {
|
||||||
Backend::decrementBufferGPUCount();
|
Backend::decrementBufferGPUCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::GLBuffer::transfer(bool forceAll) {
|
void GLBackend::GLBuffer::transfer() {
|
||||||
const auto& pageFlags = _gpuBuffer._pages;
|
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
||||||
if (!forceAll) {
|
|
||||||
size_t transitions = 0;
|
|
||||||
if (pageFlags.size()) {
|
|
||||||
bool lastDirty = (0 != (pageFlags[0] & Buffer::DIRTY));
|
|
||||||
for (size_t i = 1; i < pageFlags.size(); ++i) {
|
|
||||||
bool newDirty = (0 != (pageFlags[0] & Buffer::DIRTY));
|
|
||||||
if (newDirty != lastDirty) {
|
|
||||||
++transitions;
|
|
||||||
lastDirty = newDirty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no transitions (implying the whole buffer is dirty)
|
|
||||||
// or more than 20 transitions, then just transfer the whole buffer
|
|
||||||
if (transitions == 0 || transitions > 20) {
|
|
||||||
forceAll = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Are we transferring the whole buffer?
|
|
||||||
if (forceAll) {
|
|
||||||
if (DSA_SUPPORTED) {
|
|
||||||
glNamedBufferSubData(_buffer, 0, _size, _gpuBuffer.getSysmem().readData());
|
|
||||||
} else {
|
|
||||||
// Now let's update the content of the bo with the sysmem version
|
|
||||||
// TODO: in the future, be smarter about when to actually upload the glBO version based on the data that did change
|
|
||||||
//if () {
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, _gpuBuffer.getSysmem().getSize(), _gpuBuffer.getSysmem().readData(), GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!DSA_SUPPORTED) {
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
|
||||||
}
|
|
||||||
GLintptr offset;
|
|
||||||
GLsizeiptr size;
|
|
||||||
size_t currentPage { 0 };
|
|
||||||
auto data = _gpuBuffer.getSysmem().readData();
|
|
||||||
while (getNextTransferBlock(offset, size, currentPage)) {
|
|
||||||
if (DSA_SUPPORTED) {
|
|
||||||
glNamedBufferSubData(_buffer, offset, size, data + offset);
|
|
||||||
} else {
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, offset, size, data + offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DSA_SUPPORTED) {
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_gpuBuffer._flags &= ~Buffer::DIRTY;
|
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
|
GLintptr offset;
|
||||||
|
GLsizeiptr size;
|
||||||
|
size_t currentPage { 0 };
|
||||||
|
auto data = _gpuBuffer.getSysmem().readData();
|
||||||
|
while (getNextTransferBlock(offset, size, currentPage)) {
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, offset, size, data + offset);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
_gpuBuffer._flags &= ~Buffer::DIRTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLBackend::GLBuffer::getNextTransferBlock(GLintptr& outOffset, GLsizeiptr& outSize, size_t& currentPage) const {
|
bool GLBackend::GLBuffer::getNextTransferBlock(GLintptr& outOffset, GLsizeiptr& outSize, size_t& currentPage) const {
|
||||||
|
@ -130,6 +87,7 @@ bool GLBackend::GLBuffer::getNextTransferBlock(GLintptr& outOffset, GLsizeiptr&
|
||||||
// Advance to the next clean page
|
// Advance to the next clean page
|
||||||
outOffset = static_cast<GLintptr>(currentPage * _gpuBuffer._pageSize);
|
outOffset = static_cast<GLintptr>(currentPage * _gpuBuffer._pageSize);
|
||||||
while (currentPage < pageCount && (0 != (Buffer::DIRTY & _gpuBuffer._pages[currentPage]))) {
|
while (currentPage < pageCount && (0 != (Buffer::DIRTY & _gpuBuffer._pages[currentPage]))) {
|
||||||
|
_gpuBuffer._pages[currentPage] &= ~Buffer::DIRTY;
|
||||||
++currentPage;
|
++currentPage;
|
||||||
}
|
}
|
||||||
outSize = static_cast<GLsizeiptr>((currentPage * _gpuBuffer._pageSize) - outOffset);
|
outSize = static_cast<GLsizeiptr>((currentPage * _gpuBuffer._pageSize) - outOffset);
|
||||||
|
@ -139,15 +97,13 @@ bool GLBackend::GLBuffer::getNextTransferBlock(GLintptr& outOffset, GLsizeiptr&
|
||||||
GLBackend::GLBuffer* GLBackend::syncGPUObject(const Buffer& buffer) {
|
GLBackend::GLBuffer* GLBackend::syncGPUObject(const Buffer& buffer) {
|
||||||
GLBuffer* object = Backend::getGPUObject<GLBackend::GLBuffer>(buffer);
|
GLBuffer* object = Backend::getGPUObject<GLBackend::GLBuffer>(buffer);
|
||||||
|
|
||||||
bool forceTransferAll = false;
|
|
||||||
// Has the storage size changed?
|
// Has the storage size changed?
|
||||||
if (!object || object->_stamp != buffer.getSysmem().getStamp()) {
|
if (!object || object->_stamp != buffer.getSysmem().getStamp()) {
|
||||||
object = new GLBuffer(buffer);
|
object = new GLBuffer(buffer, object);
|
||||||
forceTransferAll = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forceTransferAll || (0 != (buffer._flags & Buffer::DIRTY))) {
|
if (0 != (buffer._flags & Buffer::DIRTY)) {
|
||||||
object->transfer(forceTransferAll);
|
object->transfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
|
|
@ -270,7 +270,7 @@ Buffer::Size Buffer::resize(Size size) {
|
||||||
if (prevSize < size) {
|
if (prevSize < size) {
|
||||||
auto newPages = getRequiredPageCount();
|
auto newPages = getRequiredPageCount();
|
||||||
auto newSize = newPages * _pageSize;
|
auto newSize = newPages * _pageSize;
|
||||||
editSysmem().resize(size);
|
editSysmem().resize(newSize);
|
||||||
// All new pages start off as clean, because they haven't been populated by data
|
// All new pages start off as clean, because they haven't been populated by data
|
||||||
_pages.resize(newPages, 0);
|
_pages.resize(newPages, 0);
|
||||||
Buffer::updateBufferCPUMemoryUsage(prevSize, newSize);
|
Buffer::updateBufferCPUMemoryUsage(prevSize, newSize);
|
||||||
|
@ -278,7 +278,7 @@ Buffer::Size Buffer::resize(Size size) {
|
||||||
return _end;
|
return _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::dirtyPages(Size offset, Size bytes) {
|
void Buffer::markDirty(Size offset, Size bytes) {
|
||||||
if (!bytes) {
|
if (!bytes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ Buffer::Size Buffer::setData(Size size, const Byte* data) {
|
||||||
Buffer::Size Buffer::setSubData(Size offset, Size size, const Byte* data) {
|
Buffer::Size Buffer::setSubData(Size offset, Size size, const Byte* data) {
|
||||||
auto changedBytes = editSysmem().setSubData(offset, size, data);
|
auto changedBytes = editSysmem().setSubData(offset, size, data);
|
||||||
if (changedBytes) {
|
if (changedBytes) {
|
||||||
dirtyPages(offset, changedBytes);
|
markDirty(offset, changedBytes);
|
||||||
}
|
}
|
||||||
return changedBytes;
|
return changedBytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,8 +136,7 @@ public:
|
||||||
// The size in bytes of data stored in the buffer
|
// The size in bytes of data stored in the buffer
|
||||||
Size getSize() const;
|
Size getSize() const;
|
||||||
const Byte* getData() const { return getSysmem().readData(); }
|
const Byte* getData() const { return getSysmem().readData(); }
|
||||||
Byte* editData() { return editSysmem().editData(); }
|
|
||||||
|
|
||||||
// Resize the buffer
|
// Resize the buffer
|
||||||
// Keep previous data [0 to min(pSize, mSize)]
|
// Keep previous data [0 to min(pSize, mSize)]
|
||||||
Size resize(Size pSize);
|
Size resize(Size pSize);
|
||||||
|
@ -159,6 +158,9 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Size setSubData(Size index, const std::vector<T>& t) {
|
Size setSubData(Size index, const std::vector<T>& t) {
|
||||||
|
if (t.empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Size offset = index * sizeof(T);
|
Size offset = index * sizeof(T);
|
||||||
Size size = t.size() * sizeof(T);
|
Size size = t.size() * sizeof(T);
|
||||||
return setSubData(offset, size, reinterpret_cast<const Byte*>(&t[0]));
|
return setSubData(offset, size, reinterpret_cast<const Byte*>(&t[0]));
|
||||||
|
@ -176,18 +178,28 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Size append(const std::vector<T>& t) {
|
Size append(const std::vector<T>& t) {
|
||||||
|
if (t.empty()) {
|
||||||
|
return _end;
|
||||||
|
}
|
||||||
return append(sizeof(T) * t.size(), reinterpret_cast<const Byte*>(&t[0]));
|
return append(sizeof(T) * t.size(), reinterpret_cast<const Byte*>(&t[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
const GPUObjectPointer gpuObject {};
|
const GPUObjectPointer gpuObject {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void markDirty(Size offset, Size bytes);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void markDirty(Size index, Size count = 1) {
|
||||||
|
markDirty(sizeof(T) * index, sizeof(T) * count);
|
||||||
|
}
|
||||||
|
|
||||||
// Access the sysmem object, limited to ourselves and GPUObject derived classes
|
// Access the sysmem object, limited to ourselves and GPUObject derived classes
|
||||||
const Sysmem& getSysmem() const { return _sysmem; }
|
const Sysmem& getSysmem() const { return _sysmem; }
|
||||||
Sysmem& editSysmem() { return _sysmem; }
|
Sysmem& editSysmem() { return _sysmem; }
|
||||||
|
Byte* editData() { return editSysmem().editData(); }
|
||||||
|
|
||||||
Size getRequiredPageCount() const;
|
Size getRequiredPageCount() const;
|
||||||
void dirtyPages(Size offset, Size bytes);
|
|
||||||
|
|
||||||
Size _end { 0 };
|
Size _end { 0 };
|
||||||
mutable uint8_t _flags;
|
mutable uint8_t _flags;
|
||||||
|
@ -197,6 +209,7 @@ protected:
|
||||||
|
|
||||||
// FIXME find a more generic way to do this.
|
// FIXME find a more generic way to do this.
|
||||||
friend class GLBackend;
|
friend class GLBackend;
|
||||||
|
friend class BufferView;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Buffer> BufferPointer;
|
typedef std::shared_ptr<Buffer> BufferPointer;
|
||||||
|
@ -320,8 +333,14 @@ public:
|
||||||
int _stride;
|
int _stride;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Direct memory access to the buffer contents is incompatible with the paging memory scheme
|
||||||
template <typename T> Iterator<T> begin() { return Iterator<T>(&edit<T>(0), _stride); }
|
template <typename T> Iterator<T> begin() { return Iterator<T>(&edit<T>(0), _stride); }
|
||||||
template <typename T> Iterator<T> end() { return Iterator<T>(&edit<T>(getNum<T>()), _stride); }
|
template <typename T> Iterator<T> end() { return Iterator<T>(&edit<T>(getNum<T>()), _stride); }
|
||||||
|
#else
|
||||||
|
template <typename T> Iterator<const T> begin() const { return Iterator<const T>(&get<T>(), _stride); }
|
||||||
|
template <typename T> Iterator<const T> end() const { return Iterator<const T>(&get<T>(getNum<T>()), _stride); }
|
||||||
|
#endif
|
||||||
template <typename T> Iterator<const T> cbegin() const { return Iterator<const T>(&get<T>(), _stride); }
|
template <typename T> Iterator<const T> cbegin() const { return Iterator<const T>(&get<T>(), _stride); }
|
||||||
template <typename T> Iterator<const T> cend() const { return Iterator<const T>(&get<T>(getNum<T>()), _stride); }
|
template <typename T> Iterator<const T> cend() const { return Iterator<const T>(&get<T>(getNum<T>()), _stride); }
|
||||||
|
|
||||||
|
@ -358,6 +377,7 @@ public:
|
||||||
qDebug() << "Accessing buffer outside the BufferView range, element size = " << sizeof(T) << " when bufferView size = " << _size;
|
qDebug() << "Accessing buffer outside the BufferView range, element size = " << sizeof(T) << " when bufferView size = " << _size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
_buffer->markDirty(_offset, sizeof(T));
|
||||||
T* t = (reinterpret_cast<T*> (_buffer->editData() + _offset));
|
T* t = (reinterpret_cast<T*> (_buffer->editData() + _offset));
|
||||||
return *(t);
|
return *(t);
|
||||||
}
|
}
|
||||||
|
@ -391,6 +411,7 @@ public:
|
||||||
qDebug() << "Accessing buffer outside the BufferView range, index = " << index << " number elements = " << getNum<T>();
|
qDebug() << "Accessing buffer outside the BufferView range, index = " << index << " number elements = " << getNum<T>();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
_buffer->markDirty(elementOffset, sizeof(T));
|
||||||
return *(reinterpret_cast<T*> (_buffer->editData() + elementOffset));
|
return *(reinterpret_cast<T*> (_buffer->editData() + elementOffset));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -118,29 +118,18 @@ AnimDebugDraw::AnimDebugDraw() :
|
||||||
|
|
||||||
// HACK: add red, green and blue axis at (1,1,1)
|
// HACK: add red, green and blue axis at (1,1,1)
|
||||||
_animDebugDrawData->_vertexBuffer->resize(sizeof(Vertex) * 6);
|
_animDebugDrawData->_vertexBuffer->resize(sizeof(Vertex) * 6);
|
||||||
Vertex* data = (Vertex*)_animDebugDrawData->_vertexBuffer->editData();
|
|
||||||
|
static std::vector<Vertex> vertices({
|
||||||
data[0].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
Vertex { glm::vec3(1.0, 1.0f, 1.0f), toRGBA(255, 0, 0, 255) },
|
||||||
data[0].rgba = toRGBA(255, 0, 0, 255);
|
Vertex { glm::vec3(2.0, 1.0f, 1.0f), toRGBA(255, 0, 0, 255) },
|
||||||
data[1].pos = glm::vec3(2.0, 1.0f, 1.0f);
|
Vertex { glm::vec3(1.0, 1.0f, 1.0f), toRGBA(0, 255, 0, 255) },
|
||||||
data[1].rgba = toRGBA(255, 0, 0, 255);
|
Vertex { glm::vec3(1.0, 2.0f, 1.0f), toRGBA(0, 255, 0, 255) },
|
||||||
|
Vertex { glm::vec3(1.0, 1.0f, 1.0f), toRGBA(0, 0, 255, 255) },
|
||||||
data[2].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
Vertex { glm::vec3(1.0, 1.0f, 2.0f), toRGBA(0, 0, 255, 255) },
|
||||||
data[2].rgba = toRGBA(0, 255, 0, 255);
|
});
|
||||||
data[3].pos = glm::vec3(1.0, 2.0f, 1.0f);
|
static std::vector<uint16_t> indices({ 0, 1, 2, 3, 4, 5 });
|
||||||
data[3].rgba = toRGBA(0, 255, 0, 255);
|
_animDebugDrawData->_vertexBuffer->setSubData<Vertex>(0, vertices);
|
||||||
|
_animDebugDrawData->_indexBuffer->setSubData<uint16_t>(0, indices);
|
||||||
data[4].pos = glm::vec3(1.0, 1.0f, 1.0f);
|
|
||||||
data[4].rgba = toRGBA(0, 0, 255, 255);
|
|
||||||
data[5].pos = glm::vec3(1.0, 1.0f, 2.0f);
|
|
||||||
data[5].rgba = toRGBA(0, 0, 255, 255);
|
|
||||||
|
|
||||||
_animDebugDrawData->_indexBuffer->resize(sizeof(uint16_t) * 6);
|
|
||||||
uint16_t* indices = (uint16_t*)_animDebugDrawData->_indexBuffer->editData();
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
indices[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimDebugDraw::~AnimDebugDraw() {
|
AnimDebugDraw::~AnimDebugDraw() {
|
||||||
|
@ -356,9 +345,13 @@ void AnimDebugDraw::update() {
|
||||||
numVerts += (int)DebugDraw::getInstance().getRays().size() * VERTICES_PER_RAY;
|
numVerts += (int)DebugDraw::getInstance().getRays().size() * VERTICES_PER_RAY;
|
||||||
|
|
||||||
// allocate verts!
|
// allocate verts!
|
||||||
data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
|
std::vector<Vertex> vertices;
|
||||||
Vertex* verts = (Vertex*)data._vertexBuffer->editData();
|
vertices.resize(numVerts);
|
||||||
Vertex* v = verts;
|
//Vertex* verts = (Vertex*)data._vertexBuffer->editData();
|
||||||
|
Vertex* v = nullptr;
|
||||||
|
if (numVerts) {
|
||||||
|
v = &vertices[0];
|
||||||
|
}
|
||||||
|
|
||||||
// draw absolute poses
|
// draw absolute poses
|
||||||
for (auto& iter : _absolutePoses) {
|
for (auto& iter : _absolutePoses) {
|
||||||
|
@ -381,6 +374,8 @@ void AnimDebugDraw::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
|
||||||
|
data._vertexBuffer->setSubData<Vertex>(0, vertices);
|
||||||
|
|
||||||
// draw markers from shared DebugDraw singleton
|
// draw markers from shared DebugDraw singleton
|
||||||
for (auto& iter : markerMap) {
|
for (auto& iter : markerMap) {
|
||||||
|
@ -408,20 +403,19 @@ void AnimDebugDraw::update() {
|
||||||
}
|
}
|
||||||
DebugDraw::getInstance().clearRays();
|
DebugDraw::getInstance().clearRays();
|
||||||
|
|
||||||
assert(numVerts == (v - verts));
|
assert((!numVerts && !v) || (numVerts == (v - &vertices[0])));
|
||||||
|
|
||||||
render::Item::Bound theBound;
|
render::Item::Bound theBound;
|
||||||
for (int i = 0; i < numVerts; i++) {
|
for (int i = 0; i < numVerts; i++) {
|
||||||
theBound += verts[i].pos;
|
theBound += vertices[i].pos;
|
||||||
}
|
}
|
||||||
data._bound = theBound;
|
data._bound = theBound;
|
||||||
|
|
||||||
data._isVisible = (numVerts > 0);
|
data._isVisible = (numVerts > 0);
|
||||||
|
|
||||||
data._indexBuffer->resize(sizeof(uint16_t) * numVerts);
|
data._indexBuffer->resize(sizeof(uint16_t) * numVerts);
|
||||||
uint16_t* indices = (uint16_t*)data._indexBuffer->editData();
|
|
||||||
for (int i = 0; i < numVerts; i++) {
|
for (int i = 0; i < numVerts; i++) {
|
||||||
indices[i] = i;
|
data._indexBuffer->setSubData<uint16_t>(i, (uint16_t)i);;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
scene->enqueuePendingChanges(pendingChanges);
|
scene->enqueuePendingChanges(pendingChanges);
|
||||||
|
|
|
@ -116,35 +116,25 @@ void DrawStatus::run(const SceneContextPointer& sceneContext,
|
||||||
// FIrst thing, we collect the bound and the status for all the items we want to render
|
// FIrst thing, we collect the bound and the status for all the items we want to render
|
||||||
int nbItems = 0;
|
int nbItems = 0;
|
||||||
{
|
{
|
||||||
if (!_itemBounds) {
|
_itemBounds.resize(inItems.size());
|
||||||
_itemBounds = std::make_shared<gpu::Buffer>();
|
_itemStatus.resize(inItems.size());
|
||||||
}
|
_itemCells.resize(inItems.size());
|
||||||
if (!_itemStatus) {
|
|
||||||
_itemStatus = std::make_shared<gpu::Buffer>();;
|
|
||||||
}
|
|
||||||
if (!_itemCells) {
|
|
||||||
_itemCells = std::make_shared<gpu::Buffer>();;
|
|
||||||
}
|
|
||||||
|
|
||||||
_itemBounds->resize((inItems.size() * sizeof(AABox)));
|
// AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
||||||
_itemStatus->resize((inItems.size() * NUM_STATUS_VEC4_PER_ITEM * sizeof(glm::vec4)));
|
// glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||||
_itemCells->resize((inItems.size() * sizeof(Octree::Location)));
|
// Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
|
||||||
|
for (size_t i = 0; i < inItems.size(); ++i) {
|
||||||
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
const auto& item = inItems[i];
|
||||||
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
|
||||||
Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
|
|
||||||
for (auto& item : inItems) {
|
|
||||||
if (!item.bound.isInvalid()) {
|
if (!item.bound.isInvalid()) {
|
||||||
if (!item.bound.isNull()) {
|
if (!item.bound.isNull()) {
|
||||||
(*itemAABox) = item.bound;
|
_itemBounds[i] = item.bound;
|
||||||
} else {
|
} else {
|
||||||
(*itemAABox).setBox(item.bound.getCorner(), 0.1f);
|
_itemBounds[i].setBox(item.bound.getCorner(), 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto& itemScene = scene->getItem(item.id);
|
auto& itemScene = scene->getItem(item.id);
|
||||||
|
_itemCells[i] = scene->getSpatialTree().getCellLocation(itemScene.getCell());
|
||||||
(*itemCell) = scene->getSpatialTree().getCellLocation(itemScene.getCell());
|
|
||||||
|
|
||||||
auto itemStatusPointer = itemScene.getStatus();
|
auto itemStatusPointer = itemScene.getStatus();
|
||||||
if (itemStatusPointer) {
|
if (itemStatusPointer) {
|
||||||
|
@ -152,25 +142,19 @@ void DrawStatus::run(const SceneContextPointer& sceneContext,
|
||||||
auto&& currentStatusValues = itemStatusPointer->getCurrentValues();
|
auto&& currentStatusValues = itemStatusPointer->getCurrentValues();
|
||||||
int valueNum = 0;
|
int valueNum = 0;
|
||||||
for (int vec4Num = 0; vec4Num < NUM_STATUS_VEC4_PER_ITEM; vec4Num++) {
|
for (int vec4Num = 0; vec4Num < NUM_STATUS_VEC4_PER_ITEM; vec4Num++) {
|
||||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
auto& value = (vec4Num ? _itemStatus[i].first : _itemStatus[i].second);
|
||||||
|
value = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
||||||
for (int component = 0; component < VEC4_LENGTH; component++) {
|
for (int component = 0; component < VEC4_LENGTH; component++) {
|
||||||
valueNum = vec4Num * VEC4_LENGTH + component;
|
valueNum = vec4Num * VEC4_LENGTH + component;
|
||||||
if (valueNum < (int)currentStatusValues.size()) {
|
if (valueNum < (int)currentStatusValues.size()) {
|
||||||
(*itemStatus)[component] = currentStatusValues[valueNum].getPackedData();
|
value[component] = currentStatusValues[valueNum].getPackedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemStatus++;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
_itemStatus[i].first = _itemStatus[i].second = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
||||||
itemStatus++;
|
|
||||||
(*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData());
|
|
||||||
itemStatus++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nbItems++;
|
nbItems++;
|
||||||
itemAABox++;
|
|
||||||
itemCell++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,25 +178,20 @@ void DrawStatus::run(const SceneContextPointer& sceneContext,
|
||||||
// bind the one gpu::Pipeline we need
|
// bind the one gpu::Pipeline we need
|
||||||
batch.setPipeline(getDrawItemBoundsPipeline());
|
batch.setPipeline(getDrawItemBoundsPipeline());
|
||||||
|
|
||||||
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
//AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
||||||
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
//glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||||
Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
|
//Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_itemCells->editData());
|
||||||
|
|
||||||
const unsigned int VEC3_ADRESS_OFFSET = 3;
|
const unsigned int VEC3_ADRESS_OFFSET = 3;
|
||||||
|
|
||||||
if (_showDisplay) {
|
if (_showDisplay) {
|
||||||
for (int i = 0; i < nbItems; i++) {
|
for (int i = 0; i < nbItems; i++) {
|
||||||
batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i));
|
batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*)&(_itemBounds[i]));
|
||||||
batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
|
batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET);
|
||||||
|
|
||||||
|
|
||||||
glm::ivec4 cellLocation(itemCell->pos.x, itemCell->pos.y, itemCell->pos.z, itemCell->depth);
|
|
||||||
|
|
||||||
|
glm::ivec4 cellLocation(_itemCells[i].pos, _itemCells[i].depth);
|
||||||
batch._glUniform4iv(_drawItemCellLocLoc, 1, ((const int*)(&cellLocation)));
|
batch._glUniform4iv(_drawItemCellLocLoc, 1, ((const int*)(&cellLocation)));
|
||||||
|
|
||||||
|
|
||||||
batch.draw(gpu::LINES, 24, 0);
|
batch.draw(gpu::LINES, 24, 0);
|
||||||
itemCell++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,10 +201,10 @@ void DrawStatus::run(const SceneContextPointer& sceneContext,
|
||||||
|
|
||||||
if (_showNetwork) {
|
if (_showNetwork) {
|
||||||
for (int i = 0; i < nbItems; i++) {
|
for (int i = 0; i < nbItems; i++) {
|
||||||
batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i));
|
batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*)&(_itemBounds[i]));
|
||||||
batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
|
batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET);
|
||||||
batch._glUniform4iv(_drawItemStatusValue0Loc, 1, (const int*)(itemStatus + NUM_STATUS_VEC4_PER_ITEM * i));
|
batch._glUniform4iv(_drawItemStatusValue0Loc, 1, (const int*)&(_itemStatus[i].first));
|
||||||
batch._glUniform4iv(_drawItemStatusValue1Loc, 1, (const int*)(itemStatus + NUM_STATUS_VEC4_PER_ITEM * i + 1));
|
batch._glUniform4iv(_drawItemStatusValue1Loc, 1, (const int*)&(_itemStatus[i].second));
|
||||||
batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0);
|
batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,13 @@ namespace render {
|
||||||
gpu::Stream::FormatPointer _drawItemFormat;
|
gpu::Stream::FormatPointer _drawItemFormat;
|
||||||
gpu::PipelinePointer _drawItemBoundsPipeline;
|
gpu::PipelinePointer _drawItemBoundsPipeline;
|
||||||
gpu::PipelinePointer _drawItemStatusPipeline;
|
gpu::PipelinePointer _drawItemStatusPipeline;
|
||||||
gpu::BufferPointer _itemBounds;
|
|
||||||
gpu::BufferPointer _itemCells;
|
std::vector<AABox> _itemBounds;
|
||||||
gpu::BufferPointer _itemStatus;
|
std::vector<std::pair<glm::ivec4, glm::ivec4>> _itemStatus;
|
||||||
|
std::vector<Octree::Location> _itemCells;
|
||||||
|
//gpu::BufferPointer _itemBounds;
|
||||||
|
//gpu::BufferPointer _itemCells;
|
||||||
|
//gpu::BufferPointer _itemStatus;
|
||||||
gpu::TexturePointer _statusIconMap;
|
gpu::TexturePointer _statusIconMap;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue