Improved OpenGL Shader Language support for game engine. The python interface is...
[blender.git] / source / gameengine / Ketsji / BL_Material.cpp
1 // ------------------------------------
2 #include "BL_Material.h"
3 #include "DNA_material_types.h"
4 #include "DNA_texture_types.h"
5 #include "DNA_image_types.h"
6 #include "DNA_mesh_types.h"
7 #include "IMB_imbuf_types.h"
8 #include "IMB_imbuf.h"
9
10 MTex* getImageFromMaterial(Material *mat, int index)
11 {
12         if(!mat) return 0;
13         
14         if(!(index >=0 && index <=10) ) return 0;
15         
16         MTex *m = mat->mtex[index];
17         return m?m:0;
18 }
19
20 int getNumTexChannels( Material *mat )
21 {
22         int count = -1;
23         if(!mat) return -1;
24
25         for(count =0; (count < 10) && mat->mtex[count] != 0; count++) {}
26         return count;
27 }
28
29 BL_Material::BL_Material()
30 {
31         rgb[0] = 0;
32         rgb[1] = 0;
33         rgb[2] = 0;
34         rgb[3] = 0;
35         IdMode = 0;
36         ras_mode = 0;
37         tile = 0;
38         matname = "NoMaterial";
39         matcolor[0] = 0.5f;
40         matcolor[1] = 0.5f;
41         matcolor[2] = 0.5f;
42         matcolor[3] = 0.5f;
43         speccolor[0] = 1.f;
44         speccolor[1] = 1.f;
45         speccolor[2] = 1.f;
46         transp = 0;
47         hard = 50.f;
48         spec_f = 0.5f;
49         alpha = 1.f;
50         emit = 0.f;
51         mode = 0;
52         material = 0;
53         tface = 0;
54         material_index = 0;
55         amb=0.5f;
56         num_enabled = 0;
57         num_users = 1;
58         share = false;
59
60         int i;
61         for(i=0; i<4; i++)
62                 uv[i] = MT_Point2(0.f,1.f);
63
64         for(i=0; i<MAXTEX; i++) // :(
65         {
66                 mapping[i].mapping = 0;
67                 mapping[i].offsets[0] = 0.f;
68                 mapping[i].offsets[1] = 0.f;
69                 mapping[i].offsets[2] = 0.f;
70                 mapping[i].scale[0]   = 1.f;
71                 mapping[i].scale[1]   = 1.f;
72                 mapping[i].scale[2]   = 1.f;
73                 mapping[i].projplane[0] = PROJX;
74                 mapping[i].projplane[1] = PROJY;
75                 mapping[i].projplane[2] = PROJZ;
76                 mapping[i].objconame = "";
77                 mtexname[i] = "NULL";
78                 imageId[i]="NULL";
79                 flag[i] = 0;
80                 texname[i] = "NULL";
81                 tilexrep[i] = 1;
82                 tileyrep[i] = 1;
83                 color_blend[i] = 1.f;
84                 blend_mode[i]   = 0;
85                 img[i] = 0;
86                 cubemap[i] = 0;
87         }
88 }
89
90 void BL_Material::SetConversionRGB(unsigned int *nrgb) {
91         rgb[0]=*nrgb++;
92         rgb[1]=*nrgb++;
93         rgb[2]=*nrgb++;
94         rgb[3]=*nrgb;
95 }
96
97 void BL_Material::GetConversionRGB(unsigned int *nrgb) {
98         *nrgb++ = rgb[0];
99         *nrgb++ = rgb[1];
100         *nrgb++ = rgb[2];
101         *nrgb   = rgb[3];
102 }
103
104 void BL_Material::SetConversionUV(MT_Point2 *nuv) {
105         uv[0] = *nuv++;
106         uv[1] = *nuv++;
107         uv[2] = *nuv++;
108         uv[3] = *nuv;
109 }
110
111 void BL_Material::GetConversionUV(MT_Point2 *nuv){
112         *nuv++ = uv[0];
113         *nuv++ = uv[1];
114         *nuv++ = uv[2];
115         *nuv   = uv[3];
116 }
117
118
119 void BL_Material::SetSharedMaterial(bool v)
120 {
121         if((v && num_users == -1) || num_users > 1 )
122                 share = true;
123         else 
124                 share = false;
125 }
126
127 bool BL_Material::IsShared()
128 {
129         return share;
130 }
131
132 void BL_Material::SetUsers(int num)
133 {
134         num_users = num;
135 }
136