| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- /*
- Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
- 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 "Types.h"
- #include "Color4.h"
- #include "Resource.h"
- #include "Shared.h"
- #include "Str.h"
- #include "Image.h"
- namespace crown
- {
- /**
- * Enumerates the type of a texture
- */
- enum TextureType
- {
- TT_1D = 0,
- TT_2D = 1,
- TT_3D = 2,
- TT_CUBEMAP = 3,
- TT_COUNT
- };
- enum TextureMode
- {
- TM_MODULATE = 0, // Multiplies texel color by the geometry color after lighting
- TM_REPLACE = 1, // Replaces the fragment color with the texel color
- TM_DECAL = 2, // WTF?
- TM_BLEND = 3, // Blends the texel color with a constant blending color
- TM_ADD = 4, // Adds the texel color to the fragment color
- TM_COUNT
- };
- /**
- * Enumerates the hardware filter to use when applying a texture
- */
- enum TextureFilter
- {
- TF_NEAREST = 0,
- TF_LINEAR = 1,
- TF_BILINEAR = 2,
- TF_TRILINEAR = 3,
- TF_ANISOTROPIC = 4,
- TF_COUNT
- };
- /**
- * Enumerates the wrapping mode to use when applying a texture
- */
- enum TextureWrap
- {
- TW_REPEAT = 0,
- TW_CLAMP = 1,
- TW_CLAMP_TO_EDGE = 2,
- TW_CLAMP_TO_BORDER = 3,
- TW_COUNT
- };
- class Image;
- /**
- * Abstracts a texture
- */
- class Texture : public Resource
- {
- public:
- //! Constructor
- Texture() :
- mType(TT_2D),
- mMode(TM_MODULATE),
- mFilter(TF_LINEAR),
- mWrap(TW_REPEAT),
- mWidth(0),
- mHeight(0),
- mGenerateMipMaps(false),
- mBlendColor(1.0f, 1.0f, 1.0f, 1.0f)
- {
- }
- //! Destructor
- virtual ~Texture() { }
- //! Returns the texture type
- inline TextureType GetType() const
- {
- return mType;
- }
- inline void SetType(TextureType type) { mType = type; }
- //! Returns the mode used by this texture
- inline TextureMode GetMode() const
- {
- return mMode;
- }
- //! Sets the mode used by this texture
- inline void SetMode(TextureMode mode)
- {
- mMode = mode;
- }
- //! Returns the filter type used by this texture
- inline TextureFilter GetFilter() const
- {
- return mFilter;
- }
- //! Sets the filter type used by this texture
- inline void SetFilter(TextureFilter filter)
- {
- mFilter = filter;
- }
- //! Returns the wrap mode used by this texture
- inline TextureWrap GetWrap() const
- {
- return mWrap;
- }
- //! Sets the wrap mode used by this texture
- inline void SetWrap(TextureWrap wrap)
- {
- mWrap = wrap;
- }
- //! Returns whether MipMaps' hardware auto generation is enabled
- inline bool GetGenerateMipMaps() const
- {
- return mGenerateMipMaps;
- }
- //! Sets whether MipMaps should be auto generated by the hardware (if supported)
- inline void SetGenerateMipMaps(bool mipmaps)
- {
- mGenerateMipMaps = mipmaps;
- }
- //! Returns the texture's blend color
- inline const Color4& GetBlendColor() const
- {
- return mBlendColor;
- }
- //! Sets the texture's blend color
- inline void SetBlendColor(const Color4& color)
- {
- mBlendColor = color;
- }
- //! Returns the texture's width
- inline uint GetWidth() const
- {
- return mWidth;
- }
- //! Returns the texture's height
- inline uint GetHeight() const
- {
- return mHeight;
- }
- virtual void LoadFromImage(const Image* image) = 0;
- virtual void LoadFromFile(const char* relativePath) = 0;
- virtual void LoadFromFile(const char* relativePath, Color4 colorKey) = 0;
- virtual void LoadFromFile(const char* relativePath, const char* alphaGreyscale) = 0;
- virtual Image* GetImage() const = 0;
- virtual PixelFormat GetTextureFormat() const = 0;
- protected:
- TextureType mType;
- TextureMode mMode;
- TextureFilter mFilter;
- TextureWrap mWrap;
- uint mWidth;
- uint mHeight;
- bool mGenerateMipMaps;
- //! It's the blending color used when mMode == TM_BLEND
- Color4 mBlendColor;
- };
- } // namespace crown
|