mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Fix] (MG_Backend/DirectGLES): Bind current state.
This commit is contained in:
@@ -70,20 +70,21 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
namespace TextureImpl {
|
namespace TextureImpl {
|
||||||
void SyncNeccessaryTextures() {
|
void SyncNeccessaryTextures() {
|
||||||
// All textures we need are:
|
// All textures we need are:
|
||||||
// 1. textures bound to current texture units (TODO: only sync ones that are used in current program)
|
// 1. textures bound to texture units (TODO: only sync ones that are used in current program)
|
||||||
// 2. textures used in current FBO
|
// 2. textures used in current FBO
|
||||||
// 3. textures bound to image units (TODO)
|
// 3. textures bound to image units (TODO)
|
||||||
|
|
||||||
Vector<SharedPtr<MG_State::GLState::ITextureObject>> texturesToSync;
|
Vector<SharedPtr<MG_State::GLState::ITextureObject>> texturesToSync;
|
||||||
|
|
||||||
auto& currentUnit =
|
for (int index = 0; index < MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS; ++index) {
|
||||||
MG_State::pGLContext->GetTextureUnitObject(MG_State::pGLContext->GetActiveTextureUnit());
|
auto& unit = MG_State::pGLContext->GetTextureUnitObject(index);
|
||||||
for (auto& bindingSlot : currentUnit.GetAllBindingSlots()) {
|
for (auto& bindingSlot : unit.GetAllBindingSlots()) {
|
||||||
const auto& textureObject = bindingSlot.GetBoundObject();
|
const auto& textureObject = bindingSlot.GetBoundObject();
|
||||||
if (textureObject) {
|
if (textureObject) {
|
||||||
texturesToSync.push_back(textureObject);
|
texturesToSync.push_back(textureObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const auto& currentFBO =
|
const auto& currentFBO =
|
||||||
MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject();
|
MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject();
|
||||||
@@ -134,29 +135,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
namespace RenderStateImpl {
|
namespace RenderStateImpl {
|
||||||
void SyncRenderState() {
|
void SyncRenderState() {
|
||||||
/*
|
|
||||||
void SetViewport(IntVec4 viewport); // x, y, width, height
|
|
||||||
const IntVec4& GetViewport() const; // x, y, width, height
|
|
||||||
void SetCapability(CapabilityInput cap, Bool enabled);
|
|
||||||
Bool IsCapabilityEnabled(CapabilityInput cap) const;
|
|
||||||
void SetBlendFunc(BlendFactor srcRGB, BlendFactor dstRGB, BlendFactor srcAlpha, BlendFactor dstAlpha);
|
|
||||||
void GetBlendFunc(BlendFactor& srcRGB, BlendFactor& dstRGB, BlendFactor& srcAlpha,
|
|
||||||
BlendFactor& dstAlpha) const;
|
|
||||||
void SetDepthFunc(DepthTestFunc func);
|
|
||||||
DepthTestFunc GetDepthFunc() const;
|
|
||||||
void SetDepthMask(Bool flag);
|
|
||||||
Bool GetDepthMask() const;
|
|
||||||
void SetColorMask(BoolVec4 mask);
|
|
||||||
const BoolVec4 GetColorMask() const;
|
|
||||||
void SetClearColor(FloatVec4 color);
|
|
||||||
const FloatVec4& GetClearColor() const;
|
|
||||||
void SetClearDepth(Float depth);
|
|
||||||
Float GetClearDepth() const;
|
|
||||||
void SetPixelStoreParam(PixelStoreParam param, Int value);
|
|
||||||
Int GetPixelStoreParam(PixelStoreParam param) const;
|
|
||||||
void SetCullFaceMode(CullFaceMode mode);
|
|
||||||
CullFaceMode GetCullFaceMode() const;*/
|
|
||||||
|
|
||||||
MG_External::GLES::glViewport(
|
MG_External::GLES::glViewport(
|
||||||
MG_State::pGLContext->GetViewport().x(), MG_State::pGLContext->GetViewport().y(),
|
MG_State::pGLContext->GetViewport().x(), MG_State::pGLContext->GetViewport().y(),
|
||||||
MG_State::pGLContext->GetViewport().z(), MG_State::pGLContext->GetViewport().w());
|
MG_State::pGLContext->GetViewport().z(), MG_State::pGLContext->GetViewport().w());
|
||||||
@@ -256,7 +234,49 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
TextureImpl::SyncNeccessaryTextures();
|
TextureImpl::SyncNeccessaryTextures();
|
||||||
FramebufferImpl::SyncCurrentFBO();
|
FramebufferImpl::SyncCurrentFBO();
|
||||||
PrgramImpl::SyncCurrentProgram();
|
PrgramImpl::SyncCurrentProgram();
|
||||||
RenderStateImpl::SyncRenderState();
|
|
||||||
|
auto currentFBO = MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject();
|
||||||
|
if (currentFBO) {
|
||||||
|
auto backendFBOIt = FramebufferImpl::g_backendFramebufferObjects.find(currentFBO);
|
||||||
|
if (backendFBOIt != FramebufferImpl::g_backendFramebufferObjects.end()) {
|
||||||
|
backendFBOIt->second->Bind();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MG_External::GLES::glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto currentVAO = MG_State::pGLContext->GetBoundVertexArray();
|
||||||
|
if (currentVAO) {
|
||||||
|
auto backendVAOIt = VertexArrayImpl::g_backendVertexArrayObjects.find(currentVAO);
|
||||||
|
if (backendVAOIt != VertexArrayImpl::g_backendVertexArrayObjects.end()) {
|
||||||
|
backendVAOIt->second->Bind();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MG_External::GLES::glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Int maxTextureUnits = MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS;
|
||||||
|
for (Int unit = 0; unit < maxTextureUnits; ++unit) {
|
||||||
|
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
||||||
|
if (!textureUnit.GetBindingSlot(TextureTarget::Texture2D).GetBoundObject()) continue;
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
|
|
||||||
|
for (auto& bindingSlot : textureUnit.GetAllBindingSlots()) {
|
||||||
|
auto textureObject = bindingSlot.GetBoundObject();
|
||||||
|
if (!textureObject) continue;
|
||||||
|
|
||||||
|
auto backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject);
|
||||||
|
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) continue;
|
||||||
|
|
||||||
|
GLenum target = MG_Util::ConvertTextureTargetToGLEnum(textureObject->GetTarget());
|
||||||
|
backendTextureIt->second->Bind(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Int originalActiveUnit = MG_State::pGLContext->GetActiveTextureUnit();
|
||||||
|
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + originalActiveUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) {
|
void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
public:
|
public:
|
||||||
BackendBufferObject();
|
BackendBufferObject();
|
||||||
void SyncToBackend(SharedPtr<MG_State::GLState::BufferObject>& stateBufferObject);
|
void SyncToBackend(SharedPtr<MG_State::GLState::BufferObject>& stateBufferObject);
|
||||||
|
Uint GetBackendBufferId() { return m_backendBufferId; }
|
||||||
void Bind();
|
void Bind();
|
||||||
void Bind(GLenum target);
|
void Bind(GLenum target);
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
public:
|
public:
|
||||||
BackendVertexArrayObject();
|
BackendVertexArrayObject();
|
||||||
void SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject);
|
void SyncToBackend(SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject);
|
||||||
|
Uint GetBackendVertexArrayId() { return m_backendVAOId; }
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -82,6 +84,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
public:
|
public:
|
||||||
BackendFramebufferObject();
|
BackendFramebufferObject();
|
||||||
void SyncToBackend(SharedPtr<MG_State::GLState::FramebufferObject>& stateFBOObject);
|
void SyncToBackend(SharedPtr<MG_State::GLState::FramebufferObject>& stateFBOObject);
|
||||||
|
Uint GetBackendFramebufferId() { return m_backendFBOId; }
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user