Skip to content

Commit

Permalink
Main: Texture - factor out common createSurfaceList
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Feb 17, 2025
1 parent 186e06f commit 17c5e21
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 186 deletions.
9 changes: 9 additions & 0 deletions OgreMain/include/OgreTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,15 @@ namespace Ogre {
*/
virtual void freeInternalResourcesImpl(void) = 0;

virtual HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height, uint32 depth)
{
return nullptr;
}

/// internal method, create HardwarePixelBuffers for every face and
/// mipmap level. This method must be called after the texture object was created
void createSurfaceList(void);

/** Default implementation of unload which calls freeInternalResources */
void unloadImpl(void) override;

Expand Down
8 changes: 1 addition & 7 deletions OgreMain/include/OgreTextureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,8 @@ namespace Ogre {
: Texture(creator, name, handle, group)
{
}
const HardwarePixelBufferSharedPtr& getBuffer(size_t, size_t) override
{
static HardwarePixelBufferSharedPtr nullBuffer;
return nullBuffer;
}

protected:
void createInternalResourcesImpl() override {}
void createInternalResourcesImpl() override { createSurfaceList(); }
void freeInternalResourcesImpl() override {}
void loadImpl() override {}
};
Expand Down
26 changes: 26 additions & 0 deletions OgreMain/src/OgreTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,32 @@ namespace Ogre {
}
}
}

void Texture::createSurfaceList(void)
{
mSurfaceList.clear();

uint32 depth = mDepth;
for (uint8 face = 0; face < getNumFaces(); face++)
{
uint32 width = mWidth;
uint32 height = mHeight;

for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
{
auto buf = createSurface(face, mip, width, height, depth);
mSurfaceList.push_back(buf);

if (width > 1)
width = width / 2;
if (height > 1)
height = height / 2;
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
depth = depth / 2;
}
}
}

//-----------------------------------------------------------------------------
void Texture::unloadImpl(void)
{
Expand Down
7 changes: 3 additions & 4 deletions RenderSystems/Direct3D11/include/OgreD3D11Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ namespace Ogre {
/// internal method, set Texture class final texture protected attributes
void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags);

/// internal method, create D3D11HardwarePixelBuffers for every face and
/// mipmap level. This method must be called after the D3D texture object was created
void _createSurfaceList(void);

void _setD3D11Surface(void* surface) override;

void notifyDeviceLost(D3D11Device* device);
void notifyDeviceRestored(D3D11Device* device);

HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth) override;

protected:
D3D11Device& mDevice;

Expand Down
40 changes: 7 additions & 33 deletions RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,42 +556,16 @@ namespace Ogre
}

// Create list of subsurfaces for getBuffer()
_createSurfaceList();
createSurfaceList();
}
//---------------------------------------------------------------------
void D3D11Texture::_createSurfaceList(void)
HardwarePixelBufferPtr D3D11Texture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth)
{
// Create new list of surfaces
mSurfaceList.clear();
size_t depth = mDepth;

for(size_t face=0; face<getNumFaces(); ++face)
{
size_t width = mWidth;
size_t height = mHeight;
for(size_t mip=0; mip<=mNumMipmaps; ++mip)
{

D3D11HardwarePixelBuffer *buffer;
buffer = new D3D11HardwarePixelBuffer(
this, // parentTexture
mDevice, // device
mip,
width,
height,
depth,
face,
mFormat,
(HardwareBuffer::Usage)mUsage
);

mSurfaceList.push_back(HardwarePixelBufferSharedPtr(buffer));

if(width > 1) width /= 2;
if(height > 1) height /= 2;
if(depth > 1 && getTextureType() != TEX_TYPE_2D_ARRAY) depth /= 2;
}
}
return std::make_shared<D3D11HardwarePixelBuffer>(this, // parentTexture
mDevice, // device
mip, width, height, depth, face, mFormat,
(HardwareBuffer::Usage)mUsage);
}
//---------------------------------------------------------------------
void D3D11Texture ::_setD3D11Surface(void* surface) { mSurface = surface; }
Expand Down
8 changes: 2 additions & 6 deletions RenderSystems/GL/include/OgreGLTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ namespace Ogre {
/// @copydoc Texture::freeInternalResourcesImpl
void freeInternalResourcesImpl(void) override;

/** internal method, create GLHardwarePixelBuffers for every face and
mipmap level. This method must be called after the GL texture object was created,
the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
actually allocate the buffer
*/
void _createSurfaceList();
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth) override;

