… | |
… | |
5 | |
5 | |
6 | #include "opengl.h" |
6 | #include "opengl.h" |
7 | #include "material.h" |
7 | #include "material.h" |
8 | #include "view.h" |
8 | #include "view.h" |
9 | #include "util.h" |
9 | #include "util.h" |
10 | |
|
|
11 | material::~material () |
|
|
12 | { |
|
|
13 | } |
|
|
14 | |
10 | |
15 | GLuint |
11 | GLuint |
16 | texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
12 | texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
17 | { |
13 | { |
18 | GLuint name; |
14 | GLuint name; |
… | |
… | |
67 | SDL_FreeSurface (image); /* No longer needed */ |
63 | SDL_FreeSurface (image); /* No longer needed */ |
68 | |
64 | |
69 | return name; |
65 | return name; |
70 | } |
66 | } |
71 | |
67 | |
|
|
68 | material::~material () |
|
|
69 | { |
|
|
70 | } |
|
|
71 | |
72 | void material::enable (view &ctx) |
72 | void material::enable (view &ctx) |
73 | { |
73 | { |
74 | pass::matmap_t &matmap = ctx.pass_data->matmap; |
74 | pass::matmap_t &matmap = ctx.pass_data->matmap; |
75 | |
75 | |
76 | pass::matmap_t::iterator i = matmap.find (this); |
76 | pass::matmap_t::iterator i = matmap.find (this); |
77 | shader::program_object *p; |
|
|
78 | |
77 | |
79 | if (i == matmap.end ()) |
78 | if (i == matmap.end ()) |
80 | { |
79 | { |
81 | shader::program_object po; |
80 | string vsh_src, fsh_src; |
82 | |
81 | |
83 | shader::shader_builder::start (); |
82 | shader::shader_builder::start (); |
84 | vsh (ctx); |
83 | vsh (ctx); |
85 | |
84 | |
86 | if (ctx.pass_data->l) |
85 | if (ctx.pass_data->l) |
… | |
… | |
90 | using namespace shader::compile; |
89 | using namespace shader::compile; |
91 | |
90 | |
92 | z (vout.position) = log2 (z (vout.position) / w (vout.position)) * w (vout.position); |
91 | z (vout.position) = log2 (z (vout.position) / w (vout.position)) * w (vout.position); |
93 | } |
92 | } |
94 | |
93 | |
95 | po->vsh->compile (shader::shader_builder::stop ()); |
94 | vsh_src = shader::shader_builder::stop (); |
96 | |
95 | |
|
|
96 | if (ctx.pass_data->l || 1) |
|
|
97 | { |
97 | shader::shader_builder::start (); |
98 | shader::shader_builder::start (); |
98 | shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); |
99 | shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); |
99 | fsh (ctx); |
100 | fsh (ctx); |
100 | po->fsh->compile (shader::shader_builder::stop ()); |
|
|
101 | |
101 | |
102 | po->link (); |
102 | fsh_src = shader::shader_builder::stop (); |
|
|
103 | } |
103 | |
104 | |
|
|
105 | shader::program_object po = shader::get_program (vsh_src, fsh_src); |
104 | matmap.insert (pass::matmap_t::value_type (this, po)); |
106 | matmap.insert (pass::matmap_t::value_type (this, po)); |
105 | |
107 | |
106 | p = &po; |
108 | po->enable (); |
107 | } |
109 | } |
108 | else |
110 | else |
109 | p = &i->second; |
111 | i->second->enable (); |
110 | |
|
|
111 | (*p)->enable (); |
|
|
112 | } |
112 | } |
113 | |
113 | |
114 | void material::disable (view &ctx) |
114 | void material::disable (view &ctx) |
115 | { |
115 | { |
116 | } |
116 | } |