Initial revision
[0ad:0ad.git] / terrain / bak / 0 / Texture.cpp
1 //***********************************************************
2 //
3 // Name:                Texture.Cpp
4 // Author:              Poya Manouchehri
5 //
6 // Description: The texture class holds data about a texture,
7 //                              and certain flags descibing the filtering used
8 //                              for the texture. It must be registered with the
9 //                              renderer before being used.
10 //
11 //***********************************************************
12
13 #include "Texture.H"
14
15 CTexture::CTexture ()
16 {
17         m_MipMap = true;
18         m_RegisterID = -1;
19 }
20
21 CTexture::~CTexture ()
22 {
23         CBitmap::~CBitmap ();
24 }
25
26 FRESULT CTexture::LoadBitmap (char *path, RESOURCETYPE type)
27 {
28         FRESULT result;
29         //load the image
30         result = CBitmap::LoadBitmap (path, type);
31
32         if (result != R_OK)
33                 return result;
34
35         int w = m_Width;
36         int h = m_Height;
37
38         //width must be a power of 2
39         while (w > 1)
40         {
41                 if (w%2 != 0)
42                 {
43                         DestroyData ();
44                         return R_FAIL;
45                 }
46
47                 w /= 2;
48         }
49
50         //height must be a power of 2
51         while (h > 1)
52         {
53                 if (h%2 != 0)
54                 {
55                         DestroyData ();
56                         return R_FAIL;
57                 }
58
59                 h /= 2;
60         }
61
62         return R_OK;
63 }
64
65 FRESULT CTexture::CreateBitmap (RESOURCETYPE type, char *name, int width, int height)
66 {
67         //must be square
68         if (width != height)
69                 return R_BADPARAMS;
70
71         int w = width;
72         int h = height;
73
74         //width must be a power of 2
75         while (w > 1)
76         {
77                 if (w%2 != 0)
78                 {
79                         DestroyData ();
80                         return R_FAIL;
81                 }
82
83                 w /= 2;
84         }
85
86         //height must be a power of 2
87         while (h > 1)
88         {
89                 if (h%2 != 0)
90                 {
91                         DestroyData ();
92                         return R_FAIL;
93                 }
94
95                 h /= 2;
96         }
97         return CBitmap::CreateBitmap (type, name, width, height);
98 }