[Feat] (MG_State): Add external index getter for each object.

This commit is contained in:
BZLZHH
2025-11-01 11:18:35 +08:00
parent 8da681c720
commit 1269bc76f3
17 changed files with 61 additions and 33 deletions
@@ -211,7 +211,7 @@ namespace MobileGL {
GLsizei c = std::min((GLsizei)s.size(), maxCount);
if (count) *count = c;
for (GLsizei i = 0; i < c; ++i) {
shaders[i] = s[i]->GetId();
shaders[i] = s[i]->GetExternalIndex();
}
}
@@ -25,7 +25,7 @@ namespace MobileGL::MG_Impl::GLImpl {
if (it != m_proxyTexturesMap.end()) {
m_proxyTexturesMap.erase(it);
}
m_proxyTexturesMap[target] = MakeShared<MG_State::GLState::TextureObject2D>();
m_proxyTexturesMap[target] = MakeShared<MG_State::GLState::TextureObject2D>(0);
return m_proxyTexturesMap[target];
}
+3 -3
View File
@@ -10,13 +10,13 @@ namespace MobileGL {
// TODO: get real info in EGL
auto fbo0 = MG_State::pGLContext->CreateFramebufferObject(0);
auto colorTex = MakeShared<MG_State::GLState::TextureObject2D>();
auto colorTex = MakeShared<MG_State::GLState::TextureObject2D>(0);
colorTex->SetInternalFormat(TextureInternalFormat::RGBA8);
colorTex->SetMipmapLevel({{512, 512, 1}, 0, false, 0, {nullptr, 0}});
auto depthTex = MakeShared<MG_State::GLState::TextureObject2D>();
auto depthTex = MakeShared<MG_State::GLState::TextureObject2D>(0);
depthTex->SetInternalFormat(TextureInternalFormat::Depth32FStencil8);
depthTex->SetMipmapLevel({{512, 512, 1}, 0, false, 0, {nullptr, 0}});
auto stencilTex = MakeShared<MG_State::GLState::TextureObject2D>();
auto stencilTex = MakeShared<MG_State::GLState::TextureObject2D>(0);
stencilTex->SetInternalFormat(TextureInternalFormat::Depth32FStencil8);
stencilTex->SetMipmapLevel({{512, 512, 1}, 0, false, 0, {nullptr, 0}});
fbo0->AttachTexture(FramebufferAttachmentType::Color0, colorTex);
@@ -4,8 +4,8 @@
namespace MobileGL {
namespace MG_State {
namespace GLState {
BufferObject::BufferObject()
: m_id(0), m_size(0), m_usage(BufferUsage::StaticDraw), m_isMapped(false),
BufferObject::BufferObject(Uint externalIndex)
: m_externalIndex(externalIndex), m_size(0), m_usage(BufferUsage::StaticDraw), m_isMapped(false),
m_mappingAccess(BufferMappingAccessBit::Null), m_dirtyRange({0, 0}), m_mappedRange({0, 0}),
m_dataPtr(MakeShared<Data>()) {}
@@ -156,6 +156,10 @@ namespace MobileGL {
Flags<BufferMappingAccessBit> BufferObject::GetMappingAccess() const {
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
}
Uint BufferObject::GetExternalIndex() const {
return m_externalIndex;
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -53,7 +53,7 @@ namespace MobileGL {
public:
using TargetEnum = BufferTarget;
BufferObject();
BufferObject(Uint externalIndex);
void Resize(SizeT size);
void UploadData(DataPtr data, SizeT atOffset);
@@ -73,9 +73,10 @@ namespace MobileGL {
Range1D GetMappedRange() const;
const SharedPtr<Data> GetDataReadOnly() const;
Flags<BufferMappingAccessBit> GetMappingAccess() const;
Uint GetExternalIndex() const;
private:
Int m_id = 0;
const Uint m_externalIndex = 0;
SizeT m_size = 0;
BufferUsage m_usage = BufferUsage::StaticDraw;
SharedPtr<Data> m_dataPtr;
@@ -24,7 +24,7 @@ namespace MobileGL {
}
SharedPtr<BufferObject> BufferState::CreateBufferObject(Uint index) {
auto bufferObject = MakeShared<BufferObject>();
auto bufferObject = MakeShared<BufferObject>(index);
m_bufferObjects[index] = bufferObject;
return bufferObject;
}
@@ -63,7 +63,7 @@ namespace MobileGL {
}
// FramebufferObject
FramebufferObject::FramebufferObject() {
FramebufferObject::FramebufferObject(Uint externalIndex) : m_externalIndex(externalIndex) {
m_attachments.fill(FramebufferAttachment(false));
}
@@ -135,6 +135,9 @@ namespace MobileGL {
return m_drawBuffers;
}
Uint FramebufferObject::GetExternalIndex() const {
return m_externalIndex;
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -82,7 +82,7 @@ namespace MobileGL {
public:
using TargetEnum = FramebufferTarget;
FramebufferObject();
FramebufferObject(Uint externalIndex);
void AttachTexture(FramebufferAttachmentType type, SharedPtr<ITextureObject> texture, int level = 0);
void AttachRenderbuffer(FramebufferAttachmentType type,
@@ -95,8 +95,10 @@ namespace MobileGL {
Bool CheckCompleteness() const;
void SetDrawBuffers(const std::vector<FramebufferAttachmentType>& buffers);
const Vector<FramebufferAttachmentType>& GetDrawBuffers() const;
Uint GetExternalIndex() const;
private:
const Uint m_externalIndex = 0;
Array<FramebufferAttachment,
static_cast<SizeT>(FramebufferAttachmentType::FramebufferAttachmentTypeCount)>
m_attachments;
@@ -32,7 +32,7 @@ namespace MobileGL {
return nullptr;
}
}
auto bufferObject = MakeShared<FramebufferObject>();
auto bufferObject = MakeShared<FramebufferObject>(index);
m_framebufferObjects[index] = bufferObject;
return bufferObject;
}
@@ -9,7 +9,7 @@ namespace MobileGL {
namespace GLState {
class ProgramObject {
public:
ProgramObject(const Uint id) : m_id(id) {}
ProgramObject(const Uint externalIndex) : m_externalIndex(externalIndex) {}
bool ShaderIsAttached(SharedPtr<ShaderObject> shader);
bool AttachShader(SharedPtr<ShaderObject> shader);
SizeT DetachShader(SharedPtr<ShaderObject> shader);
@@ -78,11 +78,14 @@ namespace MobileGL {
Vector<Vector<unsigned>>& GetGeneratedSpirv() { return m_generatedSpirv; }
Uint GetExternalIndex() const { return m_externalIndex; }
private:
void DoReflection();
void GenerateBinary();
void WaitUntilGenerationCompleted();
const Uint m_id = 0;
const Uint m_externalIndex = 0;
Vector<SharedPtr<ShaderObject>> m_shaders;
SharedPtr<glslang::TProgram> m_program;
@@ -16,13 +16,14 @@ namespace MobileGL {
namespace GLState {
class ShaderObject {
public:
ShaderObject(const ShaderStage stage, const Uint id) : m_stage(stage), m_id(id) {}
ShaderObject(const ShaderStage stage, const Uint externalIndex)
: m_stage(stage), m_externalIndex(externalIndex) {}
void SetShaderSource(const String& source);
void SetShaderSource(String&& source);
void Compile();
void MarkAsDeleted();
Uint GetId() const { return m_id; }
Uint GetExternalIndex() const { return m_externalIndex; }
ShaderStage GetShaderStage() const { return m_stage; }
const String& GetShaderSource() const { return m_source; }
SharedPtr<glslang::TShader> GetCompiledShader() const { return m_shader; }
@@ -32,7 +33,7 @@ namespace MobileGL {
Bool GetDeleteStatus() const { return m_deleteStatus; }
private:
const Uint m_id = 0;
const Uint m_externalIndex = 0;
const ShaderStage m_stage;
String m_source;
SharedPtr<glslang::TShader> m_shader;
@@ -5,7 +5,8 @@ namespace MobileGL {
namespace MG_State {
namespace GLState {
// TextureObjectBase implementations
TextureObjectBase::TextureObjectBase(TextureTarget target) : m_target(target) {
TextureObjectBase::TextureObjectBase(TextureTarget target, Uint externalIndex)
: m_target(target), m_externalIndex(externalIndex) {
m_sampler = MakeShared<SamplerObject>();
}
@@ -75,7 +76,8 @@ namespace MobileGL {
}
// TextureObject1D
TextureObject1D::TextureObject1D() : TextureObjectBase(TextureTarget::Texture1D) {}
TextureObject1D::TextureObject1D(Uint externalIndex)
: TextureObjectBase(TextureTarget::Texture1D, externalIndex) {}
void TextureObject1D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0) {
@@ -84,7 +86,8 @@ namespace MobileGL {
}
// TextureObject2D
TextureObject2D::TextureObject2D() : TextureObjectBase(TextureTarget::Texture2D) {}
TextureObject2D::TextureObject2D(Uint externalIndex)
: TextureObjectBase(TextureTarget::Texture2D, externalIndex) {}
void TextureObject2D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0 && level.size.y() > 0) {
@@ -93,7 +96,8 @@ namespace MobileGL {
}
// TextureObject3D
TextureObject3D::TextureObject3D() : TextureObjectBase(TextureTarget::Texture3D) {}
TextureObject3D::TextureObject3D(Uint externalIndex)
: TextureObjectBase(TextureTarget::Texture3D, externalIndex) {}
void TextureObject3D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0 && level.size.y() > 0 && level.size.z() > 0) {
@@ -1,4 +1,5 @@
#pragma once
#include "MG_Util/Types.h"
#include "SamplerObject.h"
#include <Includes.h>
#include <MG_Util/Math/VectorTypes.h>
@@ -213,11 +214,12 @@ namespace MobileGL {
virtual void SetInternalFormat(TextureInternalFormat format) = 0;
virtual Bool IsComplete() const = 0;
virtual void UnmarkMipmapDirty(Int index) = 0;
virtual Uint GetExternalIndex() const = 0;
};
class TextureObjectBase : public ITextureObject {
public:
TextureObjectBase(TextureTarget target);
TextureObjectBase(TextureTarget target, Uint externalIndex);
virtual ~TextureObjectBase() = default;
void SetMipmapLevel(const MipmapLevelInput& level) override;
@@ -230,10 +232,12 @@ namespace MobileGL {
void SetInternalFormat(TextureInternalFormat format) override;
Bool IsComplete() const override;
void UnmarkMipmapDirty(Int index) override;
Uint GetExternalIndex() const override;
protected:
virtual void SetMipmapImpl(const MipmapLevelInput& level) = 0;
const Uint m_externalIndex;
const TextureTarget m_target = TextureTarget::Unknown;
TextureInternalFormat m_internalFormat = TextureInternalFormat::Unknown;
Vector<MipmapLevelInternal> m_mipmaps = {};
@@ -242,7 +246,7 @@ namespace MobileGL {
class TextureObject1D : public TextureObjectBase {
public:
explicit TextureObject1D();
explicit TextureObject1D(Uint externalIndex);
protected:
void SetMipmapImpl(const MipmapLevelInput& level) override;
@@ -250,7 +254,7 @@ namespace MobileGL {
class TextureObject2D : public TextureObjectBase {
public:
explicit TextureObject2D();
explicit TextureObject2D(Uint externalIndex);
protected:
void SetMipmapImpl(const MipmapLevelInput& level) override;
@@ -258,7 +262,7 @@ namespace MobileGL {
class TextureObject3D : public TextureObjectBase {
public:
explicit TextureObject3D();
explicit TextureObject3D(Uint externalIndex);
protected:
void SetMipmapImpl(const MipmapLevelInput& level) override;
@@ -29,13 +29,13 @@ namespace MobileGL {
SharedPtr<ITextureObject> textureObject = nullptr;
switch (target) {
case TextureTarget::Texture1D:
textureObject = MakeShared<TextureObject1D>();
textureObject = MakeShared<TextureObject1D>(index);
break;
case TextureTarget::Texture2D:
textureObject = MakeShared<TextureObject2D>();
textureObject = MakeShared<TextureObject2D>(index);
break;
case TextureTarget::Texture3D:
textureObject = MakeShared<TextureObject3D>();
textureObject = MakeShared<TextureObject3D>(index);
break;
default:
// TODO: implement more texture types
@@ -3,7 +3,7 @@
namespace MobileGL {
namespace MG_State {
namespace GLState {
VertexArrayObject::VertexArrayObject() {
VertexArrayObject::VertexArrayObject(Uint externIndex) : m_externalIndex(externIndex) {
for (int index = 0; index < MAX_VERTEX_ATTRIBS; ++index) {
auto& attr = m_attributes[index];
attr.Enabled = false;
@@ -90,6 +90,10 @@ namespace MobileGL {
void VertexArrayObject::ClearDirtyAttributes() {
m_dirtyAttributes.clear();
}
Uint VertexArrayObject::GetExternalIndex() const {
return m_externalIndex;
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -20,7 +20,7 @@ namespace MobileGL {
public:
static constexpr int MAX_VERTEX_ATTRIBS = 16;
VertexArrayObject();
VertexArrayObject(Uint externIndex);
void EnableAttribute(Uint index);
void DisableAttribute(Uint index);
@@ -38,10 +38,12 @@ namespace MobileGL {
const Vector<Uint>& GetDirtyAttributeIndices() const;
void ClearDirtyAttributes();
Uint GetExternalIndex() const;
private:
void MarkAttributeDirty(Uint index);
const Uint m_externalIndex = 0;
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
Vector<Uint> m_dirtyAttributes;
BindingSlot<BufferObject> m_indexBufferBindingSlot;
@@ -7,7 +7,7 @@ namespace MobileGL {
// Generate default VAO at index 0, which is not valid in core profile, but still remains for
// compatibility reasons.
m_indexGenerator.Insert(0);
auto defaultVAO = MakeShared<VertexArrayObject>();
auto defaultVAO = MakeShared<VertexArrayObject>(0);
m_vertexArrays.push_back(defaultVAO);
m_boundVertexArray = defaultVAO;
}
@@ -36,7 +36,7 @@ namespace MobileGL {
m_vertexArrays.reserve(std::bit_ceil(index + 1));
m_vertexArrays.resize(index + 1, nullptr);
}
auto vao = m_vertexArrays[index] = MakeShared<VertexArrayObject>();
auto vao = m_vertexArrays[index] = MakeShared<VertexArrayObject>(index);
return vao;
}