16 , _type( gl46core::GL_NONE )
27 if (_textureHandle > 0u)
34 gl46core::glDeleteTextures(1, &_textureHandle);
47 gl46core::glWaitSync(
_loadSync, gl46core::UnusedMask::GL_UNUSED_BIT, gl46core::GL_TIMEOUT_IGNORED);
59 const gl46core::GLuint msaaSamples =
static_cast<gl46core::GLuint
>(_descriptor._msaaSamples);
61 DIVIDE_ASSERT(!(isCubeMap && _width != _height) &&
"glTexture::reserverStorage error: width and height for cube map texture do not match!");
63 switch (_descriptor._texType )
79 if (msaaSamples == 0u) {
96 if (msaaSamples == 0u)
119 const U32 layerCount = isCubeMap ? _depth * 6 : _depth;
121 if (msaaSamples == 0u)
156 assert(
_loadingHandle != 0 &&
"glTexture error: failed to generate new texture handle!");
159 gl46core::glObjectLabel( gl46core::GL_TEXTURE,
_loadingHandle, -1, resourceName().c_str());
167 gl46core::glTextureParameteri(
_loadingHandle, gl46core::GL_TEXTURE_BASE_LEVEL, _descriptor._mipBaseLevel );
168 gl46core::glTextureParameteri(
_loadingHandle, gl46core::GL_TEXTURE_MAX_LEVEL, mipCount());
175 if (_textureHandle > 0u)
178 gl46core::glDeleteTextures(1, &_textureHandle);
200 for (
U32 l = 0u; l < numLayers; ++l )
203 for (
U8 m = 0u; m < numMips; ++m )
206 assert( mip->
_size > 0u );
215 const bool isCompressed =
IsCompressed( _descriptor._baseFormat );
219 DIVIDE_ASSERT( _descriptor._msaaSamples == 0u || data ==
nullptr);
231 switch ( _descriptor._texType )
235 assert(offset.
z == 0u);
249 assert( offset.
z == 0u );
267 gl46core::glCompressedTextureSubImage3D(
_loadingHandle, targetMip, offset.
x, offset.
y, offset.
z, dimensions.
width, dimensions.
height, dimensions.
depth, formatAndType.
_internalFormat,
static_cast<gl46core::GLsizei
>(size), data);
271 gl46core::glTextureSubImage3D(
_loadingHandle, targetMip, offset.
x, offset.
y, offset.
z, dimensions.
width, dimensions.
height, dimensions.
depth, formatAndType.
_internalFormat, formatAndType.
_dataType, data);
286 const auto GetClearData = [clearColour, &floatData, &shortData, &intData](
const GFXDataFormat format)
298 shortData = { clearColour.
r, clearColour.
g, clearColour.
b, clearColour.
a };
305 intData = { clearColour.
r, clearColour.
g, clearColour.
b, clearColour.
a };
326 assert(mipCount() > 0u);
327 mipLevel =
to_U8(mipCount() - 1u);
336 gl46core::glClearTexImage( _textureHandle, mipLevel, formatAndType.
_internalFormat, formatAndType.
_dataType, GetClearData( _descriptor._dataType ) );
340 if ( layerRange.
_count >= _depth )
342 layerRange.
_count = _depth;
345 const bool isCubeMap =
IsCubeTexture( _descriptor._texType );
347 const U32 depth = isCubeMap ? layerRange.
_count * 6 : layerRange.
_count;
348 const U16 mipWidth = _width >> mipLevel;
349 const U16 mipHeight = _height >> mipLevel;
351 gl46core::glClearTexSubImage( _textureHandle,
361 GetClearData( _descriptor._dataType) );
371 DIVIDE_ASSERT(sourceSamples == destinationSamples == 0u,
"glTexture::copy Multisampled textures is not supported yet!");
372 DIVIDE_ASSERT(source !=
nullptr && destination !=
nullptr,
"glTexture::copy Invalid source and/or destination textures specified!");
374 const TextureType srcType = source->_descriptor._texType;
375 const TextureType dstType = destination->_descriptor._texType;
388 gl46core::glCopyImageSubData(
390 source->textureHandle(),
397 destination->textureHandle(),
416 grabData._sourceIsBGR =
IsBGRTexture( _descriptor._baseFormat );
418 DIVIDE_ASSERT(_depth == 1u && !
IsCubeTexture( _descriptor._texType ),
"glTexture:readData: unsupported image for readback. Support is very limited!");
420 mipLevel = std::min(mipLevel,
to_U8(mipCount() - 1u));
423 gl46core::GLint compressedSize = 0;
424 gl46core::glGetTextureLevelParameteriv(_textureHandle,
static_cast<gl46core::GLint
>(mipLevel) , gl46core::GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressedSize);
425 if ( compressedSize > 0 )
427 grabData._data.resize(compressedSize);
428 gl46core::glGetCompressedTextureImage( _textureHandle, mipLevel, compressedSize, (
bufferPtr)grabData._data.data() );
433 grabData._numComponents = 4;
435 gl46core::GLint width = _width, height = _height;
436 gl46core::glGetTextureLevelParameteriv(_textureHandle,
static_cast<gl46core::GLint
>(mipLevel), gl46core::GL_TEXTURE_WIDTH, &width );
437 gl46core::glGetTextureLevelParameteriv(_textureHandle,
static_cast<gl46core::GLint
>(mipLevel), gl46core::GL_TEXTURE_HEIGHT, &height );
438 grabData._width =
to_U16(width);
439 grabData._height =
to_U16(height);
442 const U8 storagePerComponent = grabData._bpp /
numChannels();
443 grabData._data.resize(
to_size( grabData._width ) * grabData._height * _depth * storagePerComponent * 4 );
449 gl46core::glGetTextureImage( _textureHandle,
453 (gl46core::GLsizei)grabData._data.size(),
454 grabData._data.data() );
#define PROFILE_SCOPE_AUTO(CATEGORY)
static void DestroyFenceSync(gl46core::GLsync &sync)
static gl46core::GLsync CreateFenceSync()
static GLStateTracker & GetStateTracker() noexcept
An API-independent representation of a texture.
virtual void submitTextureData()
virtual void prepareTextureData(U16 width, U16 height, U16 depth, bool emptyAllocation)
U8 numChannels() const noexcept
static U8 GetBytesPerPixel(GFXDataFormat format, GFXImageFormat baseFormat, GFXImagePacking packing) noexcept
void loadDataInternal(const ImageTools::ImageData &imageData, const vec3< U16 > &offset, const PixelAlignment &pixelUnpackAlignment) override
gl46core::GLsync _loadSync
ImageReadbackData readData(U8 mipLevel, const PixelAlignment &pixelPackAlignment) const override
void submitTextureData() override
gl46core::GLuint _loadingHandle
static void Copy(const glTexture *source, U8 sourceSamples, const glTexture *destination, U8 destinationSamples, const CopyTexParams ¶ms)
void clearData(const UColour4 &clearColour, SubRange layerRange, U8 mipLevel) const
void prepareTextureData(U16 width, U16 height, U16 depth, bool emptyAllocation) override
glTexture(PlatformContext &context, const ResourceDescriptor< Texture > &descriptor)
constexpr bool ENABLE_GPU_VALIDATION
Error callbacks, validations, buffer checks, etc. are controlled by this flag. Heavy performance impa...
gl46core::GLenum internalTextureType(const TextureType type, const U8 msaaSamples)
FormatAndDataType InternalFormatAndDataType(const GFXImageFormat baseFormat, const GFXDataFormat dataType, const GFXImagePacking packing) noexcept
constexpr Optick::Category::Type Graphics
bool isMainThread() noexcept
FColour4 ToFloatColour(const UColour4 &byteColour) noexcept
Handle console commands that start with a forward slash.
constexpr U16 to_U16(const T value)
bool IsCubeTexture(TextureType texType) noexcept
constexpr gl46core::GLuint GL_NULL_HANDLE
Invalid object value. Used to compare handles and determine if they were properly created.
constexpr U8 to_U8(const T value)
constexpr size_t to_size(const T value)
bool IsCompressed(GFXImageFormat format) noexcept
bool IsBGRTexture(GFXImageFormat format) noexcept
vec2< U32 > _sourceCoords
vec2< U32 > _targetCoords
bool setPixelPackAlignment(const PixelAlignment &pixelPackAlignment)
Pixel pack alignment is usually changed by textures, PBOs, etc.
bool setPixelUnpackAlignment(const PixelAlignment &pixelUnpackAlignment)
Pixel unpack alignment is usually changed by textures, PBOs, etc.