camera.set_aspect(1);
camera.set_depth_clip(0.1, 100);
- shdata.uniform("environment", 4);
}
void EnvironmentMap::setup_frame() const
if(!enabled_passes.count(tag))
return renderer.render(renderable, tag);
+ Renderer::Push _push_rend(renderer);
+
+ unsigned unit = renderer.allocate_effect_texunit();
+ shdata.uniform("environment", static_cast<int>(unit));
+ env_tex.bind_to(unit);
+
const Matrix &view_matrix = renderer.get_camera()->get_matrix();
// XXX The camera should maybe have store its own object matrix
float env_mdata[9];
env_mdata[8] = view_matrix[10];
shdata.uniform_matrix3("env_eye_matrix", env_mdata);
- env_tex.bind_to(4);
-
- Renderer::Push _push_rend(renderer);
renderer.add_shader_data(shdata);
renderer.render(renderable, tag);
- env_tex.unbind_from(4);
+ env_tex.unbind_from(unit);
}
} // namespace GL
#include "renderer.h"
#include "texture.h"
#include "texturing.h"
+#include "texunit.h"
#include "vertexarray.h"
#include "windingtest.h"
state->texture = 0;
}
+unsigned Renderer::allocate_effect_texunit()
+{
+ return --state->lowest_effect_texunit;
+}
+
void Renderer::set_material(const Material *m)
{
state->material = m;
Renderer::State::State():
texture(0),
texturing(0),
+ lowest_effect_texunit(TexUnit::get_n_units()),
material(0),
lighting(0),
shprog(0),
{
const Texture *texture;
const Texturing *texturing;
+ unsigned lowest_effect_texunit;
const Material *material;
const Lighting *lighting;
Matrix lighting_matrix;
void set_texture(const Texture *);
void set_texturing(const Texturing *);
+ unsigned allocate_effect_texunit();
void set_material(const Material *);
void set_lighting(const Lighting *);
fbo.require_complete();
set_darkness(0.7);
- set_texture_unit(3);
}
void ShadowMap::set_target(const Vector3 &t, float r)
depth_bias = b;
}
-void ShadowMap::set_texture_unit(unsigned u)
-{
- unit = u;
-
- int i = unit;
- shdata.uniform("shadow", i);
- shdata.uniform("shadow_unit", i);
-}
-
void ShadowMap::setup_frame() const
{
if(rendered)
if(!enabled_passes.count(tag))
return renderer.render(renderable, tag);
+ Renderer::Push _push_rend(renderer);
+
+ unsigned unit = renderer.allocate_effect_texunit();
+ int iunit = unit;
+ shdata.uniform("shadow", iunit);
+ shdata.uniform("shadow_unit", iunit);
+
depth_buf.bind_to(unit);
TexGen tg_s, tg_t, tg_r;
tg_s.set_plane(Vector4(shadow_matrix(0, 0), shadow_matrix(0, 1), shadow_matrix(0, 2), shadow_matrix(0, 3)));
else
shdata.uniform("shd_eye_matrix", shadow_matrix);
- Renderer::Push _push_rend(renderer);
renderer.add_shader_data(shdata);
renderer.render(renderable, tag);
mutable Matrix light_matrix;
mutable Matrix view_matrix;
mutable Matrix shadow_matrix;
- unsigned unit;
Texture2D depth_buf;
Vector3 target;
float radius;
thin objects from casting shadows on nearby sufraces. */
void set_depth_bias(float);
- /** Sets the texture unit to bind the shadow map to during the rendering
- phase. Provided to shaders through the shadow and shadow_unit uniforms.
- The default is texture unit 3. */
- void set_texture_unit(unsigned);
-
virtual void setup_frame() const;
virtual void finish_frame() const;