Skip to content

Commit a00a217

Browse files
committed
Main: Texture - factor out common createSurfaceList
1 parent 7966599 commit a00a217

17 files changed

+85
-186
lines changed

OgreMain/include/OgreTexture.h

+9
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,15 @@ namespace Ogre {
495495
*/
496496
virtual void freeInternalResourcesImpl(void) = 0;
497497

498+
virtual HardwarePixelBufferPtr createSurface(uint32 face, uint32 mip, uint32 width, uint32 height, uint32 depth)
499+
{
500+
return nullptr;
501+
}
502+
503+
/// internal method, create HardwarePixelBuffers for every face and
504+
/// mipmap level. This method must be called after the texture object was created
505+
void createSurfaceList(void);
506+
498507
/** Default implementation of unload which calls freeInternalResources */
499508
void unloadImpl(void) override;
500509

OgreMain/include/OgreTextureManager.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,8 @@ namespace Ogre {
435435
: Texture(creator, name, handle, group)
436436
{
437437
}
438-
const HardwarePixelBufferSharedPtr& getBuffer(size_t, size_t) override
439-
{
440-
static HardwarePixelBufferSharedPtr nullBuffer;
441-
return nullBuffer;
442-
}
443-
444438
protected:
445-
void createInternalResourcesImpl() override {}
439+
void createInternalResourcesImpl() override { createSurfaceList(); }
446440
void freeInternalResourcesImpl() override {}
447441
void loadImpl() override {}
448442
};

OgreMain/src/OgreTexture.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,32 @@ namespace Ogre {
356356
}
357357
}
358358
}
359+
360+
void Texture::createSurfaceList(void)
361+
{
362+
mSurfaceList.clear();
363+
364+
uint32 depth = mDepth;
365+
for (uint8 face = 0; face < getNumFaces(); face++)
366+
{
367+
uint32 width = mWidth;
368+
uint32 height = mHeight;
369+
370+
for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
371+
{
372+
auto buf = createSurface(face, mip, width, height, depth);
373+
mSurfaceList.push_back(buf);
374+
375+
if (width > 1)
376+
width = width / 2;
377+
if (height > 1)
378+
height = height / 2;
379+
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
380+
depth = depth / 2;
381+
}
382+
}
383+
}
384+
359385
//-----------------------------------------------------------------------------
360386
void Texture::unloadImpl(void)
361387
{

RenderSystems/Direct3D11/include/OgreD3D11Texture.h

-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ namespace Ogre {
106106
/// internal method, set Texture class final texture protected attributes
107107
void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags);
108108

109-
/// internal method, create D3D11HardwarePixelBuffers for every face and
110-
/// mipmap level. This method must be called after the D3D texture object was created
111-
void _createSurfaceList(void);
112-
113109
void _setD3D11Surface(void* surface) override;
114110

115111
void notifyDeviceLost(D3D11Device* device);

RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp

+7-33
Original file line numberDiff line numberDiff line change
@@ -556,42 +556,16 @@ namespace Ogre
556556
}
557557

558558
// Create list of subsurfaces for getBuffer()
559-
_createSurfaceList();
559+
createSurfaceList();
560560
}
561561
//---------------------------------------------------------------------
562-
void D3D11Texture::_createSurfaceList(void)
562+
HardwarePixelBufferPtr D3D11Texture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
563+
uint32 depth)
563564
{
564-
// Create new list of surfaces
565-
mSurfaceList.clear();
566-
size_t depth = mDepth;
567-
568-
for(size_t face=0; face<getNumFaces(); ++face)
569-
{
570-
size_t width = mWidth;
571-
size_t height = mHeight;
572-
for(size_t mip=0; mip<=mNumMipmaps; ++mip)
573-
{
574-
575-
D3D11HardwarePixelBuffer *buffer;
576-
buffer = new D3D11HardwarePixelBuffer(
577-
this, // parentTexture
578-
mDevice, // device
579-
mip,
580-
width,
581-
height,
582-
depth,
583-
face,
584-
mFormat,
585-
(HardwareBuffer::Usage)mUsage
586-
);
587-
588-
mSurfaceList.push_back(HardwarePixelBufferSharedPtr(buffer));
589-
590-
if(width > 1) width /= 2;
591-
if(height > 1) height /= 2;
592-
if(depth > 1 && getTextureType() != TEX_TYPE_2D_ARRAY) depth /= 2;
593-
}
594-
}
565+
return std::make_shared<D3D11HardwarePixelBuffer>(this, // parentTexture
566+
mDevice, // device
567+
mip, width, height, depth, face, mFormat,
568+
(HardwareBuffer::Usage)mUsage);
595569
}
596570
//---------------------------------------------------------------------
597571
void D3D11Texture ::_setD3D11Surface(void* surface) { mSurface = surface; }