private:
GLRenderSystem* mRenderSystem;
Expand Down
28 changes: 3 additions & 25 deletions RenderSystems/GL/src/OgreGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace Ogre {
depth = depth/2;
}
}
_createSurfaceList();
createSurfaceList();
// Get final internal format
mFormat = getBuffer(0,0)->getFormat();
}
Expand All @@ -243,31 +243,9 @@ namespace Ogre {
}

//---------------------------------------------------------------------------------------------
void GLTexture::_createSurfaceList()
HardwarePixelBufferPtr GLTexture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height, uint32 depth)
{
mSurfaceList.clear();

uint32 depth = mDepth;

// For all faces and mipmaps, store surfaces as HardwarePixelBufferSharedPtr
for(GLint face=0; face<static_cast<GLint>(getNumFaces()); face++)
{
uint32 width = mWidth;
uint32 height = mHeight;

for(uint32 mip=0; mip<=getNumMipmaps(); mip++)
{
auto buf = std::make_shared<GLTextureBuffer>(mRenderSystem, this, face, mip, width, height, depth);
mSurfaceList.push_back(buf);

if (width > 1)
width = width / 2;
if (height > 1)
height = height / 2;
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
depth = depth / 2;
}
}
return std::make_shared<GLTextureBuffer>(mRenderSystem, this, face, mip, width, height, depth);
}
}

8 changes: 2 additions & 6 deletions RenderSystems/GL3Plus/include/OgreGL3PlusTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ namespace Ogre {
/// @copydoc Resource::freeInternalResourcesImpl
void freeInternalResourcesImpl(void) override;

/** internal method, create GL3PlusHardwarePixelBuffers for every face and
mipmap level. This method must be called after the GL texture object was created,
the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
actually allocate the buffer
*/
void _createSurfaceList();
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth) override;

private:
GL3PlusRenderSystem* mRenderSystem;
Expand Down
27 changes: 4 additions & 23 deletions RenderSystems/GL3Plus/src/OgreGL3PlusTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ namespace Ogre {
// Reset unpack alignment to defaults
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, 4));

_createSurfaceList();
createSurfaceList();

// Generate mipmaps after all texture levels have been loaded
// This is required for compressed formats such as DXT
Expand All @@ -333,29 +333,10 @@ namespace Ogre {
}
}

void GL3PlusTexture::_createSurfaceList()
HardwarePixelBufferPtr GL3PlusTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
uint32 depth)
{
mSurfaceList.clear();

uint32 depth = mDepth;
for (uint8 face = 0; face < getNumFaces(); face++)
{
uint32 width = mWidth;
uint32 height = mHeight;

for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
{
auto buf = std::make_shared<GL3PlusTextureBuffer>(this, face, mip, width, height, depth);
mSurfaceList.push_back(buf);

if (width > 1)
width = width / 2;
if (height > 1)
height = height / 2;
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
depth = depth / 2;
}
}
return std::make_shared<GL3PlusTextureBuffer>(this, face, mipmap, width, height, depth);
}

void GL3PlusTexture::createShaderAccessPoint(uint bindPoint, TextureAccess access,
Expand Down
8 changes: 2 additions & 6 deletions RenderSystems/GLES2/include/OgreGLES2Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ namespace Ogre {
/// @copydoc Texture::freeInternalResourcesImpl
void freeInternalResourcesImpl(void) override;

/** Internal method, create GLHardwarePixelBuffers for every face and
mipmap level. This method must be called after the GL texture object was created,
the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
actually allocate the buffer
*/
void _createSurfaceList();
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth) override;

/// Create gl texture
void _createGLTexResource();
Expand Down
29 changes: 4 additions & 25 deletions RenderSystems/GLES2/src/OgreGLES2Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace Ogre {
{
_createGLTexResource();

_createSurfaceList();
createSurfaceList();

// Get final internal format
mFormat = getBuffer(0,0)->getFormat();
Expand Down Expand Up @@ -354,30 +354,9 @@ namespace Ogre {
}
#endif

void GLES2Texture::_createSurfaceList()
HardwarePixelBufferPtr GLES2Texture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
uint32 depth)
{
mSurfaceList.clear();

uint32 depth = mDepth;

// For all faces and mipmaps, store surfaces as HardwarePixelBufferSharedPtr
for (size_t face = 0; face < getNumFaces(); face++)
{
uint32 width = mWidth;
uint32 height = mHeight;

for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
{
auto buf = std::make_shared<GLES2TextureBuffer>(this, int(face), mip, width, height, depth);
mSurfaceList.push_back(buf);

if (width > 1)
width = width / 2;
if (height > 1)
height = height / 2;
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
depth = depth / 2;
}
}
return std::make_shared<GLES2TextureBuffer>(this, face, mip, width, height, depth);
}
}
3 changes: 2 additions & 1 deletion RenderSystems/Metal/include/OgreMetalTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ namespace Ogre

MTLTextureType getMetalTextureTarget(void) const;
void createMetalTexResource(void);
void createSurfaceList(void);
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
uint32 depth) override;

