/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
gl->GenTextures(1, &texture);
context->BindTexture(GL_TEXTURE_2D, GetTextureTypeId(), texture);
- // Allocate memory for the texture
- if(!mIsCompressed)
+ if(mCreateInfo.allocationPolicy == Graphics::TextureAllocationPolicy::CREATION || mCreateInfo.data)
{
- gl->TexImage2D(GL_TEXTURE_2D,
- 0,
- format.internalFormat,
- mCreateInfo.size.width,
- mCreateInfo.size.height,
- 0,
- format.format,
- format.type,
- (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
- }
- else
- {
- gl->CompressedTexImage2D(GL_TEXTURE_2D,
- 0,
- format.internalFormat,
- mCreateInfo.size.width,
- mCreateInfo.size.height,
- 0,
- mCreateInfo.dataSize,
- (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ // Allocate memory for the texture
+ if(!mIsCompressed)
+ {
+ gl->TexImage2D(GL_TEXTURE_2D,
+ 0,
+ format.internalFormat,
+ mCreateInfo.size.width,
+ mCreateInfo.size.height,
+ 0,
+ format.format,
+ format.type,
+ (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ }
+ else
+ {
+ gl->CompressedTexImage2D(GL_TEXTURE_2D,
+ 0,
+ format.internalFormat,
+ mCreateInfo.size.width,
+ mCreateInfo.size.height,
+ 0,
+ mCreateInfo.dataSize,
+ (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ }
}
// Clear staging buffer if there was any
SetSamplerParameter(GL_TEXTURE_WRAP_S, mDefaultSamplerState.wrapS, GL_WRAP_DEFAULT);
SetSamplerParameter(GL_TEXTURE_WRAP_T, mDefaultSamplerState.wrapT, GL_WRAP_DEFAULT);
- // Allocate memory for the texture
- for(uint32_t i = 0; i < 6; ++i)
+ if(mCreateInfo.allocationPolicy == Graphics::TextureAllocationPolicy::CREATION || mCreateInfo.data)
{
- if(!mIsCompressed)
+ // Allocate memory for the texture
+ for(uint32_t i = 0; i < 6; ++i)
{
- gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
- 0,
- format.internalFormat,
- mCreateInfo.size.width,
- mCreateInfo.size.height,
- 0,
- format.format,
- format.type,
- (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
- }
- else
- {
- gl->CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
- 0,
- format.internalFormat,
- mCreateInfo.size.width,
- mCreateInfo.size.height,
- 0,
- mCreateInfo.dataSize,
- (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ if(!mIsCompressed)
+ {
+ gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+ 0,
+ format.internalFormat,
+ mCreateInfo.size.width,
+ mCreateInfo.size.height,
+ 0,
+ format.format,
+ format.type,
+ (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ }
+ else
+ {
+ gl->CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+ 0,
+ format.internalFormat,
+ mCreateInfo.size.width,
+ mCreateInfo.size.height,
+ 0,
+ mCreateInfo.dataSize,
+ (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+ }
}
}
auto mipMapMode = samplerCreateInfo.mipMapMode;
+ // @todo : Should we always ignore mipmap mode when it is compressed, and never bind higher level mipmap?
+ if(mMaxMipMapLevel == 0u && mIsCompressed)
+ {
+ mipMapMode = Graphics::SamplerMipmapMode::NONE;
+ }
+
SetSamplerParameter(GL_TEXTURE_MIN_FILTER, mDefaultSamplerState.minFilter, GLSamplerFilterAndMipMapMode(samplerCreateInfo.minFilter, mipMapMode).glFilter);
SetSamplerParameter(GL_TEXTURE_MAG_FILTER, mDefaultSamplerState.magFilter, GLSamplerFilter(samplerCreateInfo.magFilter).glFilter);
SetSamplerParameter(GL_TEXTURE_WRAP_S, mDefaultSamplerState.wrapS, GLAddressMode(samplerCreateInfo.addressModeU).texParameter);
NativeImageInterfacePtr nativeImage = mCreateInfo.nativeImagePtr;
if(nativeImage)
{
- if(nativeImage->SourceChanged())
- {
- // Update size
- uint32_t width = mCreateInfo.nativeImagePtr->GetWidth();
- uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
- mCreateInfo.SetSize({width, height}); // Size may change
- }
-
nativeImage->PrepareTexture();
}
}
void Texture::SetSamplerParameter(uint32_t param, uint32_t& cacheValue, uint32_t value) const
{
- if(cacheValue != value)
+ auto gl = mController.GetGL();
+ if(gl && cacheValue != value)
{
- auto gl = mController.GetGL();
gl->TexParameteri(mGlTarget, param, value);
cacheValue = value;
}