mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Feat] (MG_Backend/DirectGLES): sync tex buffer to backend
This commit is contained in:
@@ -386,7 +386,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
// Bind texture object
|
// Bind texture object
|
||||||
auto target = textureObject->GetTarget();
|
auto target = textureObject->GetTarget();
|
||||||
if (target == TextureTarget::TextureBuffer || target == TextureTarget::Texture1D ||
|
if (target == TextureTarget::Texture1D ||
|
||||||
target == TextureTarget::TextureRectangle || target == TextureTarget::Texture2DMultisampleArray ||
|
target == TextureTarget::TextureRectangle || target == TextureTarget::Texture2DMultisampleArray ||
|
||||||
target == TextureTarget::Texture1DArray || target == TextureTarget::Texture3D ||
|
target == TextureTarget::Texture1DArray || target == TextureTarget::Texture3D ||
|
||||||
target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DArray) {
|
target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DArray) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include "MG_Backend/Backends.h"
|
#include "MG_Backend/Backends.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "DirectGLES.h"
|
#include "DirectGLES.h"
|
||||||
|
#include "MG_State/GLState/TextureState/TextureObjectBuffer.h"
|
||||||
|
|
||||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||||
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
|
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
|
||||||
#include <MG_Util/Converters/MGToStr/TextureEnumConverter.h>
|
#include <MG_Util/Converters/MGToStr/TextureEnumConverter.h>
|
||||||
@@ -262,7 +264,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
auto targetInternal = stateTextureObject->GetTarget();
|
auto targetInternal = stateTextureObject->GetTarget();
|
||||||
MGLOG_D(" Texture target for syncing is %s",
|
MGLOG_D(" Texture target for syncing is %s",
|
||||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||||
if (targetInternal == TextureTarget::TextureBuffer || targetInternal == TextureTarget::Texture1D ||
|
if (targetInternal == TextureTarget::Texture1D ||
|
||||||
targetInternal == TextureTarget::TextureRectangle ||
|
targetInternal == TextureTarget::TextureRectangle ||
|
||||||
targetInternal == TextureTarget::Texture2DMultisampleArray ||
|
targetInternal == TextureTarget::Texture2DMultisampleArray ||
|
||||||
targetInternal == TextureTarget::Texture1DArray || targetInternal == TextureTarget::Texture3D ||
|
targetInternal == TextureTarget::Texture1DArray || targetInternal == TextureTarget::Texture3D ||
|
||||||
@@ -292,7 +294,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
const auto baseSize = stateTextureObject->GetBaseSize();
|
const auto baseSize = stateTextureObject->GetBaseSize();
|
||||||
StateTextureBasicInfo currentTextureInfo = {
|
StateTextureBasicInfo currentTextureInfo = {
|
||||||
stateTextureObject->GetFormat(), static_cast<SizeT>(baseSize.x()), static_cast<SizeT>(baseSize.y()),
|
stateTextureObject->GetFormat(), static_cast<SizeT>(baseSize.x()), static_cast<SizeT>(baseSize.y()),
|
||||||
static_cast<SizeT>(baseSize.z()), 0};
|
static_cast<SizeT>(baseSize.z()), 0, 0};
|
||||||
switch (stateTextureObject->GetStorageType()) {
|
switch (stateTextureObject->GetStorageType()) {
|
||||||
case TextureStorageType::Mipmap: {
|
case TextureStorageType::Mipmap: {
|
||||||
auto* textureMipmapObject = static_cast<MG_State::GLState::TextureObjectMipmap*>(stateTextureObject.get());
|
auto* textureMipmapObject = static_cast<MG_State::GLState::TextureObjectMipmap*>(stateTextureObject.get());
|
||||||
@@ -385,6 +387,39 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TextureStorageType::Buffer: {
|
||||||
|
auto* textureBufferObject = static_cast<MG_State::GLState::TextureObjectBuffer*>(stateTextureObject.get());
|
||||||
|
auto& slot = textureBufferObject->GetBufferBindingSlot();
|
||||||
|
auto buffer = slot.GetBoundObject();
|
||||||
|
auto bufferIndex = buffer->GetExternalIndex();
|
||||||
|
currentTextureInfo.bufferExternalIndex = bufferIndex;
|
||||||
|
|
||||||
|
Bool needsRegeneration = !m_isInitialized || (currentTextureInfo != m_prevTextureInfo);
|
||||||
|
MGLOG_D("Texture state changed significantly or not initialized, regenerating texture (tex buffer) with ID: %u",
|
||||||
|
m_backendTextureId);
|
||||||
|
|
||||||
|
// Need to sync texture buffer if not synced yet
|
||||||
|
auto& backendBuffers = BufferImpl::g_backendBufferObjects;
|
||||||
|
SharedPtr<BufferImpl::BackendBufferObject> backendBufferObject;
|
||||||
|
const auto& backendBufferIt = backendBuffers.find(buffer);
|
||||||
|
if (backendBufferIt == backendBuffers.end()) {
|
||||||
|
backendBufferObject = MakeShared<BufferImpl::BackendBufferObject>();
|
||||||
|
backendBuffers[buffer] = backendBufferObject;
|
||||||
|
} else {
|
||||||
|
backendBufferObject = backendBufferIt->second;
|
||||||
|
}
|
||||||
|
backendBufferObject->SyncToBackend(buffer);
|
||||||
|
|
||||||
|
// Bind buffer to texture
|
||||||
|
auto backendId = backendBufferObject->GetBackendBufferId();
|
||||||
|
|
||||||
|
GLenum glInternalFormat, glType, glFormat;
|
||||||
|
TextureImpl::GenerateTextureFormatInfo(textureBufferObject->GetFormat(), &glInternalFormat, &glType,
|
||||||
|
&glFormat);
|
||||||
|
|
||||||
|
MG_External::GLES::glTexBuffer(GL_TEXTURE_BUFFER, glInternalFormat, backendId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: THROW_UNIMPL_EXCEPTION;
|
default: THROW_UNIMPL_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,10 +54,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
SizeT height = 0;
|
SizeT height = 0;
|
||||||
SizeT depth = 0;
|
SizeT depth = 0;
|
||||||
SizeT mipmapLevels = 0;
|
SizeT mipmapLevels = 0;
|
||||||
|
Uint bufferExternalIndex = 0;
|
||||||
|
|
||||||
bool operator==(const StateTextureBasicInfo& other) const {
|
bool operator==(const StateTextureBasicInfo& other) const {
|
||||||
return internalFormat == other.internalFormat && width == other.width && height == other.height &&
|
return internalFormat == other.internalFormat && width == other.width && height == other.height &&
|
||||||
depth == other.depth && mipmapLevels == other.mipmapLevels;
|
depth == other.depth && mipmapLevels == other.mipmapLevels && bufferExternalIndex == other.bufferExternalIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const StateTextureBasicInfo& other) const { return !(*this == other); }
|
bool operator!=(const StateTextureBasicInfo& other) const { return !(*this == other); }
|
||||||
|
|||||||
@@ -317,6 +317,8 @@ namespace MobileGL {
|
|||||||
return TextureUploadTarget::CubeMapPositiveZ;
|
return TextureUploadTarget::CubeMapPositiveZ;
|
||||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
||||||
return TextureUploadTarget::CubeMapNegativeZ;
|
return TextureUploadTarget::CubeMapNegativeZ;
|
||||||
|
case GL_TEXTURE_BUFFER:
|
||||||
|
return TextureUploadTarget::TextureBuffer;
|
||||||
case GL_PROXY_TEXTURE_CUBE_MAP:
|
case GL_PROXY_TEXTURE_CUBE_MAP:
|
||||||
return TextureUploadTarget::ProxyCubeMap;
|
return TextureUploadTarget::ProxyCubeMap;
|
||||||
case GL_TEXTURE_2D_MULTISAMPLE:
|
case GL_TEXTURE_2D_MULTISAMPLE:
|
||||||
|
|||||||
Reference in New Issue
Block a user