1
1
#include " ball.hpp"
2
2
3
+ #include " Demo.h"
4
+
3
5
extern " C" {
4
6
#include " graphics/context.h"
5
7
#include " graphics/material.h"
@@ -16,76 +18,50 @@ enum {
16
18
17
19
using namespace BouncingLights ;
18
20
19
- extern ilA_fs demo_fs;
20
-
21
- void BallRenderer::free (void *ptr)
21
+ void BallRenderer::free ()
22
22
{
23
- BallRenderer &self = *reinterpret_cast <BallRenderer*>(ptr);
24
- ilG_mesh_free (&self.mesh );
25
- ilG_renderman_delMaterial (self.rm , self.mat );
23
+ ilG_mesh_free (&mesh);
24
+ ilG_renderman_delMaterial (rm, mat);
26
25
}
27
26
28
- void BallRenderer::draw (void *obj, ilG_rendid id, il_mat **mats, const unsigned *objects, unsigned num_mats )
27
+ void BallRenderer::draw (il_mat *mvp, il_mat *imt, il_vec3 *col, size_t count )
29
28
{
30
- (void )id, (void )objects;
31
- BallRenderer &self = *reinterpret_cast <BallRenderer*>(obj);
32
- ilG_material *mat = ilG_renderman_findMaterial (self.rm , self.mat );
33
- ilG_mesh_bind (&self.mesh );
29
+ ilG_material *mat = ilG_renderman_findMaterial (rm, this ->mat );
30
+ ilG_mesh_bind (&mesh);
34
31
ilG_material_bind (mat);
35
- for (unsigned i = 0 ; i < num_mats ; i++) {
36
- ilG_material_bindMatrix (mat, self. mvp_loc , mats[MVP] [i]);
37
- ilG_material_bindMatrix (mat, self. imt_loc , mats[IMT] [i]);
38
- il_vec3 c = self. cols [objects[i] ];
39
- glUniform3f (self. col_loc , c.x , c.y , c.z );
40
- ilG_mesh_draw (&self. mesh );
32
+ for (unsigned i = 0 ; i < count ; i++) {
33
+ ilG_material_bindMatrix (mat, mvp_loc, mvp [i]);
34
+ ilG_material_bindMatrix (mat, imt_loc, imt [i]);
35
+ il_vec3 c = col[i ];
36
+ glUniform3f (col_loc, c.x , c.y , c.z );
37
+ ilG_mesh_draw (&mesh);
41
38
}
42
39
}
43
40
44
- bool BallRenderer::build (void *obj, ilG_rendid id, ilG_renderman *rm, ilG_buildresult *out )
41
+ bool BallRenderer::build (ilG_renderman *rm, char **error )
45
42
{
46
- (void )id;
47
- BallRenderer &b = *reinterpret_cast <BallRenderer*>(obj);
48
-
49
- b.rm = rm;
43
+ this ->rm = rm;
50
44
51
45
ilG_material m;
52
46
ilG_material_init (&m);
53
47
ilG_material_name (&m, " Ball Material" );
54
48
ilG_material_fragData (&m, ILG_CONTEXT_NORMAL, " out_Normal" );
55
49
ilG_material_fragData (&m, ILG_CONTEXT_ALBEDO, " out_Albedo" );
56
50
ilG_material_arrayAttrib (&m, ILG_MESH_POS, " in_Position" );
57
- if (!ilG_renderman_addMaterialFromFile (rm, m, " glow.vert" , " glow.frag" , &b. mat , &out-> error )) {
51
+ if (!ilG_renderman_addMaterialFromFile (rm, m, " glow.vert" , " glow.frag" , &mat, error)) {
58
52
return false ;
59
53
}
60
- ilG_material *mat = ilG_renderman_findMaterial (rm, b. mat );
61
- b. mvp_loc = ilG_material_getLoc (mat, " mvp" );
62
- b. imt_loc = ilG_material_getLoc (mat, " imt" );
63
- b. col_loc = ilG_material_getLoc (mat, " col" );
54
+ ilG_material *mat = ilG_renderman_findMaterial (rm, this -> mat );
55
+ mvp_loc = ilG_material_getLoc (mat, " mvp" );
56
+ imt_loc = ilG_material_getLoc (mat, " imt" );
57
+ col_loc = ilG_material_getLoc (mat, " col" );
64
58
65
- if (!ilG_mesh_fromfile (&b. mesh , &demo_fs, " sphere.obj" )) {
59
+ if (!ilG_mesh_fromfile (&mesh, &demo_fs, " sphere.obj" )) {
66
60
return false ;
67
61
}
68
- if (!ilG_mesh_build (&b. mesh )) {
62
+ if (!ilG_mesh_build (&mesh)) {
69
63
return false ;
70
64
}
71
65
72
- int *types = (int *)calloc (2 , sizeof (int ));
73
- types[MVP] = ILG_MVP;
74
- types[IMT] = ILG_IMT;
75
- out->free = &BallRenderer::free;
76
- out->draw = &BallRenderer::draw;
77
- out->types = types;
78
- out->num_types = 2 ;
79
- out->obj = obj;
80
- out->name = strdup (" Ball" );
81
66
return true ;
82
67
}
83
-
84
- namespace BouncingLights {
85
-
86
- ilG_builder BallRenderer::builder ()
87
- {
88
- return ilG_builder_wrap (this , &BallRenderer::build);
89
- }
90
-
91
- }
0 commit comments