mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Feat] (MG_Backend/DirectGLES): implement glGenerateMipmap
This commit is contained in:
@@ -112,6 +112,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
} // namespace VertexArrayImpl
|
} // namespace VertexArrayImpl
|
||||||
|
|
||||||
namespace TextureImpl {
|
namespace TextureImpl {
|
||||||
|
SharedPtr<BackendTextureObject> SyncTextureObjectToBackend(SharedPtr<MG_State::GLState::ITextureObject>& textureObject) {
|
||||||
|
const auto& backendTextureIt = g_backendTextureObjects.find(textureObject);
|
||||||
|
SharedPtr<BackendTextureObject> backendTextureObject;
|
||||||
|
if (backendTextureIt == g_backendTextureObjects.end()) {
|
||||||
|
backendTextureObject = MakeShared<BackendTextureObject>();
|
||||||
|
g_backendTextureObjects[textureObject] = backendTextureObject;
|
||||||
|
} else {
|
||||||
|
backendTextureObject = backendTextureIt->second;
|
||||||
|
}
|
||||||
|
backendTextureObject->SyncToBackend(textureObject);
|
||||||
|
return backendTextureObject;
|
||||||
|
}
|
||||||
|
|
||||||
void SyncNeccessaryTextures() {
|
void SyncNeccessaryTextures() {
|
||||||
// All textures we need are:
|
// All textures we need are:
|
||||||
// 1. textures bound to 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)
|
||||||
@@ -144,15 +157,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
// Do real sync
|
// Do real sync
|
||||||
for (auto& textureObject : texturesToSync) {
|
for (auto& textureObject : texturesToSync) {
|
||||||
const auto& backendTextureIt = g_backendTextureObjects.find(textureObject);
|
SyncTextureObjectToBackend(textureObject);
|
||||||
SharedPtr<BackendTextureObject> backendTextureObject;
|
|
||||||
if (backendTextureIt == g_backendTextureObjects.end()) {
|
|
||||||
backendTextureObject = MakeShared<BackendTextureObject>();
|
|
||||||
g_backendTextureObjects[textureObject] = backendTextureObject;
|
|
||||||
} else {
|
|
||||||
backendTextureObject = backendTextureIt->second;
|
|
||||||
}
|
|
||||||
backendTextureObject->SyncToBackend(textureObject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace TextureImpl
|
} // namespace TextureImpl
|
||||||
@@ -486,14 +491,30 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
|
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
|
||||||
GLint dstY1, GLbitfield mask, GLenum filter) {
|
GLint dstY1, GLbitfield mask, GLenum filter) {
|
||||||
|
DebugImpl::ErrorLopper errorLopper;
|
||||||
|
|
||||||
TextureImpl::SyncNeccessaryTextures();
|
TextureImpl::SyncNeccessaryTextures();
|
||||||
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
});
|
||||||
FramebufferImpl::SyncCurrentFBO();
|
FramebufferImpl::SyncCurrentFBO();
|
||||||
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
});
|
||||||
RenderStateImpl::SyncRenderState();
|
RenderStateImpl::SyncRenderState();
|
||||||
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
});
|
||||||
|
|
||||||
BindCurrentFBO(FramebufferTarget::Draw);
|
BindCurrentFBO(FramebufferTarget::Draw);
|
||||||
BindCurrentFBO(FramebufferTarget::Read);
|
BindCurrentFBO(FramebufferTarget::Read);
|
||||||
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
});
|
||||||
MG_External::GLES::glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
|
MG_External::GLES::glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
|
||||||
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
|
void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
|
||||||
@@ -662,6 +683,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GenerateMipmap(GLenum target) {
|
||||||
|
auto unitIndex = MG_State::pGLContext->GetActiveTextureUnit();
|
||||||
|
auto& unit = MG_State::pGLContext->GetTextureUnitObject(unitIndex);
|
||||||
|
auto& slot = unit.GetBindingSlot(MG_Util::ConvertGLEnumToTextureTarget(target));
|
||||||
|
auto texture = slot.GetBoundObject();
|
||||||
|
auto backendTexture = TextureImpl::SyncTextureObjectToBackend(texture);
|
||||||
|
|
||||||
|
TextureImpl::BackendTextureBindingProtector protector(target);
|
||||||
|
backendTexture->Bind(target);
|
||||||
|
MG_External::GLES::glGenerateMipmap(target);
|
||||||
|
}
|
||||||
|
|
||||||
const GLubyte* GetString(GLenum name) {
|
const GLubyte* GetString(GLenum name) {
|
||||||
return MG_External::GLES::glGetString(name);
|
return MG_External::GLES::glGetString(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
GLsizei height, GLint border);
|
GLsizei height, GLint border);
|
||||||
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y,
|
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y,
|
||||||
GLsizei width, GLsizei height);
|
GLsizei width, GLsizei height);
|
||||||
|
void GenerateMipmap(GLenum target);
|
||||||
const GLubyte* GetString(GLenum name);
|
const GLubyte* GetString(GLenum name);
|
||||||
} // namespace MobileGL::MG_Backend::DirectGLES
|
} // namespace MobileGL::MG_Backend::DirectGLES
|
||||||
@@ -46,8 +46,10 @@ namespace MobileGL {
|
|||||||
// TODO: implement
|
// TODO: implement
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateMipmap_State(GLenum target) {
|
void GenerateMipmap_Backend(GLenum target) {
|
||||||
// TODO: implement
|
#if MOBILEGL_BACKEND == MOBILEGL_BACKEND_TYPE_DIRECT_GLES
|
||||||
|
MG_Backend::DirectGLES::GenerateMipmap(target);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenRenderbuffers_State(GLsizei n, GLuint* renderbuffers) {
|
void GenRenderbuffers_State(GLsizei n, GLuint* renderbuffers) {
|
||||||
@@ -325,7 +327,7 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GenerateMipmap(GLenum target) {
|
void GenerateMipmap(GLenum target) {
|
||||||
GenerateMipmap_State(target);
|
GenerateMipmap_Backend(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenRenderbuffers(GLsizei n, GLuint* renderbuffers) {
|
void GenRenderbuffers(GLsizei n, GLuint* renderbuffers) {
|
||||||
|
|||||||
Reference in New Issue
Block a user