RenderSystems/GL/include/OgreGLTexture.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ namespace Ogre {
5656
/// @copydoc Texture::freeInternalResourcesImpl
5757
void freeInternalResourcesImpl(void) override;
5858

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

6662
private:
6763
GLRenderSystem* mRenderSystem;

RenderSystems/GL/src/OgreGLTexture.cpp

+3-25
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ namespace Ogre {
226226
depth = depth/2;
227227
}
228228
}
229-
_createSurfaceList();
229+
createSurfaceList();
230230
// Get final internal format
231231
mFormat = getBuffer(0,0)->getFormat();
232232
}
@@ -243,31 +243,9 @@ namespace Ogre {
243243
}
244244

245245
//---------------------------------------------------------------------------------------------
246-
void GLTexture::_createSurfaceList()
246+
HardwarePixelBufferPtr GLTexture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height, uint32 depth)
247247
{
248-
mSurfaceList.clear();
249-
250-
uint32 depth = mDepth;
251-
252-
// For all faces and mipmaps, store surfaces as HardwarePixelBufferSharedPtr
253-
for(GLint face=0; face<static_cast<GLint>(getNumFaces()); face++)
254-
{
255-
uint32 width = mWidth;
256-
uint32 height = mHeight;
257-
258-
for(uint32 mip=0; mip<=getNumMipmaps(); mip++)
259-
{
260-
auto buf = std::make_shared<GLTextureBuffer>(mRenderSystem, this, face, mip, width, height, depth);
261-
mSurfaceList.push_back(buf);
262-
263-
if (width > 1)
264-
width = width / 2;
265-
if (height > 1)
266-
height = height / 2;
267-
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
268-
depth = depth / 2;
269-
}
270-
}
248+
return std::make_shared<GLTextureBuffer>(mRenderSystem, this, face, mip, width, height, depth);
271249
}
272250
}
273251

RenderSystems/GL3Plus/include/OgreGL3PlusTexture.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ namespace Ogre {
5858
/// @copydoc Resource::freeInternalResourcesImpl
5959
void freeInternalResourcesImpl(void) override;
6060

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

6864
private:
6965
GL3PlusRenderSystem* mRenderSystem;

RenderSystems/GL3Plus/src/OgreGL3PlusTexture.cpp

+4-23
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ namespace Ogre {
311311
// Reset unpack alignment to defaults
312312
OGRE_CHECK_GL_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, 4));
313313

314-
_createSurfaceList();
314+
createSurfaceList();
315315

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

336-
void GL3PlusTexture::_createSurfaceList()
336+
HardwarePixelBufferPtr GL3PlusTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
337+
uint32 depth)
337338
{
338-
mSurfaceList.clear();
339-
340-
uint32 depth = mDepth;
341-
for (uint8 face = 0; face < getNumFaces(); face++)
342-
{
343-
uint32 width = mWidth;
344-
uint32 height = mHeight;
345-
346-
for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
347-
{
348-
auto buf = std::make_shared<GL3PlusTextureBuffer>(this, face, mip, width, height, depth);
349-
mSurfaceList.push_back(buf);
350-
351-
if (width > 1)
352-
width = width / 2;
353-
if (height > 1)
354-
height = height / 2;
355-
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
356-
depth = depth / 2;
357-
}
358-
}
339+
return std::make_shared<GL3PlusTextureBuffer>(this, face, mipmap, width, height, depth);
359340
}
360341

