[Feat] (MG_State): Integration with RenderbufferState.

This commit is contained in:
BZLZHH
2025-12-14 09:49:55 +08:00
parent 5bb9faaaa5
commit 711e427b76
4 changed files with 57 additions and 33 deletions
+26
View File
@@ -1,4 +1,5 @@
#include "Core.h" #include "Core.h"
#include "MG_State/GLState/RenderbufferState/RenderbufferObject.h"
namespace MobileGL { namespace MobileGL {
namespace MG_State { namespace MG_State {
@@ -368,6 +369,31 @@ namespace MobileGL {
Bool GLContext::ValidateSamplerObject(Uint index) const { Bool GLContext::ValidateSamplerObject(Uint index) const {
return m_samplerState.ValidateSamplerObject(index); return m_samplerState.ValidateSamplerObject(index);
} }
// Renderbuffer
Vector<Uint> GLContext::GenRenderbufferNames(Uint number) {
return m_renderbufferState.GenerateNames(number);
}
SharedPtr<RenderbufferObject> GLContext::GetRenderbufferObject(Uint index) {
return m_renderbufferState.GetRenderbufferObject(index);
}
BindingSlot<RenderbufferObject>& GLContext::GetRenderbufferBindingSlot(RenderbufferTarget target) {
return m_renderbufferState.GetBindingSlot(target);
}
SharedPtr<RenderbufferObject> GLContext::CreateRenderbufferObject(Uint index) {
return m_renderbufferState.CreateRenderbufferObject(index);
}
void GLContext::MarkRenderbufferObjectForDeletion(Uint index) {
m_renderbufferState.MarkRenderbufferObjectForDeletion(index);
}
Bool GLContext::ValidateRenderbufferName(Uint index) const {
return m_renderbufferState.ValidateName(index);
}
} // namespace GLState } // namespace GLState
GLState::GLContext* pGLContext; GLState::GLContext* pGLContext;
+15 -17
View File
@@ -1,14 +1,16 @@
#pragma once #pragma once
#include <Includes.h> #include <Includes.h>
#include "MG_Util/Types.h"
#include "ErrorState/Error.h" #include "ErrorState/Error.h"
#include "BufferState/BufferState.h" #include "BufferState/BufferState.h"
#include "MG_State/GLState/RenderbufferState/RenderbufferObject.h"
#include "MG_State/GLState/RenderbufferState/RenderbufferState.h"
#include "RenderState/RenderState.h"
#include "ProgramState/ProgramState.h" #include "ProgramState/ProgramState.h"
#include "SamplerState/SamplerState.h" #include "SamplerState/SamplerState.h"
#include "TextureState/TextureState.h" #include "TextureState/TextureState.h"
#include "FramebufferState/FramebufferState.h" #include "FramebufferState/FramebufferState.h"
#include "VertexArrayState/VertexArrayState.h" #include "VertexArrayState/VertexArrayState.h"
#include "MG_State/GLState/RenderState/RenderState.h" #include "RenderbufferState/RenderbufferState.h"
namespace MobileGL { namespace MobileGL {
namespace MG_State { namespace MG_State {
@@ -118,30 +120,26 @@ namespace MobileGL {
Bool ValidateSamplerName(Uint index) const; Bool ValidateSamplerName(Uint index) const;
Bool ValidateSamplerObject(Uint index) const; Bool ValidateSamplerObject(Uint index) const;
// Renderbuffer
Vector<Uint> GenRenderbufferNames(Uint number);
SharedPtr<RenderbufferObject> GetRenderbufferObject(Uint index);
BindingSlot<RenderbufferObject>& GetRenderbufferBindingSlot(RenderbufferTarget target);
SharedPtr<RenderbufferObject> CreateRenderbufferObject(Uint index);
void MarkRenderbufferObjectForDeletion(Uint index);
Bool ValidateRenderbufferName(Uint index) const;
Bool ValidateRenderbufferObject(Uint index) const;
private: private:
// Error // State Components
ErrorState m_errorState; ErrorState m_errorState;
// Buffer
BufferState m_bufferState; BufferState m_bufferState;
// VertexArray
VertexArrayState m_vertexArrayState; VertexArrayState m_vertexArrayState;
// Texture
TextureState m_textureState; TextureState m_textureState;
// Program
ProgramState m_programState; ProgramState m_programState;
// RenderState
RenderState m_renderState; RenderState m_renderState;
// Framebuffer
FramebufferState m_framebufferState; FramebufferState m_framebufferState;
// Sampler
SamplerState m_samplerState; SamplerState m_samplerState;
RenderbufferState m_renderbufferState;
}; };
} // namespace GLState } // namespace GLState
@@ -1,4 +1,5 @@
#include "FramebufferObject.h" #include "FramebufferObject.h"
#include "MG_Util/Types.h"
namespace MobileGL { namespace MobileGL {
namespace MG_State { namespace MG_State {
@@ -7,7 +8,7 @@ namespace MobileGL {
FramebufferAttachment::FramebufferAttachment(SharedPtr<MG_State::GLState::ITextureObject> texture, FramebufferAttachment::FramebufferAttachment(SharedPtr<MG_State::GLState::ITextureObject> texture,
Int level) Int level)
: m_texture(texture), m_textureLevel(level) {} : m_texture(texture), m_textureLevel(level) {}
FramebufferAttachment::FramebufferAttachment(SharedPtr<RenderbufferObjectStub> renderbuffer) FramebufferAttachment::FramebufferAttachment(SharedPtr<RenderbufferObject> renderbuffer)
: m_renderbuffer(renderbuffer) {} : m_renderbuffer(renderbuffer) {}
FramebufferAttachment::FramebufferAttachment(Bool IsValid) : m_texture(nullptr), m_renderbuffer(nullptr) { FramebufferAttachment::FramebufferAttachment(Bool IsValid) : m_texture(nullptr), m_renderbuffer(nullptr) {
m_isValid = IsValid; m_isValid = IsValid;
@@ -18,7 +19,7 @@ namespace MobileGL {
} }
Bool FramebufferAttachment::IsRenderbuffer() const { Bool FramebufferAttachment::IsRenderbuffer() const {
return false; return m_renderbuffer != nullptr;
} }
Bool FramebufferAttachment::IsEmpty() const { Bool FramebufferAttachment::IsEmpty() const {
@@ -29,7 +30,7 @@ namespace MobileGL {
return m_texture; return m_texture;
} }
SharedPtr<RenderbufferObjectStub> FramebufferAttachment::GetRenderbuffer() const { SharedPtr<RenderbufferObject> FramebufferAttachment::GetRenderbuffer() const {
return m_renderbuffer; return m_renderbuffer;
} }
@@ -42,8 +43,8 @@ namespace MobileGL {
Bool complete = m_texture->IsComplete(); Bool complete = m_texture->IsComplete();
return complete; return complete;
} else if (IsRenderbuffer()) { } else if (IsRenderbuffer()) {
// TODO Bool complete = m_renderbuffer->IsAllocated();
return false; return complete;
} }
return false; return false;
@@ -52,13 +53,14 @@ namespace MobileGL {
IntVec3 FramebufferAttachment::GetSize() const { IntVec3 FramebufferAttachment::GetSize() const {
if (IsTexture()) { if (IsTexture()) {
// TODO: get correct upload target // TODO: get correct upload target
MOBILEGL_ASSERT(nullptr != dynamic_cast<MG_State::GLState::TextureObjectMipmap*>(m_texture.get()), "Texture object here should always be an object with mipmap"); MOBILEGL_ASSERT(nullptr != dynamic_cast<MG_State::GLState::TextureObjectMipmap*>(m_texture.get()),
"Texture object here should always be an object with mipmap");
auto textureMipmapObject = static_cast<MG_State::GLState::TextureObjectMipmap*>(m_texture.get()); auto textureMipmapObject = static_cast<MG_State::GLState::TextureObjectMipmap*>(m_texture.get());
return textureMipmapObject->GetMipmapTexelSize(TextureUploadTarget::Texture2D, m_textureLevel); return textureMipmapObject->GetMipmapTexelSize(TextureUploadTarget::Texture2D, m_textureLevel);
} else if (IsRenderbuffer()) { } else if (IsRenderbuffer()) {
// TODO return IntVec3(m_renderbuffer->GetWidth(), m_renderbuffer->GetHeight(), 1);
} }
return {0, 0}; return {0, 0, 0};
} }
Bool FramebufferAttachment::IsValid() const { Bool FramebufferAttachment::IsValid() const {
@@ -79,7 +81,7 @@ namespace MobileGL {
} }
void FramebufferObject::AttachRenderbuffer(FramebufferAttachmentType type, void FramebufferObject::AttachRenderbuffer(FramebufferAttachmentType type,
std::shared_ptr<RenderbufferObjectStub> renderbuffer) { std::shared_ptr<RenderbufferObject> renderbuffer) {
m_attachments[static_cast<SizeT>(type)] = FramebufferAttachment(renderbuffer); m_attachments[static_cast<SizeT>(type)] = FramebufferAttachment(renderbuffer);
m_drawBuffersDirty = true; m_drawBuffersDirty = true;
} }
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MG_Util/Types.h"
#include <Includes.h> #include <Includes.h>
#include <MG_State/GLState/TextureState/TextureObject.h> #include <MG_State/GLState/TextureState/TextureObject.h>
#include <MG_State/GLState/RenderbufferState/RenderbufferObject.h>
namespace MobileGL { namespace MobileGL {
enum class FramebufferTarget { enum class FramebufferTarget {
@@ -61,20 +61,18 @@ namespace MobileGL {
namespace MG_State { namespace MG_State {
namespace GLState { namespace GLState {
class RenderbufferObjectStub {}; // TODO
class FramebufferAttachment { class FramebufferAttachment {
public: public:
// TODO: add Renderbuffer when it is implemented // TODO: add Renderbuffer when it is implemented
explicit FramebufferAttachment(SharedPtr<MG_State::GLState::ITextureObject> texture, Int level = 0); explicit FramebufferAttachment(SharedPtr<MG_State::GLState::ITextureObject> texture, Int level = 0);
explicit FramebufferAttachment(SharedPtr<RenderbufferObjectStub> renderbuffer); explicit FramebufferAttachment(SharedPtr<RenderbufferObject> renderbuffer);
explicit FramebufferAttachment(Bool IsValid = true); explicit FramebufferAttachment(Bool IsValid = true);
Bool IsTexture() const; Bool IsTexture() const;
Bool IsRenderbuffer() const; Bool IsRenderbuffer() const;
Bool IsEmpty() const; Bool IsEmpty() const;
SharedPtr<MG_State::GLState::ITextureObject> GetTexture() const; SharedPtr<MG_State::GLState::ITextureObject> GetTexture() const;
SharedPtr<RenderbufferObjectStub> GetRenderbuffer() const; SharedPtr<RenderbufferObject> GetRenderbuffer() const;
Int GetTextureLevel() const; Int GetTextureLevel() const;
Bool IsComplete() const; Bool IsComplete() const;
IntVec3 GetSize() const; IntVec3 GetSize() const;
@@ -82,7 +80,7 @@ namespace MobileGL {
private: private:
SharedPtr<MG_State::GLState::ITextureObject> m_texture = nullptr; SharedPtr<MG_State::GLState::ITextureObject> m_texture = nullptr;
SharedPtr<RenderbufferObjectStub> m_renderbuffer = nullptr; SharedPtr<RenderbufferObject> m_renderbuffer = nullptr;
Int m_textureLevel = 0; Int m_textureLevel = 0;
Bool m_isValid = true; Bool m_isValid = true;
}; };
@@ -96,7 +94,7 @@ namespace MobileGL {
void AttachTexture(FramebufferAttachmentType type, SharedPtr<ITextureObject> texture, int level = 0); void AttachTexture(FramebufferAttachmentType type, SharedPtr<ITextureObject> texture, int level = 0);
void AttachRenderbuffer(FramebufferAttachmentType type, void AttachRenderbuffer(FramebufferAttachmentType type,
std::shared_ptr<RenderbufferObjectStub> renderbuffer); std::shared_ptr<RenderbufferObject> renderbuffer);
void Detach(FramebufferAttachmentType type); void Detach(FramebufferAttachmentType type);
const FramebufferAttachment& GetAttachment(FramebufferAttachmentType type) const; const FramebufferAttachment& GetAttachment(FramebufferAttachmentType type) const;
const Array<FramebufferAttachment, const Array<FramebufferAttachment,