void createInternalResourcesImpl(void) override;
void freeInternalResourcesImpl(void) override;
Expand Down
26 changes: 5 additions & 21 deletions RenderSystems/Metal/src/OgreMetalTexture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ of this software and associated documentation files (the "Software"), to deal
mTexture = 0;
}
//-----------------------------------------------------------------------------------
void MetalTexture::createSurfaceList(void)
HardwarePixelBufferPtr MetalTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
uint32 depth)
{
mSurfaceList.clear();

__unsafe_unretained id<MTLTexture> renderTexture = mTexture;
__unsafe_unretained id<MTLTexture> resolveTexture = 0;

Expand All @@ -163,24 +162,9 @@ of this software and associated documentation files (the "Software"), to deal
resolveTexture = mTexture;
}

for (size_t face = 0; face < getNumFaces(); face++)
{
uint32 width = mWidth;
uint32 height = mHeight;
uint32 depth = mDepth;

for (uint8 mip = 0; mip <= getNumMipmaps(); mip++)
{
MetalHardwarePixelBuffer *buf = OGRE_NEW MetalTextureBuffer(
renderTexture, resolveTexture, mDevice, mName,
getMetalTextureTarget(), width, height, depth, mFormat,
static_cast<int32>(face), mip,
static_cast<HardwareBuffer::Usage>(mUsage),
mHwGamma, mFSAA );

mSurfaceList.push_back( HardwarePixelBufferSharedPtr(buf) );
}
}
return std::make_shared<MetalTextureBuffer>(renderTexture, resolveTexture, mDevice, mName,
getMetalTextureTarget(), width, height, depth, mFormat, face,
mipmap, mUsage, mHwGamma, mFSAA);
}
//-----------------------------------------------------------------------------------
void MetalTexture::_autogenerateMipmaps(void)
Expand Down
2 changes: 2 additions & 0 deletions RenderSystems/Tiny/include/OgreTinyTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace Ogre {
Image mBuffer;
void createInternalResourcesImpl(void) override;
void freeInternalResourcesImpl(void) override {}
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
uint32 depth) override;
};
}

Expand Down
18 changes: 7 additions & 11 deletions RenderSystems/Tiny/src/OgreTinyTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ namespace Ogre {
}

// Creation / loading methods
HardwarePixelBufferPtr TinyTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
uint32 depth)
{
return std::make_shared<TinyHardwarePixelBuffer>(mBuffer.getPixelBox(face, mipmap), mUsage);
}

void TinyTexture::createInternalResourcesImpl(void)
{
// set HardwareBuffer::Usage for TU_RENDERTARGET if nothing else specified
Expand All @@ -40,17 +46,7 @@ namespace Ogre {

mBuffer.create(mFormat, mWidth, mHeight, mDepth, getNumFaces(), mNumMipmaps);

mSurfaceList.clear();

for (uint8 face = 0; face < getNumFaces(); face++)
{
for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
{
TinyHardwarePixelBuffer* buf =
new TinyHardwarePixelBuffer(mBuffer.getPixelBox(face, mip), mUsage);
mSurfaceList.push_back(HardwarePixelBufferSharedPtr(buf));
}
}
createSurfaceList();

// Generate mipmaps after all texture levels have been loaded
// This is required for compressed formats such as DXT
Expand Down
Loading

0 comments on commit 17c5e21

Please sign in to comment.