Files
MobileGL/MobileGL/MG_State/GLState/Core.cpp
T

194 lines
7.1 KiB
C++

#include "Core.h"
namespace MobileGL {
namespace MG_State {
namespace GLState {
// Error
void GLContext::RecordError(ErrorCode code, SharedPtr<ErrorInfo> info) {
m_errorState.RecordError(code, info);
}
Bool GLContext::HasGLError() const {
return m_errorState.HasGLError();
}
Optional<const Error> GLContext::PeekGLError() const {
return m_errorState.PeekGLError();
}
Optional<Error> GLContext::PopGLError() {
return m_errorState.PopGLError();
}
Bool GLContext::HasNonGLError() const {
return m_errorState.HasNonGLError();
}
Optional<const Error> GLContext::PeekNonGLError() const {
return m_errorState.PeekNonGLError();
}
Optional<Error> GLContext::PopNonGLError() {
return m_errorState.PopNonGLError();
}
void GLContext::ClearErrors() {
m_errorState.Clear();
}
// Buffer
Vector<Uint> GLContext::GenBufferNames(Uint number) {
return m_bufferState.GenerateNames(number);
}
SharedPtr<BufferObject> GLContext::GetBufferObject(Uint index) {
return m_bufferState.GetBufferObject(index);
}
BindingSlot<BufferObject>& GLContext::GetBufferBindingSlot(BufferTarget target) {
if (target == BufferTarget::Index) {
return m_vertexArrayState.GetBoundVertexArray()->GetIndexBufferBindingSlot();
}
return m_bufferState.GetBindingSlot(target);
}
SharedPtr<BufferObject> GLContext::CreateBufferObject(Uint index) {
return m_bufferState.CreateBufferObject(index);
}
void GLContext::MarkBufferObjectForDeletion(Uint index) {
if (ValidateBufferObject(index)) {
auto bufferObject = m_bufferState.GetBufferObject(index);
auto& vaos = m_vertexArrayState.GetAllVertexArrays();
for (SizeT i = 0; i < vaos.size(); ++i) {
auto vao = vaos[i];
if (vao == nullptr) continue;
if (vao->GetIndexBufferBindingSlot().GetBoundObject() == bufferObject) {
vao->GetIndexBufferBindingSlot().Bind(nullptr);
}
for (SizeT j = 0; j < VertexArrayObject::MAX_VERTEX_ATTRIBS; ++j) {
if (vao->GetAttribute(j).Buffer == bufferObject) {
vao->BindAttributeBuffer(j, nullptr);
}
}
}
}
m_bufferState.MarkBufferObjectForDeletion(index);
}
Bool GLContext::ValidateBufferName(Uint index) const {
return m_bufferState.ValidateName(index);
}
Bool GLContext::ValidateBufferObject(Uint index) const {
return m_bufferState.ValidateBufferObject(index);
}
// VertexArray
Vector<Uint> GLContext::GenVertexArrayNames(Uint number) {
return m_vertexArrayState.GenerateNames(number);
}
SharedPtr<VertexArrayObject> GLContext::GetVertexArrayObject(Uint index) {
return m_vertexArrayState.GetVertexArrayObject(index);
}
void GLContext::BindVertexArray(Uint index) {
m_vertexArrayState.Bind(index);
}
SharedPtr<VertexArrayObject> GLContext::CreateVertexArrayObject(Uint index) {
return m_vertexArrayState.CreateVertexArrayObject(index);
}
void GLContext::MarkVertexArrayForDeletion(Uint index) {
m_vertexArrayState.MarkVertexArrayForDeletion(index);
}
Bool GLContext::ValidateVertexArrayName(Uint index) const {
return m_vertexArrayState.ValidateName(index);
}
Bool GLContext::ValidateVertexArrayObject(Uint index) const {
return m_vertexArrayState.ValidateVertexArrayObject(index);
}
SharedPtr<VertexArrayObject> GLContext::GetBoundVertexArray() {
return m_vertexArrayState.GetBoundVertexArray();
}
// Texture
Vector<Uint> GLContext::GenTextureNames(Uint number) {
return m_textureState.GenerateNames(number);
}
SharedPtr<ITextureObject> GLContext::GetTextureObject(Uint index) {
return m_textureState.GetTextureObject(index);
}
SharedPtr<ITextureObject> GLContext::CreateTextureObject(Uint index, TextureTarget target) {
return m_textureState.CreateTextureObject(index, target);
}
void GLContext::MarkTextureObjectForDeletion(Uint index) {
m_textureState.MarkTextureObjectForDeletion(index);
}
TextureUnit& GLContext::GetTextureUnitObject() {
return m_textureState.GetUnitObject();
}
Bool GLContext::ValidateTextureName(Uint index) const {
return m_textureState.ValidateName(index);
}
Bool GLContext::ValidateTextureObject(Uint index) const {
return m_textureState.ValidateTextureObject(index);
}
Int GLContext::GetActiveTextureUnit() const {
return m_textureState.GetActiveTextureUnit();
}
void GLContext::SetActiveTextureUnit(Int unit) {
m_textureState.SetActiveTextureUnit(unit);
}
Uint GLContext::CreateProgram() {
return m_programState.CreateProgram();
}
Uint GLContext::CreateShader(const ShaderStage stage) {
return m_programState.CreateShader(stage);
}
void GLContext::MarkProgramForDeletion(const Uint index) {
return m_programState.MarkProgramObjectForDeletion(index);
}
void GLContext::MarkShaderForDeletion(const Uint index) {
return m_programState.MarkShaderObjectForDeletion(index);
}
Bool GLContext::ValidateProgramName(const Uint index) const {
return m_programState.ValidateProgramObject(index);
}
Bool GLContext::ValidateShaderName(const Uint index) const {
return m_programState.ValidateShaderObject(index);
}
SharedPtr<ProgramObject> GLContext::GetProgramObject(const Uint index) {
return m_programState.GetProgramObject(index);
}
SharedPtr<ShaderObject> GLContext::GetShaderObject(const Uint index) {
return m_programState.GetShaderObject(index);
}
} // namespace GLState
GLState::GLContext* pGLContext;
} // namespace MG_State
} // namespace MobileGL