Re-fix QuadTree GPU rendering, discard groups
[ipdf/code.git] / src / graphicsbuffer.cpp
index 576c2d6..217fa9a 100644 (file)
@@ -74,6 +74,7 @@ GraphicsBuffer::GraphicsBuffer()
        m_buffer_handle = 0;
        m_buffer_usage = BufferUsageDynamicDraw;
        m_faking_map = false;
+       m_name = "Unnamed Buffer";
        SetUsage(BufferUsageStaticDraw);
 }
 
@@ -91,6 +92,11 @@ void GraphicsBuffer::SetType(GraphicsBuffer::BufferType bufType)
        m_buffer_type = bufType;
 }
 
+void GraphicsBuffer::SetName(const char *name)
+{
+       m_name = name;
+}
+
 void GraphicsBuffer::SetUsage(GraphicsBuffer::BufferUsage bufUsage)
 {
        if (bufUsage != m_buffer_usage)
@@ -125,6 +131,7 @@ bool GraphicsBuffer::RecreateBuffer(const void *data)
                glDeleteBuffers(1, &m_buffer_handle);
        }
        glGenBuffers(1, &m_buffer_handle);
+       glObjectLabel(GL_BUFFER, m_buffer_handle, -1, m_name);
        m_buffer_shape_dirty = false;
        if (m_buffer_size)
                Upload(m_buffer_size, data);
@@ -185,12 +192,16 @@ void* GraphicsBuffer::MapRange(int offset, int length, bool read, bool write, bo
 void GraphicsBuffer::UnMap()
 {
        GLenum target = BufferTypeToGLType(m_buffer_type);
+       
+       // If we're not mapped, unmapping is a no-op.
+       if (!m_map_pointer)
+               return;
 
        if (m_faking_map)
        {
                Upload(m_buffer_size, m_map_pointer);
                free(m_map_pointer);
-               m_map_pointer = nullptr;
+               m_map_pointer = NULL;
                m_invalidated = false;
                m_faking_map = false;
                return;
@@ -198,7 +209,7 @@ void GraphicsBuffer::UnMap()
        
        Bind();
        glUnmapBuffer(target);
-       m_map_pointer = nullptr;
+       m_map_pointer = NULL;
        m_invalidated = false;
 }
 
@@ -215,7 +226,7 @@ void GraphicsBuffer::Upload(size_t length, const void* data)
                Bind();
                glBufferData(target, length, data, usage);
        }
-       if (data != nullptr)
+       if (data != NULL)
                m_invalidated = false;
 }
 
@@ -238,16 +249,19 @@ void GraphicsBuffer::Resize(size_t length)
        }
        else
        {
+               glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Resizing buffer.");
+               glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, NULL, GL_TRUE);
                // Create a new buffer and copy the old data into it.
                UnMap();
                GLuint old_buffer = m_buffer_handle;    
                glGenBuffers(1, &m_buffer_handle);
-               Upload(length, nullptr);
+               Upload(length, NULL);
                glBindBuffer(GL_COPY_READ_BUFFER, old_buffer);
                glBindBuffer(GL_COPY_WRITE_BUFFER, m_buffer_handle);
                glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, m_buffer_size);
                glDeleteBuffers(1, &old_buffer);
                m_buffer_size = length;
+               glPopDebugGroup();
        }
 }
 
@@ -259,3 +273,7 @@ void GraphicsBuffer::Bind() const
                glBindBuffer(BufferTypeToGLType(m_buffer_type), m_buffer_handle);
 }
 
+void GraphicsBuffer::BindRange(size_t start, size_t size) const
+{
+       glBindBufferRange(BufferTypeToGLType(m_buffer_type), 0, m_buffer_handle, start, size);
+}

UCC git Repository :: git.ucc.asn.au