PageRenderTime 264ms CodeModel.GetById 100ms app.highlight 11ms RepoModel.GetById 150ms app.codeStats 1ms

/opengles/src/Texture.h

http://ftk.googlecode.com/
C++ Header | 149 lines | 82 code | 32 blank | 35 comment | 2 complexity | 51c7a50d286d1168f7f39f4a2ba393cb MD5 | raw file
  1#ifndef EGL_TEXTURE_H
  2#define EGL_TEXTURE_H 1
  3
  4// ==========================================================================
  5//
  6// Texture.h		Texture Class for 3D Rendering Library
  7//
  8// --------------------------------------------------------------------------
  9//
 10// 09-14-2003		Hans-Martin Will	initial version
 11//
 12// --------------------------------------------------------------------------
 13//
 14// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 15// 
 16// Redistribution and use in source and binary forms, with or without 
 17// modification, are permitted provided that the following conditions are 
 18// met:
 19// 
 20//	 *  Redistributions of source code must retain the above copyright
 21// 		notice, this list of conditions and the following disclaimer. 
 22//   *	Redistributions in binary form must reproduce the above copyright
 23// 		notice, this list of conditions and the following disclaimer in the 
 24// 		documentation and/or other materials provided with the distribution. 
 25// 
 26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 31// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 36// THE POSSIBILITY OF SUCH DAMAGE.
 37//
 38// ==========================================================================
 39
 40
 41#include "OGLES.h"
 42#include "GLES/gl.h"
 43#include "Config.h"
 44#include "Color.h"
 45#include "RasterizerState.h"
 46
 47
 48namespace EGL {
 49
 50	class Rasterizer;
 51	class CodeGenerator;
 52
 53	class Texture { 
 54
 55#ifdef EGL_ON_LINUX
 56		friend class Rasterizer;
 57		friend class CodeGenerator;
 58#else
 59		friend Rasterizer;
 60		friend CodeGenerator;
 61#endif
 62
 63	public:
 64
 65		void Init();
 66		void Dispose();
 67
 68		bool Initialize(U32 width, U32 height, RasterizerState::TextureFormat format);
 69
 70		U32 GetWidth() const				{ return 1 << m_LogWidth; }
 71		U32 GetHeight() const				{ return 1 << m_LogHeight; }
 72		U32 GetLogWidth() const				{ return m_LogWidth; }
 73		U32 GetLogHeight() const			{ return m_LogHeight; }
 74		U32 GetLogBytesPerPixel() const;
 75
 76		RasterizerState::TextureFormat 
 77			GetInternalFormat() const		{ return m_InternalFormat; }
 78
 79		U8 GetBytesPerPixel() const			{ return s_BytesPerPixel[m_InternalFormat]; }
 80
 81		void * GetData() const				{ return m_Data; }
 82
 83	private:
 84		void *							m_Data;
 85		U32								m_LogWidth;
 86		U32								m_LogHeight;
 87		RasterizerState::TextureFormat	m_InternalFormat;
 88
 89		const static U8 s_BytesPerPixel[];
 90	};
 91
 92
 93	class MultiTexture {
 94
 95#ifdef EGL_ON_LINUX
 96		friend class Rasterizer;
 97#else
 98		friend Rasterizer;
 99#endif
100
101	public:
102		enum {
103			MAX_LEVELS = RasterizerState::LogMaxTextureSize
104		};
105
106		MultiTexture();
107		~MultiTexture();
108
109		Texture * GetTexture(int level)				{ return m_TextureLevels + level; }
110		const Texture * GetTexture(int level) const	{ return m_TextureLevels + level; }
111
112		void SetMinFilterMode(RasterizerState::FilterMode mode)		{ m_MinFilterMode = mode; }
113		void SetMagFilterMode(RasterizerState::FilterMode mode)		{ m_MagFilterMode = mode; }
114		void SetMipmapFilterMode(RasterizerState::FilterMode mode)	{ m_MipmapFilterMode = mode; }
115		void SetWrappingModeS(RasterizerState::WrappingMode mode)	{ m_WrappingModeS = mode; }
116		void SetWrappingModeT(RasterizerState::WrappingMode mode)	{ m_WrappingModeT = mode; }
117
118		RasterizerState::FilterMode GetMinFilterMode() const		{ return m_MinFilterMode; }
119		RasterizerState::FilterMode GetMagFilterMode() const		{ return m_MagFilterMode; }
120		RasterizerState::FilterMode GetMipmapFilterMode() const		{ return m_MipmapFilterMode; }
121		RasterizerState::WrappingMode GetWrappingModeS() const		{ return m_WrappingModeS; }
122		RasterizerState::WrappingMode GetWrappingModeT() const		{ return m_WrappingModeT; }
123
124		RasterizerState::TextureFormat 
125			GetInternalFormat() const				{ return m_TextureLevels[0].GetInternalFormat(); }
126
127		bool IsComplete() const;
128
129		bool IsMipMap() const;
130
131	private:
132		Texture							m_TextureLevels[MAX_LEVELS + 1];
133		RasterizerState::FilterMode		m_MinFilterMode;
134		RasterizerState::FilterMode		m_MagFilterMode;
135		RasterizerState::FilterMode		m_MipmapFilterMode;
136		RasterizerState::WrappingMode	m_WrappingModeS;
137		RasterizerState::WrappingMode	m_WrappingModeT;
138		U32								m_Levels;
139	};
140
141	inline bool MultiTexture :: IsMipMap() const {
142		return 
143			m_MipmapFilterMode == RasterizerState::FilterModeNearest ||
144			m_MipmapFilterMode == RasterizerState::FilterModeLinear;
145	}
146
147}
148
149#endif //ndef EGL_TEXTURE_H