|
|
@@ -1,30 +1,3 @@
|
|
|
-/*
|
|
|
------------------------------------------------------------------------------
|
|
|
-This source file is part of OGRE
|
|
|
- (Object-oriented Graphics Rendering Engine)
|
|
|
-For the latest info, see http://www.ogre3d.org/
|
|
|
-
|
|
|
-Copyright (c) 2000-2011 Torus Knot Software Ltd
|
|
|
-
|
|
|
-Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
-of this software and associated documentation files (the "Software"), to deal
|
|
|
-in the Software without restriction, including without limitation the rights
|
|
|
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
-copies of the Software, and to permit persons to whom the Software is
|
|
|
-furnished to do so, subject to the following conditions:
|
|
|
-
|
|
|
-The above copyright notice and this permission notice shall be included in
|
|
|
-all copies or substantial portions of the Software.
|
|
|
-
|
|
|
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
-THE SOFTWARE.
|
|
|
------------------------------------------------------------------------------
|
|
|
-*/
|
|
|
#pragma once
|
|
|
|
|
|
#include "CmPrerequisites.h"
|
|
|
@@ -35,49 +8,43 @@ THE SOFTWARE.
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
- /** Enum identifying the texture usage
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * @brief Properties that describe how is the texture used.
|
|
|
+ */
|
|
|
enum TextureUsage
|
|
|
{
|
|
|
- /// @copydoc HardwareBuffer::Usage
|
|
|
- TU_STATIC = GBU_STATIC, // Optimal setting if texture is read by the GPU often, and very rarely written by CPU
|
|
|
- TU_DYNAMIC = GBU_DYNAMIC, // Optimal if the texture is updated by CPU often (e.g. every frame)
|
|
|
- TU_RENDERTARGET = 0x200, // Used for rendering by the GPU
|
|
|
- TU_DEPTHSTENCIL = 0x400,
|
|
|
+ TU_STATIC = GBU_STATIC, /**< A regular texture that is not often or ever updated from the CPU. */
|
|
|
+ TU_DYNAMIC = GBU_DYNAMIC, /**< A regular texture that is often updated by the CPU. */
|
|
|
+ TU_RENDERTARGET = 0x200, /**< Texture used for rendering by the GPU. */
|
|
|
+ TU_DEPTHSTENCIL = 0x400, /**< Texture used as a depth/stencil buffer by the GPU. */
|
|
|
TU_DEFAULT = TU_STATIC
|
|
|
};
|
|
|
|
|
|
- /** Enum identifying the texture type
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * @brief Different texture types.
|
|
|
+ */
|
|
|
enum TextureType
|
|
|
{
|
|
|
- /// 1D texture, used in combination with 1D texture coordinates
|
|
|
- TEX_TYPE_1D = 1,
|
|
|
- /// 2D texture, used in combination with 2D texture coordinates (default)
|
|
|
- TEX_TYPE_2D = 2,
|
|
|
- /// 3D volume texture, used in combination with 3D texture coordinates
|
|
|
- TEX_TYPE_3D = 3,
|
|
|
- /// 3D cube map, used in combination with 3D texture coordinates
|
|
|
- TEX_TYPE_CUBE_MAP = 4
|
|
|
+ TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
|
|
|
+ TEX_TYPE_2D = 2, /**< Two dimensional texture. */
|
|
|
+ TEX_TYPE_3D = 3, /**< Three dimensional texture. */
|
|
|
+ TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
|
|
|
};
|
|
|
|
|
|
- /** Enum identifying special mipmap numbers
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * @brief Mipmap options.
|
|
|
+ */
|
|
|
enum TextureMipmap
|
|
|
{
|
|
|
- /// Generate mipmaps up to 1x1
|
|
|
- MIP_UNLIMITED = 0x7FFFFFFF
|
|
|
+ MIP_UNLIMITED = 0x7FFFFFFF /**< Create all mip maps down to 1x1. */
|
|
|
};
|
|
|
|
|
|
- /** Abstract class representing a Texture resource.
|
|
|
- @remarks
|
|
|
- The actual concrete subclass which will exist for a texture
|
|
|
- is dependent on the rendering system in use (Direct3D, OpenGL etc).
|
|
|
- This class represents the commonalities, and is the one 'used'
|
|
|
- by programmers even though the real implementation could be
|
|
|
- different in reality. Texture objects are created through
|
|
|
- the 'create' method of the TextureManager concrete subclass.
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * @brief Abstract class representing a texture. Specific render systems have their
|
|
|
+ * own Texture implementations.
|
|
|
+ *
|
|
|
+ * @note Core thread unless specified otherwise.
|
|
|
+ */
|
|
|
class CM_EXPORT Texture : public GpuResource
|
|
|
{
|
|
|
public:
|
|
|
@@ -167,15 +134,6 @@ namespace BansheeEngine
|
|
|
*/
|
|
|
virtual UINT32 getNumFaces() const;
|
|
|
|
|
|
- /**
|
|
|
- * @brief Returns true if the texture can be bound to a shader.
|
|
|
- *
|
|
|
- * @note This is only false for some rare special cases. (e.g. AA render texture in DX9)
|
|
|
- *
|
|
|
- * Core thread only.
|
|
|
- */
|
|
|
- virtual bool isBindableAsShaderResource() const { return true; }
|
|
|
-
|
|
|
/**
|
|
|
* @copydoc GpuResource::writeSubresource
|
|
|
*/
|
|
|
@@ -187,31 +145,33 @@ namespace BansheeEngine
|
|
|
virtual void readSubresource(UINT32 subresourceIdx, GpuResourceData& data);
|
|
|
|
|
|
/**
|
|
|
- * @brief Allocates a buffer you may use for storage when reading a subresource. You
|
|
|
+ * @brief Allocates a buffer you may use for storage when reading or writing a sub-resource. You
|
|
|
* need to allocate such a buffer if you are calling "readSubresource".
|
|
|
+ *
|
|
|
+ * You can retrieve a sub-resource index by calling "mapToSubresourceIdx".
|
|
|
*
|
|
|
* @note Thread safe.
|
|
|
*/
|
|
|
PixelDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
|
|
|
|
|
|
/**
|
|
|
- * @brief Maps a subresource index to an exact face and mip level. Subresource indexes
|
|
|
+ * @brief Maps a sub-resource index to an exact face and mip level. Sub-resource indexes
|
|
|
* are used when reading or writing to the resource.
|
|
|
*
|
|
|
- * @note Subresource index is only valid for the instance it was created on. You cannot use a subresource
|
|
|
+ * @note Sub-resource index is only valid for the instance it was created on. You cannot use a sub-resource
|
|
|
* index from a different texture and expect to get valid result. Modifying the resource so the number
|
|
|
- * of subresources changes, invalidates all subresource indexes.
|
|
|
+ * of sub-resources changes invalidates all sub-resource indexes.
|
|
|
*
|
|
|
* Thread safe.
|
|
|
*/
|
|
|
void mapFromSubresourceIdx(UINT32 subresourceIdx, UINT32& face, UINT32& mip) const;
|
|
|
|
|
|
/**
|
|
|
- * @brief Map a face and a mip level to a subresource index you can use for updating or reading
|
|
|
+ * @brief Map a face and a mip level to a sub-resource index you can use for updating or reading
|
|
|
* a specific sub-resource.
|
|
|
*
|
|
|
- * @note Generated subresource index is only valid for the instance it was created on. Modifying the resource so the number
|
|
|
- * of subresources changes, invalidates all subresource indexes.
|
|
|
+ * @note Generated sub-resource index is only valid for the instance it was created on. Modifying the resource so the number
|
|
|
+ * of sub-resources changes, invalidates all sub-resource indexes.
|
|
|
*
|
|
|
* Thread safe.
|
|
|
*/
|
|
|
@@ -220,14 +180,14 @@ namespace BansheeEngine
|
|
|
/**
|
|
|
* @brief Locks the buffer for reading or writing.
|
|
|
*
|
|
|
- * @param options Options for controlling the operation.
|
|
|
- * @param mipLevel (optional) the mip level.
|
|
|
- * @param face (optional) the face.
|
|
|
+ * @param options Options for controlling what you may do with the locked data.
|
|
|
+ * @param mipLevel (optional) Mipmap level to lock.
|
|
|
+ * @param face (optional) Texture face to lock.
|
|
|
*
|
|
|
* @return Pointer to the buffer data. Only valid until you call unlock.
|
|
|
*
|
|
|
* @note If you are just reading or writing one block of data use
|
|
|
- * readData/writeData methods as they can be must faster in certain situations.
|
|
|
+ * readData/writeData methods as they can be much faster in certain situations.
|
|
|
*
|
|
|
* Core thread only.
|
|
|
*/
|
|
|
@@ -252,6 +212,10 @@ namespace BansheeEngine
|
|
|
/**
|
|
|
* @brief Reads data from the texture buffer into the provided buffer.
|
|
|
*
|
|
|
+ * @param dest Previously allocated buffer to read data into.
|
|
|
+ * @param mipLevel (optional) Mipmap level to read from.
|
|
|
+ * @param face (optional) Texture face to read from.
|
|
|
+ *
|
|
|
* @note Core thread only.
|
|
|
*/
|
|
|
virtual void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
|
|
|
@@ -259,6 +223,12 @@ namespace BansheeEngine
|
|
|
/**
|
|
|
* @brief Writes data from the provided buffer into the texture buffer.
|
|
|
*
|
|
|
+ * @param dest Buffer to retrieve the data from.
|
|
|
+ * @param mipLevel (optional) Mipmap level to write into.
|
|
|
+ * @param face (optional) Texture face to write into.
|
|
|
+ * @param discardWholeBuffer (optional) If true any existing texture data will be discard. This can
|
|
|
+ * improve performance of the write operation.
|
|
|
+ *
|
|
|
* @note Core thread only.
|
|
|
*/
|
|
|
virtual void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) = 0;
|
|
|
@@ -270,18 +240,108 @@ namespace BansheeEngine
|
|
|
*/
|
|
|
static const HTexture& dummy();
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Returns true if the texture can be bound to a shader.
|
|
|
+ *
|
|
|
+ * @note This is only false for some rare special cases. (e.g. AA render texture in DX9)
|
|
|
+ * Internal method.
|
|
|
+ */
|
|
|
+ virtual bool _isBindableAsShaderResource() const { return true; }
|
|
|
+
|
|
|
/************************************************************************/
|
|
|
/* TEXTURE VIEW */
|
|
|
/************************************************************************/
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Requests a texture view for the specified mip and array ranges. Returns an existing view of one for
|
|
|
+ * the specified ranges already exists, otherwise creates a new one. You must release all views
|
|
|
+ * by calling "releaseView" when done.
|
|
|
+ */
|
|
|
static TextureViewPtr requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Releases the view. View won't actually get destroyed until all references to it are released.
|
|
|
+ */
|
|
|
static void releaseView(TextureViewPtr view);
|
|
|
|
|
|
+ /************************************************************************/
|
|
|
+ /* STATICS */
|
|
|
+ /************************************************************************/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Creates a new empty texture.
|
|
|
+ *
|
|
|
+ * @param texType Type of the texture.
|
|
|
+ * @param width Width of the texture in pixels.
|
|
|
+ * @param height Height of the texture in pixels.
|
|
|
+ * @param depth Depth of the texture in pixels (Must be 1 for 2D textures).
|
|
|
+ * @param numMips Number of mip-maps the texture has. This number excludes the full resolution map.
|
|
|
+ * @param format Format of the pixels.
|
|
|
+ * @param usage Describes how we plan on using the texture in the pipeline.
|
|
|
+ * @param hwGammaCorrection If true the texture data is assumed to have been gamma corrected and will be
|
|
|
+ * converted back to linear space when sampled on GPU.
|
|
|
+ * @param fsaa If higher than 1, texture containing multiple samples per pixel is created.
|
|
|
+ * @param fsaaHint Hint about what kind of multisampling to use. Render system specific.
|
|
|
+ */
|
|
|
+ static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
|
|
|
+ int numMips, PixelFormat format, int usage = TU_DEFAULT,
|
|
|
+ bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Creates a new empty texture.
|
|
|
+ *
|
|
|
+ * @param texType Type of the texture.
|
|
|
+ * @param width Width of the texture in pixels.
|
|
|
+ * @param height Height of the texture in pixels.
|
|
|
+ * @param numMips Number of mip-maps the texture has. This number excludes the full resolution map.
|
|
|
+ * @param format Format of the pixels.
|
|
|
+ * @param usage Describes how we plan on using the texture in the pipeline.
|
|
|
+ * @param hwGammaCorrection If true the texture data is assumed to have been gamma corrected and will be
|
|
|
+ * converted back to linear space when sampled on GPU.
|
|
|
+ * @param fsaa If higher than 1, texture containing multiple samples per pixel is created.
|
|
|
+ * @param fsaaHint Hint about what kind of multisampling to use. Render system specific.
|
|
|
+ */
|
|
|
+ static HTexture create(TextureType texType, UINT32 width, UINT32 height, int numMips,
|
|
|
+ PixelFormat format, int usage = TU_DEFAULT,
|
|
|
+ bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @copydoc create
|
|
|
+ *
|
|
|
+ * @note Internal method. Creates a texture pointer without a handle. Use "create" for normal usage.
|
|
|
+ */
|
|
|
+ static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
|
|
|
+ int num_mips, PixelFormat format, int usage = TU_DEFAULT,
|
|
|
+ bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @copydoc create
|
|
|
+ *
|
|
|
+ * @note Internal method. Creates a texture pointer without a handle. Use "create" for normal usage.
|
|
|
+ */
|
|
|
+ static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, int num_mips,
|
|
|
+ PixelFormat format, int usage = TU_DEFAULT,
|
|
|
+ bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
+
|
|
|
protected:
|
|
|
+ /************************************************************************/
|
|
|
+ /* TEXTURE VIEW */
|
|
|
+ /************************************************************************/
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Creates a new empty/undefined texture view.
|
|
|
+ */
|
|
|
virtual TextureViewPtr createView();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Releases all internal texture view references. Views won't get destroyed if there are external references still held.
|
|
|
+ */
|
|
|
void clearBufferViews();
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Holds a single texture view with a usage reference count.
|
|
|
+ */
|
|
|
struct TextureViewReference
|
|
|
{
|
|
|
TextureViewReference(TextureViewPtr _view)
|
|
|
@@ -297,38 +357,47 @@ namespace BansheeEngine
|
|
|
protected:
|
|
|
friend class TextureManager;
|
|
|
|
|
|
- UINT32 mHeight; // Immutable
|
|
|
- UINT32 mWidth; // Immutable
|
|
|
- UINT32 mDepth; // Immutable
|
|
|
-
|
|
|
- UINT32 mNumMipmaps; // Immutable
|
|
|
- bool mHwGamma; // Immutable
|
|
|
- UINT32 mFSAA; // Immutable
|
|
|
- String mFSAAHint; // Immutable
|
|
|
-
|
|
|
- TextureType mTextureType; // Immutable
|
|
|
- PixelFormat mFormat; // Immutable
|
|
|
- int mUsage; // Immutable
|
|
|
-
|
|
|
Texture();
|
|
|
|
|
|
/**
|
|
|
- * @brief Initializes the texture. This must be called right after the texture is constructed. Called by TextureManager
|
|
|
- * upon texture creation, so usually you don't want to call this manually.
|
|
|
- *
|
|
|
- * @note Initialization is not done immediately, and is instead just scheduled on the
|
|
|
- * core thread. Unless called from core thread, in which case it is initialized
|
|
|
- * right away.
|
|
|
+ * @copydoc GpuResource::initialize
|
|
|
*/
|
|
|
void initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
|
|
|
PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint);
|
|
|
|
|
|
+ /**
|
|
|
+ * @copydoc lock
|
|
|
+ */
|
|
|
virtual PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @copydoc unlock
|
|
|
+ */
|
|
|
virtual void unlockImpl() = 0;
|
|
|
|
|
|
+ /**
|
|
|
+ * @copydoc copy
|
|
|
+ */
|
|
|
virtual void copyImpl(TexturePtr& target) = 0;
|
|
|
- /// @copydoc Resource::calculateSize
|
|
|
- UINT32 calculateSize(void) const;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @copydoc Resource::calculateSize
|
|
|
+ */
|
|
|
+ UINT32 calculateSize() const;
|
|
|
+
|
|
|
+ protected:
|
|
|
+ UINT32 mHeight; // Immutable
|
|
|
+ UINT32 mWidth; // Immutable
|
|
|
+ UINT32 mDepth; // Immutable
|
|
|
+
|
|
|
+ UINT32 mNumMipmaps; // Immutable
|
|
|
+ bool mHwGamma; // Immutable
|
|
|
+ UINT32 mFSAA; // Immutable
|
|
|
+ String mFSAAHint; // Immutable
|
|
|
+
|
|
|
+ TextureType mTextureType; // Immutable
|
|
|
+ PixelFormat mFormat; // Immutable
|
|
|
+ int mUsage; // Immutable
|
|
|
|
|
|
/************************************************************************/
|
|
|
/* SERIALIZATION */
|
|
|
@@ -337,25 +406,5 @@ namespace BansheeEngine
|
|
|
friend class TextureRTTI;
|
|
|
static RTTITypeBase* getRTTIStatic();
|
|
|
virtual RTTITypeBase* getRTTI() const;
|
|
|
-
|
|
|
- /************************************************************************/
|
|
|
- /* STATICS */
|
|
|
- /************************************************************************/
|
|
|
- public:
|
|
|
- static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
|
|
|
- int num_mips, PixelFormat format, int usage = TU_DEFAULT,
|
|
|
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
-
|
|
|
- static HTexture create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
|
|
|
- PixelFormat format, int usage = TU_DEFAULT,
|
|
|
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
-
|
|
|
- static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
|
|
|
- int num_mips, PixelFormat format, int usage = TU_DEFAULT,
|
|
|
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
-
|
|
|
- static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, int num_mips,
|
|
|
- PixelFormat format, int usage = TU_DEFAULT,
|
|
|
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
|
|
|
};
|
|
|
}
|