mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Fix] (MG_State/TextureObject): fix silly tex input data bug introduced by the refractor
This commit is contained in:
@@ -599,15 +599,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
auto textureObject = bindingSlot.GetBoundObject();
|
||||
|
||||
|
||||
const SizeT bytesPerPixel = MG_Util::GetInputBytesPerPixel(mglInternalFormat, texturePixelDataType);
|
||||
const SizeT totalBytes = width * height * bytesPerPixel;
|
||||
// const SizeT bytesPerPixel = MG_Util::GetInputBytesPerPixel(mglInternalFormat, texturePixelDataType);
|
||||
// const SizeT totalBytes = width * height * bytesPerPixel;
|
||||
|
||||
// MG_State::GLState::MipmapLevelInput mipmap =
|
||||
// MG_State::GLState::MipmapLevelInput({width, height, 1}, level, false, 0,
|
||||
// {nullptr, totalBytes});
|
||||
|
||||
textureObject->SetInternalFormat(mglInternalFormat);
|
||||
textureObject->AllocateStorage(TextureUploadTarget::Texture2D, level, {{width, height, 1}, totalBytes});
|
||||
textureObject->AllocateStorage(TextureUploadTarget::Texture2D, level, {{width, height, 1}, 0});
|
||||
}
|
||||
|
||||
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "DirectGLES.h"
|
||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
|
||||
#include <MG_Util/Converters/MGToStr/TextureEnumConverter.h>
|
||||
#include <MG_Util/Converters/MGToGL/DataTypeConverter.h>
|
||||
#include <MG_Util/Converters/MGToGL/BufferEnumConverter.h>
|
||||
#include <MG_Util/Converters/MGToGL/TextureEnumConverter.h>
|
||||
@@ -282,6 +283,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
Bool needsRegeneration = !m_isInitialized || (currentTextureInfo != m_prevTextureInfo);
|
||||
|
||||
MGLOG_D("%s: Got texture info: %dx%dx%d, mips %d, format %s", __func__,
|
||||
baseSize.x(), baseSize.y(), baseSize.z(),
|
||||
mipmapCount,
|
||||
MG_Util::ConvertTextureInternalFormatToString(stateTextureObject->GetFormat()).c_str());
|
||||
|
||||
if (needsRegeneration) {
|
||||
MGLOG_D("Texture state changed significantly or not initialized, regenerating texture with ID: %u",
|
||||
m_backendTextureId);
|
||||
@@ -294,6 +300,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// TODO: deal with multiple upload target texture
|
||||
auto levelTexelSize = stateTextureObject->GetMipmapTexelSize(TextureUploadTarget::Texture2D, level);
|
||||
auto levelByteSize = stateTextureObject->GetMipmapByteSize(TextureUploadTarget::Texture2D, level);
|
||||
bool levelDirty = stateTextureObject->IsStorageDirty(TextureUploadTarget::Texture2D, 0);
|
||||
auto* pData = (levelDirty && levelByteSize != 0) ? stateTextureObject->MapMipmapData(TextureUploadTarget::Texture2D, level) : nullptr;
|
||||
MGLOG_D("%s: syncing mip %d: %dx%dx%d, byteSize = %d, pData = %p", __func__,
|
||||
level,
|
||||
levelTexelSize.x(), levelTexelSize.y(), levelTexelSize.z(),
|
||||
levelByteSize,
|
||||
pData);
|
||||
BufferImpl::BackendBufferBindingProtector pixelUnpackProtector =
|
||||
BufferImpl::BackendBufferBindingProtector(GL_PIXEL_UNPACK_BUFFER);
|
||||
errorLopper.Clear();
|
||||
@@ -301,7 +314,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MG_External::GLES::glTexImage2D(GL_TEXTURE_2D, static_cast<GLint>(level), glInternalFormat,
|
||||
static_cast<GLsizei>(levelTexelSize.x()),
|
||||
static_cast<GLsizei>(levelTexelSize.y()), 0, glFormat, glType,
|
||||
(levelByteSize != 0) ? stateTextureObject->MapMipmapData(TextureUploadTarget::Texture2D, level) : nullptr);
|
||||
pData);
|
||||
|
||||
// errorLopper.Loop([index = stateTextureObject->GetExternalIndex(), &mipmap, level, glInternalFormat, glFormat, glType, file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||
// MGLOG_D("%s(%s:%d) ES error: %s, texobj %d, mip %d (%dx%d, %s, %s, %s)", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str(),
|
||||
|
||||
@@ -382,8 +382,6 @@ namespace MobileGL {
|
||||
const SizeT totalBytes = width * height * bytesPerPixel;
|
||||
|
||||
textureObject->SetInternalFormat(textureInternalFormat);
|
||||
// Allocate in TextureObject
|
||||
textureObject->AllocateStorage(textureUploadingTarget, level, {{width, height, 1}, isProxy ? 0 : totalBytes});
|
||||
|
||||
// if isProxy, no more pixel transfer needed below
|
||||
if (isProxy)
|
||||
@@ -401,16 +399,19 @@ namespace MobileGL {
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
|
||||
void* processedPixels = nullptr;
|
||||
if (originalPixels) {
|
||||
processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack(
|
||||
originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel,
|
||||
{width, height, 1}, false, imageSize);
|
||||
} else {
|
||||
// Allocate in TextureObject
|
||||
textureObject->AllocateStorage(textureUploadingTarget, level, {{width, height, 1}, totalBytes});
|
||||
|
||||
if (!originalPixels) {
|
||||
MGLOG_D("TexImage2D_State: No input pixel and no PBO bound, no pixel transfer");
|
||||
return;
|
||||
}
|
||||
|
||||
void* processedPixels = nullptr;
|
||||
processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack(
|
||||
originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel,
|
||||
{width, height, 1}, false, imageSize);
|
||||
|
||||
if (processedPixels && imageSize > 0) {
|
||||
if (imageSize != totalBytes) {
|
||||
MGLOG_W("TexImage2D_State: Processed pixel data size (%zu) does not match expected size (%zu). "
|
||||
@@ -421,11 +422,8 @@ namespace MobileGL {
|
||||
const SizeT copySize = std::min(imageSize, totalBytes);
|
||||
DataPtr texelInput { processedPixels, copySize };
|
||||
textureObject->UpdateMipmapSubData(textureUploadingTarget, level, texelInput);
|
||||
} else if (originalPixels) {
|
||||
MGLOG_E("TexImage2D_State: Failed to process pixel data, initializing with original data.");
|
||||
DataPtr texelInput { (void*)originalPixels, totalBytes };
|
||||
textureObject->UpdateMipmapSubData(textureUploadingTarget, level, texelInput);
|
||||
}
|
||||
|
||||
free(processedPixels);
|
||||
|
||||
// MG_State::GLState::MipmapLevelInput mipmap =
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace MobileGL {
|
||||
// stencilTex->SetMipmapLevel({{512, 512, 1}, 0, false, 0, {nullptr, 0}});
|
||||
fbo0->AttachTexture(FramebufferAttachmentType::Color0, colorTex);
|
||||
fbo0->AttachTexture(FramebufferAttachmentType::Depth, depthTex);
|
||||
fbo0->AttachTexture(FramebufferAttachmentType::Depth, depthTex);
|
||||
fbo0->AttachTexture(FramebufferAttachmentType::Stencil, stencilTex);
|
||||
GLImpl::FramebufferImpl::pDefaultFramebufferInfo =
|
||||
new GLImpl::FramebufferImpl::DefaultFramebufferInfo(fbo0, colorTex, depthTex, stencilTex);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace MobileGL {
|
||||
targetTexelSizes.resize(level + 1);
|
||||
targetTexelSizes[level] = input.texelSize;
|
||||
auto& dirtyArr = m_isDirty[targetIndex];
|
||||
dirtyArr.resize(level + 1, true);
|
||||
dirtyArr.resize(level + 1, false);
|
||||
|
||||
auto& data = targetData[level];
|
||||
data.resize(input.byteSize, 0);
|
||||
@@ -49,7 +49,7 @@ namespace MobileGL {
|
||||
if (input.data && input.size > 0) {
|
||||
const Uint8* src = static_cast<const Uint8*>(input.data);
|
||||
Memcpy(levelData.data(), src, input.size);
|
||||
m_isDirty[targetIndex][level] = false;
|
||||
m_isDirty[targetIndex][level] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user