Page MenuHomePhorge

Texture.h
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

Texture.h

#ifndef _ECHOTEXTURE_H_
#define _ECHOTEXTURE_H_
#include <echo/Types.h>
#include <string>
namespace Echo
{
class TextureManager;
//!\brief Texture encapsulates texture data.
//!\details This class encapsulates texture data that is platform independent.
//! Normally a texture object is passed to a render target which will then allocate any resources
//! that the render target may need.
class Texture
{
public:
struct Formats
{
enum _
{
UNKNOWN,
R8G8B8X8,
R8G8B8A8,
R8G8B8,
R5G6B5,
R5G5B5A1,
R4G4B4A4,
LUMINANCE8,
LUMINANCE8_ALPHA8
};
static size_t GetBytesPerPixel(Formats::_ format)
{
switch(format)
{
case Formats::R8G8B8A8:
case Formats::R8G8B8X8:
return 4;
case Formats::R8G8B8:
return 3;
case Formats::R5G6B5:
case Formats::R5G5B5A1:
case Formats::LUMINANCE8_ALPHA8:
return 2;
case Formats::LUMINANCE8:
return 1;
case Formats::UNKNOWN:
default:
break;
}
return 0;
}
};
typedef Formats::_ Format;
Texture(u32 width, u32 height, Format format);
Texture(TextureManager& manager, const std::string& resourceName);
virtual ~Texture();
void SetResourceName(const std::string& resourceName);
const std::string& GetResourceName() const;
Texture(const Texture& rhs);
const Texture& operator=(const Texture& rhs);
//!\brief Get the width of the texture buffer.
u32 GetWidth() const {return mWidth;}
//!\brief Get the height of the texture buffer.
u32 GetHeight() const {return mHeight;}
//!\brief Get a pointer to the texture byte buffer.
shared_ptr<u8> GetBuffer() {return mBuffer;}
Format GetFormat() {return mFormat;}
//!\brief Attempts to unload the texture data.
//!\details This method will attempt to free the texture memory.
//!\note This method will not free any memory if the texture data cannot be reloaded.
//!\return The number of bytes freed.
size_t AttemptUnload();
//!\brief Unload the texture data from a resource.
//!\note This method has not effect if the texture manager and resource names are not valid.
//!\return Whether the resources was loaded or not.
bool LoadResource();
//!\brief Get the number of bytes per pixel.
size_t GetBytesPerPixel() const;
private:
TextureManager* mTextureManager;
std::string mResourceName;
Format mFormat;
u32 mWidth;
u32 mHeight;
shared_ptr<u8> mBuffer;
};
}
#endif

File Metadata

Mime Type
text/x-c++
Expires
Thu, Dec 5, 2:17 AM (7 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
62342
Default Alt Text
Texture.h (2 KB)

Event Timeline