361342
void GL3PlusTexture::createShaderAccessPoint(uint bindPoint, TextureAccess access,

RenderSystems/GLES2/include/OgreGLES2Texture.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ namespace Ogre {
5858
/// @copydoc Texture::freeInternalResourcesImpl
5959
void freeInternalResourcesImpl(void) override;
6060

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

6864
/// Create gl texture
6965
void _createGLTexResource();

RenderSystems/GLES2/src/OgreGLES2Texture.cpp

+4-25
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ namespace Ogre {
297297
{
298298
_createGLTexResource();
299299

300-
_createSurfaceList();
300+
createSurfaceList();
301301

302302
// Get final internal format
303303
mFormat = getBuffer(0,0)->getFormat();
@@ -354,30 +354,9 @@ namespace Ogre {
354354
}
355355
#endif
356356

357-
void GLES2Texture::_createSurfaceList()
357+
HardwarePixelBufferPtr GLES2Texture::createSurface(uint32 face, uint32 mip, uint32 width, uint32 height,
358+
uint32 depth)
358359
{
359-
mSurfaceList.clear();
360-
361-
uint32 depth = mDepth;
362-
363-
// For all faces and mipmaps, store surfaces as HardwarePixelBufferSharedPtr
364-
for (size_t face = 0; face < getNumFaces(); face++)
365-
{
366-
uint32 width = mWidth;
367-
uint32 height = mHeight;
368-
369-
for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
370-
{
371-
auto buf = std::make_shared<GLES2TextureBuffer>(this, int(face), mip, width, height, depth);
372-
mSurfaceList.push_back(buf);
373-
374-
if (width > 1)
375-
width = width / 2;
376-
if (height > 1)
377-
height = height / 2;
378-
if (depth > 1 && mTextureType != TEX_TYPE_2D_ARRAY)
379-
depth = depth / 2;
380-
}
381-
}
360+
return std::make_shared<GLES2TextureBuffer>(this, face, mip, width, height, depth);
382361
}
383362
}

RenderSystems/Metal/include/OgreMetalTexture.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ namespace Ogre
4949

5050
MTLTextureType getMetalTextureTarget(void) const;
5151
void createMetalTexResource(void);
52-
void createSurfaceList(void);
52+
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
53+
uint32 depth) override;
5354

5455
void createInternalResourcesImpl(void) override;
5556
void freeInternalResourcesImpl(void) override;

RenderSystems/Metal/src/OgreMetalTexture.mm

+5-21
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ of this software and associated documentation files (the "Software"), to deal
150150
mTexture = 0;
151151
}
152152
//-----------------------------------------------------------------------------------
153-
void MetalTexture::createSurfaceList(void)
153+
HardwarePixelBufferPtr MetalTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
154+
uint32 depth)
154155
{
155-
mSurfaceList.clear();
156-
157156
__unsafe_unretained id<MTLTexture> renderTexture = mTexture;
158157
__unsafe_unretained id<MTLTexture> resolveTexture = 0;
159158

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

166-
for (size_t face = 0; face < getNumFaces(); face++)
167-
{
168-
uint32 width = mWidth;
169-
uint32 height = mHeight;
170-
uint32 depth = mDepth;
171-
172-
for (uint8 mip = 0; mip <= getNumMipmaps(); mip++)
173-
{
174-
MetalHardwarePixelBuffer *buf = OGRE_NEW MetalTextureBuffer(
175-
renderTexture, resolveTexture, mDevice, mName,
176-
getMetalTextureTarget(), width, height, depth, mFormat,
177-
static_cast<int32>(face), mip,
178-
static_cast<HardwareBuffer::Usage>(mUsage),
179-
mHwGamma, mFSAA );
180-
181-
mSurfaceList.push_back( HardwarePixelBufferSharedPtr(buf) );
182-
}
183-
}
165+
return std::make_shared<MetalTextureBuffer>(
166+
renderTexture, resolveTexture, mDevice, mName, getMetalTextureTarget(), width, height, depth, mFormat,
167+
static_cast<int32>(face), mip, static_cast<HardwareBuffer::Usage>(mUsage), mHwGamma, mFSAA);
184168
}
185169
//-----------------------------------------------------------------------------------
186170
void MetalTexture::_autogenerateMipmaps(void)

RenderSystems/Tiny/include/OgreTinyTexture.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace Ogre {
2323
Image mBuffer;
2424
void createInternalResourcesImpl(void) override;
2525
void freeInternalResourcesImpl(void) override {}
26+
HardwarePixelBufferPtr createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
27+
uint32 depth) override;
2628
};
2729
}
2830

RenderSystems/Tiny/src/OgreTinyTexture.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ namespace Ogre {
2727
}
2828

2929
// Creation / loading methods
30+
HardwarePixelBufferPtr TinyTexture::createSurface(uint32 face, uint32 mipmap, uint32 width, uint32 height,
31+
uint32 depth)
32+
{
33+
return std::make_shared<TinyHardwarePixelBuffer>(mBuffer.getPixelBox(face, mip), mUsage);
34+
}
35+
3036
void TinyTexture::createInternalResourcesImpl(void)
3137
{
3238
// set HardwareBuffer::Usage for TU_RENDERTARGET if nothing else specified
@@ -40,17 +46,7 @@ namespace Ogre {
4046

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

43-
mSurfaceList.clear();
44-
45-
for (uint8 face = 0; face < getNumFaces(); face++)
46-
{
47-
for (uint32 mip = 0; mip <= getNumMipmaps(); mip++)
48-
{
49-
TinyHardwarePixelBuffer* buf =
50-
new TinyHardwarePixelBuffer(mBuffer.getPixelBox(face, mip), mUsage);
51-
mSurfaceList.push_back(HardwarePixelBufferSharedPtr(buf));
52-
}
53-
}
49+
createSurfaceList();
5450

5551
// Generate mipmaps after all texture levels have been loaded
5652
// This is required for compressed formats such as DXT

0 commit comments

Comments
 (0)