]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CSoftwareTexture2.h
37bd1c7dbd9bac2e393d2e10fb594e1dcc6c2630
[irrlicht.git] / source / Irrlicht / CSoftwareTexture2.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_SOFTWARE_2_TEXTURE_H_INCLUDED__\r
6 #define __C_SOFTWARE_2_TEXTURE_H_INCLUDED__\r
7 \r
8 #include "SoftwareDriver2_compile_config.h"\r
9 \r
10 #include "ITexture.h"\r
11 #if defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)\r
12 #include "IVideoDriver.h"\r
13 #else\r
14 #include "IRenderTarget.h"\r
15 #endif\r
16 #include "CImage.h"\r
17 \r
18 namespace irr\r
19 {\r
20 namespace video\r
21 {\r
22 \r
23 class CBurningVideoDriver;\r
24 \r
25 /*!\r
26         interface for a Video Driver dependent Texture.\r
27 */\r
28 struct CSoftwareTexture2_Bound\r
29 {\r
30         f32 w;  // width - 0.5f;\r
31         f32 h;  // height- 0.5f;\r
32         f32 cx; // texelcenter x 1.f/width*0.5f\r
33         f32 cy; // texelcenter y 1.f/height*0.5f\r
34 };\r
35 \r
36 class CSoftwareTexture2 : public ITexture\r
37 {\r
38 public:\r
39 \r
40         //! constructor\r
41         enum eTex2Flags\r
42         {\r
43                 GEN_MIPMAP                      = 1,            // has mipmaps\r
44                 GEN_MIPMAP_AUTO         = 2,            // automatic mipmap generation\r
45                 IS_RENDERTARGET         = 4,\r
46                 ALLOW_NPOT                      = 8,            //allow non power of two\r
47                 IMAGE_IS_LINEAR         = 16,\r
48                 TEXTURE_IS_LINEAR       = 32,\r
49         };\r
50         CSoftwareTexture2(IImage* surface, const io::path& name, u32 flags /*eTex2Flags*/, CBurningVideoDriver* driver);\r
51 \r
52         //! destructor\r
53         virtual ~CSoftwareTexture2();\r
54 \r
55         u32 getMipmapLevel(s32 newLevel) const\r
56         {\r
57                 if ( newLevel < 0 ) newLevel = 0;\r
58                 else if ( newLevel >= (s32)array_size(MipMap)) newLevel = array_size(MipMap) - 1;\r
59 \r
60                 while ( newLevel > 0 && MipMap[newLevel] == 0 ) newLevel -= 1;\r
61                 return newLevel;\r
62         }\r
63 \r
64         //! lock function\r
65 #if defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)\r
66         virtual void* lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)\r
67 #else\r
68         virtual void* lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel, u32 layer, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_\r
69 #endif\r
70         {\r
71                 if (Flags & GEN_MIPMAP)\r
72                 {\r
73                         //called from outside. must test\r
74                         MipMapLOD = getMipmapLevel(mipmapLevel);\r
75                         Size = MipMap[MipMapLOD]->getDimension();\r
76                         Pitch = MipMap[MipMapLOD]->getPitch();\r
77                 }\r
78 \r
79                 return MipMap[MipMapLOD]->getData();\r
80         }\r
81 \r
82         //! unlock function\r
83         virtual void unlock() _IRR_OVERRIDE_\r
84         {\r
85         }\r
86 /*\r
87         //! compare the area drawn with the area of the texture\r
88         f32 getLODFactor( const f32 texArea ) const\r
89         {\r
90                 return MipMap0_Area[0]* MipMap0_Area[1] * 0.5f * texArea;\r
91                 //return MipMap[0]->getImageDataSizeInPixels () * texArea;\r
92         }\r
93 */\r
94 \r
95         const u32* getMipMap0_Area() const\r
96         {\r
97                 return MipMap0_Area;\r
98         }\r
99         f32 get_lod_bias() const { return LodBIAS; }\r
100 \r
101         //! returns unoptimized surface (misleading name. burning can scale down originalimage)\r
102         virtual CImage* getImage() const\r
103         {\r
104                 return MipMap[0];\r
105         }\r
106 \r
107         //! returns texture surface\r
108         virtual CImage* getTexture() const\r
109         {\r
110                 return MipMap[MipMapLOD];\r
111         }\r
112 \r
113         //precalculated dimx-1/dimx*0.5f\r
114         const CSoftwareTexture2_Bound& getTexBound() const\r
115         {\r
116                 return TexBound[MipMapLOD];\r
117         }\r
118 \r
119 #if !defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)\r
120         virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_;\r
121 #else\r
122         virtual void regenerateMipMapLevels(void* data = 0);\r
123 #endif\r
124 \r
125 \r
126 #if defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)\r
127         const core::dimension2d<u32>& getOriginalSize() const { return OriginalSize; };\r
128         const core::dimension2d<u32>& getSize() const { return Size; };\r
129         E_DRIVER_TYPE getDriverType() const { return DriverType; };\r
130         ECOLOR_FORMAT getColorFormat() const { return ColorFormat; };\r
131         ECOLOR_FORMAT getOriginalColorFormat() const { return OriginalColorFormat; };\r
132         u32 getPitch() const { return Pitch; };\r
133         bool hasMipMaps() const { return HasMipMaps; }\r
134         bool isRenderTarget() const { return IsRenderTarget; }\r
135 \r
136         core::dimension2d<u32> OriginalSize;\r
137         core::dimension2d<u32> Size;\r
138         E_DRIVER_TYPE DriverType;\r
139         ECOLOR_FORMAT OriginalColorFormat;\r
140         ECOLOR_FORMAT ColorFormat;\r
141         u32 Pitch;\r
142         bool HasMipMaps;\r
143         bool IsRenderTarget;\r
144 #endif\r
145 \r
146 private:\r
147         void calcDerivative();\r
148 \r
149         //! controls MipmapSelection. relation between drawn area and image size\r
150         u32 MipMapLOD; // 0 .. original Texture pot -SOFTWARE_DRIVER_2_MIPMAPPING_MAX\r
151         u32 Flags; //eTex2Flags\r
152         CBurningVideoDriver* Driver;\r
153 \r
154         CImage* MipMap[SOFTWARE_DRIVER_2_MIPMAPPING_MAX];\r
155         CSoftwareTexture2_Bound TexBound[SOFTWARE_DRIVER_2_MIPMAPPING_MAX];\r
156         u32 MipMap0_Area[2];\r
157         f32 LodBIAS;    // Tweak mipmap selection\r
158 };\r
159 \r
160 /*!\r
161 interface for a Video Driver dependent render target.\r
162 */\r
163 class CSoftwareRenderTarget2 : public IRenderTarget\r
164 {\r
165 public:\r
166         CSoftwareRenderTarget2(CBurningVideoDriver* driver);\r
167         virtual ~CSoftwareRenderTarget2();\r
168 \r
169         virtual void setTexture(const core::array<ITexture*>& texture, ITexture* depthStencil, const core::array<E_CUBE_SURFACE>& cubeSurfaces) _IRR_OVERRIDE_;\r
170 \r
171 #if defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)\r
172         E_DRIVER_TYPE DriverType;\r
173         core::array<ITexture*> Texture;\r
174 #endif\r
175 \r
176 protected:\r
177         CBurningVideoDriver* Driver;\r
178 };\r
179 \r
180 } // end namespace video\r
181 } // end namespace irr\r
182 \r
183 #endif // __C_SOFTWARE_2_TEXTURE_H_INCLUDED__\r
184 \r
185 \r