1
+ #include " comp.h"
2
+
3
+ extern " C" {
1
4
#include " graphics/context.h"
2
5
#include " graphics/floatspace.h"
3
6
#include " graphics/material.h"
6
9
#include " graphics/tex.h"
7
10
#include " math/matrix.h"
8
11
#include " util/log.h"
12
+ }
9
13
10
14
#include " tgl/tgl.h"
11
15
@@ -158,51 +162,34 @@ enum {
158
162
TEX_EMISSION,
159
163
};
160
164
161
- typedef struct ilG_computer {
162
- ilG_renderman * rm ;
163
- ilG_matid mat ;
164
- tgl_vao vao ;
165
- GLuint v_vbo , n_vbo , t_vbo ;
166
- GLuint mvp_loc , imt_loc ;
167
- ilG_tex tex_albedo , tex_normal , tex_refraction , tex_emission ;
168
- } ilG_computer ;
169
-
170
- static void comp_draw (void * obj , ilG_rendid id , il_mat * * mats , const unsigned * objects , unsigned num_mats )
165
+ void Computer::draw (il_mat mvp, il_mat imt)
171
166
{
172
- (void )id , (void )objects ;
173
- ilG_computer * self = obj ;
174
- ilG_material * mat = ilG_renderman_findMaterial (self -> rm , self -> mat );
167
+ ilG_material *mat = ilG_renderman_findMaterial (rm, this ->mat );
175
168
176
- ilG_tex_bind (& self -> tex_albedo );
177
- ilG_tex_bind (& self -> tex_normal );
178
- ilG_tex_bind (& self -> tex_refraction );
179
- ilG_tex_bind (& self -> tex_emission );
169
+ ilG_tex_bind (&tex_albedo);
170
+ ilG_tex_bind (&tex_normal);
171
+ ilG_tex_bind (&tex_refraction);
172
+ ilG_tex_bind (&tex_emission);
180
173
181
174
ilG_material_bind (mat);
182
- tgl_vao_bind (& self -> vao );
183
- for (unsigned i = 0 ; i < num_mats ; i ++ ) {
184
- ilG_material_bindMatrix (mat , self -> mvp_loc , mats [0 ][i ]);
185
- ilG_material_bindMatrix (mat , self -> imt_loc , mats [1 ][i ]);
186
- glDrawArrays (GL_TRIANGLES , 0 , 36 );
187
- }
175
+ tgl_vao_bind (&vao);
176
+ ilG_material_bindMatrix (mat, mvp_loc, mvp);
177
+ ilG_material_bindMatrix (mat, imt_loc, imt);
178
+ glDrawArrays (GL_TRIANGLES, 0 , 36 );
188
179
}
189
180
190
- static void comp_free ( void * obj )
181
+ void Computer::free ( )
191
182
{
192
- ilG_computer * self = obj ;
193
- ilG_renderman_delMaterial (self -> rm , self -> mat );
194
- tgl_vao_free (& self -> vao );
195
- glDeleteBuffers (1 , & self -> v_vbo );
196
- glDeleteBuffers (1 , & self -> n_vbo );
197
- glDeleteBuffers (1 , & self -> t_vbo );
198
- free (self );
183
+ ilG_renderman_delMaterial (rm, mat);
184
+ tgl_vao_free (&vao);
185
+ glDeleteBuffers (1 , &v_vbo);
186
+ glDeleteBuffers (1 , &n_vbo);
187
+ glDeleteBuffers (1 , &t_vbo);
199
188
}
200
189
201
- static bool comp_build ( void * obj , ilG_rendid id , ilG_renderman * rm , ilG_buildresult * out )
190
+ bool Computer::build ( ilG_renderman *rm, char **error )
202
191
{
203
- (void )id ;
204
- ilG_computer * self = obj ;
205
- self -> rm = rm ;
192
+ this ->rm = rm;
206
193
207
194
ilG_material m;
208
195
ilG_material_init (&m);
@@ -219,36 +206,36 @@ static bool comp_build(void *obj, ilG_rendid id, ilG_renderman *rm, ilG_buildres
219
206
ilG_material_textureUnit (&m, TEX_NORMAL, " tex_Normal" );
220
207
ilG_material_textureUnit (&m, TEX_REFRACTION, " tex_Reflect" );
221
208
ilG_material_textureUnit (&m, TEX_EMISSION, " tex_Emission" );
222
- if (!ilG_renderman_addMaterialFromFile (rm , m , "comp.vert" , "comp.frag" , & self -> mat , & out -> error )) {
209
+ if (!ilG_renderman_addMaterialFromFile (rm, m, " comp.vert" , " comp.frag" , &mat, error)) {
223
210
return false ;
224
211
}
225
- ilG_material * mat = ilG_renderman_findMaterial (rm , self -> mat );
226
- self -> mvp_loc = ilG_material_getLoc (mat , "mvp" );
227
- self -> imt_loc = ilG_material_getLoc (mat , "imt" );
212
+ ilG_material *mat = ilG_renderman_findMaterial (rm, this ->mat );
213
+ mvp_loc = ilG_material_getLoc (mat, " mvp" );
214
+ imt_loc = ilG_material_getLoc (mat, " imt" );
228
215
229
- tgl_vao_init (& self -> vao );
230
- tgl_vao_bind (& self -> vao );
231
- glGenBuffers (1 , & self -> v_vbo );
232
- glBindBuffer (GL_ARRAY_BUFFER , self -> v_vbo );
216
+ tgl_vao_init (&vao);
217
+ tgl_vao_bind (&vao);
218
+ glGenBuffers (1 , &v_vbo);
219
+ glBindBuffer (GL_ARRAY_BUFFER, v_vbo);
233
220
glBufferData (GL_ARRAY_BUFFER, sizeof (cube), cube, GL_STATIC_DRAW);
234
221
glVertexAttribPointer (ATTRIB_POSITION, 3 , GL_FLOAT, GL_FALSE, 0 , NULL );
235
222
glEnableVertexAttribArray (ATTRIB_POSITION);
236
- glGenBuffers (1 , & self -> n_vbo );
237
- glBindBuffer (GL_ARRAY_BUFFER , self -> n_vbo );
223
+ glGenBuffers (1 , &n_vbo);
224
+ glBindBuffer (GL_ARRAY_BUFFER, n_vbo);
238
225
glBufferData (GL_ARRAY_BUFFER, sizeof (cube_n), cube_n, GL_STATIC_DRAW);
239
226
glVertexAttribPointer (ATTRIB_NORMAL, 3 , GL_FLOAT, GL_FALSE, 0 , NULL );
240
227
glEnableVertexAttribArray (ATTRIB_NORMAL);
241
- glGenBuffers (1 , & self -> t_vbo );
242
- glBindBuffer (GL_ARRAY_BUFFER , self -> t_vbo );
228
+ glGenBuffers (1 , &t_vbo);
229
+ glBindBuffer (GL_ARRAY_BUFFER, t_vbo);
243
230
glBufferData (GL_ARRAY_BUFFER, sizeof (cube_t ), cube_t , GL_STATIC_DRAW);
244
231
glVertexAttribPointer (ATTRIB_TEXCOORD, 2 , GL_FLOAT, GL_FALSE, 0 , NULL );
245
232
glEnableVertexAttribArray (ATTRIB_TEXCOORD);
246
233
247
234
ilG_tex *texes[4 ] = {
248
- & self -> tex_albedo ,
249
- & self -> tex_normal ,
250
- & self -> tex_refraction ,
251
- & self -> tex_emission
235
+ &tex_albedo,
236
+ &tex_normal,
237
+ &tex_refraction,
238
+ &tex_emission
252
239
};
253
240
static const char *const files[] = {
254
241
" comp1a.png" ,
@@ -267,20 +254,5 @@ static bool comp_build(void *obj, ilG_rendid id, ilG_renderman *rm, ilG_buildres
267
254
texes[i]->unit = i;
268
255
}
269
256
270
- int * types = calloc (2 , sizeof (int ));
271
- types [0 ] = ILG_MVP ;
272
- types [1 ] = ILG_IMT ;
273
- out -> free = comp_free ;
274
- out -> draw = comp_draw ;
275
- out -> types = types ;
276
- out -> num_types = 2 ;
277
- out -> obj = obj ;
278
- out -> name = strdup ("Computer" );
279
257
return true ;
280
258
}
281
-
282
- ilG_builder ilG_computer_builder ()
283
- {
284
- ilG_computer * self = calloc (1 , sizeof (ilG_computer ));
285
- return ilG_builder_wrap (self , comp_build );
286
- }
0 commit comments