Allow updates of VertexObject and mark some methods as noexcept
parent
6712b90d84
commit
a90570e36a
|
@ -35,9 +35,9 @@ VertexObject::~VertexObject()
|
|||
glDeleteBuffers(1, &m_vboId);
|
||||
}
|
||||
|
||||
void VertexObject::bind()
|
||||
void VertexObject::bind() noexcept
|
||||
{
|
||||
if (m_firstBind)
|
||||
if ((m_state & State::Initialize) != 0)
|
||||
{
|
||||
if (GLEW_ARB_vertex_array_object)
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ void VertexObject::bind()
|
|||
if (GLEW_ARB_vertex_array_object)
|
||||
{
|
||||
glBindVertexArray(m_vaoId);
|
||||
if ((m_state & State::Update) != 0)
|
||||
glBindBuffer(m_bufferType, m_vboId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -61,11 +63,17 @@ void VertexObject::bind()
|
|||
}
|
||||
}
|
||||
|
||||
void VertexObject::unbind()
|
||||
void VertexObject::bindWritable() noexcept
|
||||
{
|
||||
m_state |= State::Update;
|
||||
bind();
|
||||
}
|
||||
|
||||
void VertexObject::unbind() noexcept
|
||||
{
|
||||
if (GLEW_ARB_vertex_array_object)
|
||||
{
|
||||
if (m_firstBind)
|
||||
if ((m_state & (State::Initialize | State::Update)) != 0)
|
||||
glBindBuffer(m_bufferType, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
@ -74,22 +82,22 @@ void VertexObject::unbind()
|
|||
disableAttribArrays();
|
||||
glBindBuffer(m_bufferType, 0);
|
||||
}
|
||||
m_firstBind = false;
|
||||
m_state = State::NormalState;
|
||||
}
|
||||
|
||||
bool VertexObject::allocate(const void* data)
|
||||
bool VertexObject::allocate(const void* data) noexcept
|
||||
{
|
||||
glBufferData(m_bufferType, m_bufferSize, data, m_streamType);
|
||||
return glGetError() != GL_NO_ERROR;
|
||||
}
|
||||
|
||||
bool VertexObject::allocate(GLsizeiptr bufferSize, const void* data)
|
||||
bool VertexObject::allocate(GLsizeiptr bufferSize, const void* data) noexcept
|
||||
{
|
||||
m_bufferSize = bufferSize;
|
||||
return allocate(data);
|
||||
}
|
||||
|
||||
bool VertexObject::allocate(GLenum bufferType, GLsizeiptr bufferSize, const void* data, GLenum streamType)
|
||||
bool VertexObject::allocate(GLenum bufferType, GLsizeiptr bufferSize, const void* data, GLenum streamType) noexcept
|
||||
{
|
||||
m_bufferType = bufferType;
|
||||
m_bufferSize = bufferSize;
|
||||
|
@ -97,21 +105,21 @@ bool VertexObject::allocate(GLenum bufferType, GLsizeiptr bufferSize, const void
|
|||
return allocate(data);
|
||||
}
|
||||
|
||||
bool VertexObject::setBufferData(const void* data, GLintptr offset, GLsizeiptr size)
|
||||
bool VertexObject::setBufferData(const void* data, GLintptr offset, GLsizeiptr size) noexcept
|
||||
{
|
||||
glBufferSubData(m_bufferType, offset, size == 0 ? m_bufferSize : size, data);
|
||||
return glGetError() != GL_NO_ERROR;
|
||||
}
|
||||
|
||||
void VertexObject::draw(GLenum primitive, GLsizei count, GLint first)
|
||||
void VertexObject::draw(GLenum primitive, GLsizei count, GLint first) noexcept
|
||||
{
|
||||
if (m_firstBind)
|
||||
if ((m_state & State::Initialize) != 0)
|
||||
enableAttribArrays();
|
||||
|
||||
glDrawArrays(primitive, first, count);
|
||||
}
|
||||
|
||||
void VertexObject::enableAttribArrays()
|
||||
void VertexObject::enableAttribArrays() noexcept
|
||||
{
|
||||
glBindBuffer(m_bufferType, m_vboId);
|
||||
|
||||
|
@ -183,7 +191,7 @@ void VertexObject::enableAttribArrays()
|
|||
}
|
||||
}
|
||||
|
||||
void VertexObject::disableAttribArrays()
|
||||
void VertexObject::disableAttribArrays() noexcept
|
||||
{
|
||||
if (m_attrIndexes & AttrType::Vertices)
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
@ -218,49 +226,49 @@ void VertexObject::disableAttribArrays()
|
|||
glBindBuffer(m_bufferType, 0);
|
||||
}
|
||||
|
||||
void VertexObject::setVertices(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setVertices(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Vertices;
|
||||
m_params[0] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setNormals(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setNormals(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Normal;
|
||||
m_params[1] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setColors(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setColors(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Color;
|
||||
m_params[2] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setIndexes(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setIndexes(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Index;
|
||||
m_params[3] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setTextureCoords(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setTextureCoords(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Texture;
|
||||
m_params[4] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setEdgeFlags(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setEdgeFlags(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::EdgeFlag;
|
||||
m_params[5] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setTangents(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setTangents(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::Tangent;
|
||||
m_params[6] = { offset, stride, count, type, normalized };
|
||||
}
|
||||
|
||||
void VertexObject::setPointSizes(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset)
|
||||
void VertexObject::setPointSizes(GLint count, GLenum type, bool normalized, GLsizei stride, GLsizeiptr offset) noexcept
|
||||
{
|
||||
m_attrIndexes |= AttrType::PointSize;
|
||||
m_params[7] = { offset, stride, count, type, normalized };
|
||||
|
|
|
@ -30,30 +30,35 @@ class VertexObject
|
|||
VertexObject(GLenum bufferType, GLsizeiptr bufferSize, GLenum streamType);
|
||||
~VertexObject();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
void draw(GLenum primitive, GLsizei count, GLint first = 0);
|
||||
bool allocate(const void* data = nullptr);
|
||||
bool allocate(GLsizeiptr bufferSize, const void* data = nullptr);
|
||||
bool allocate(GLenum bufferType, GLsizeiptr bufferSize, const void* data, GLenum streamType);
|
||||
bool setBufferData(const void* data, GLintptr offset = 0, GLsizeiptr size = 0);
|
||||
void setVertices(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setNormals(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setColors(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setIndexes(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setTextureCoords(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setEdgeFlags(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setTangents(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void setPointSizes(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
void bind() noexcept;
|
||||
void bindWritable() noexcept;
|
||||
void unbind() noexcept;
|
||||
void draw(GLenum primitive, GLsizei count, GLint first = 0) noexcept;
|
||||
bool allocate(const void* data = nullptr) noexcept;
|
||||
bool allocate(GLsizeiptr bufferSize, const void* data = nullptr) noexcept;
|
||||
bool allocate(GLenum bufferType, GLsizeiptr bufferSize, const void* data, GLenum streamType) noexcept;
|
||||
bool setBufferData(const void* data, GLintptr offset = 0, GLsizeiptr size = 0) noexcept;
|
||||
void setVertices(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setNormals(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setColors(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setIndexes(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setTextureCoords(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setEdgeFlags(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setTangents(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setPointSizes(GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0) noexcept;
|
||||
void setVertexAttrib(GLint location, GLint count, GLenum type, bool normalized = false, GLsizei stride = 0, GLsizeiptr offset = 0);
|
||||
bool initialized() const { return !m_firstBind; }
|
||||
void setBufferType(GLenum bufferType) { m_bufferType = bufferType; }
|
||||
void setBufferSize(GLsizeiptr bufferSize) { m_bufferSize = bufferSize; }
|
||||
void setStreamType(GLenum streamType) { m_streamType = streamType; }
|
||||
inline bool initialized() const noexcept
|
||||
{
|
||||
return (m_state & State::Initialize) == 0;
|
||||
}
|
||||
void setBufferType(GLenum bufferType) noexcept { m_bufferType = bufferType; }
|
||||
void setBufferSize(GLsizeiptr bufferSize) noexcept { m_bufferSize = bufferSize; }
|
||||
void setStreamType(GLenum streamType) noexcept { m_streamType = streamType; }
|
||||
|
||||
private:
|
||||
enum AttrType
|
||||
enum AttrType : uint16_t
|
||||
{
|
||||
Nothing = 0x00000000,
|
||||
Vertices = 0x00000001,
|
||||
Normal = 0x00000002,
|
||||
Color = 0x00000004,
|
||||
|
@ -64,6 +69,13 @@ class VertexObject
|
|||
PointSize = 0x00000080
|
||||
};
|
||||
|
||||
enum State : uint16_t
|
||||
{
|
||||
NormalState = 0x0000,
|
||||
Initialize = 0x0001,
|
||||
Update = 0x0002
|
||||
};
|
||||
|
||||
struct PtrParams
|
||||
{
|
||||
GLsizeiptr offset;
|
||||
|
@ -73,19 +85,18 @@ class VertexObject
|
|||
bool normalized;
|
||||
};
|
||||
|
||||
void enableAttribArrays();
|
||||
void disableAttribArrays();
|
||||
void enableAttribArrays() noexcept;
|
||||
void disableAttribArrays() noexcept;
|
||||
|
||||
GLuint m_vboId{ 0 };
|
||||
GLuint m_vaoId{ 0 };
|
||||
uint16_t m_attrIndexes{ 0 };
|
||||
uint16_t m_attrIndexes{ AttrType::Nothing };
|
||||
uint16_t m_state{ State::Initialize };
|
||||
|
||||
GLsizeiptr m_bufferSize{ 0 };
|
||||
GLenum m_bufferType{ 0 };
|
||||
GLenum m_streamType{ 0 };
|
||||
std::array<PtrParams, 8> m_params {};
|
||||
std::map<GLint, PtrParams>* m_attribParams{ nullptr };
|
||||
|
||||
bool m_firstBind{ true };
|
||||
};
|
||||
}; // namespace
|
||||
|
|
Loading…
Reference in New Issue