generate "RES"
{
in_suffix ".glsl";
+ in_suffix ".samp";
+ in_suffix ".mesh";
out_suffix ".cpp";
command "mspdatatool";
arguments "-i" "-n" "Msp::GL";
source "source/glsl";
source "source/builders";
source "extensions";
+ source "builtin_data";
source "shaderlib";
build_info
{
--- /dev/null
+const int max_samples = 32;
+
+uniform mat4 projection_matrix;
+
+uniform sampler2D depth;
+uniform sampler2D occlusion;
+uniform sampler2D rotate;
+uniform AmbientOcclusionParams
+{
+ mat4 inverse_projection;
+ float darkness;
+ vec3 sample_points[max_samples];
+ int n_samples;
+ float occlusion_radius;
+ float edge_depth_threshold;
+};
+
+#pragma MSP stage(fragment)
+vec3 project(vec3 position)
+{
+ if(position.z>=0.0)
+ return vec3(0.0, 0.0, -1.0);
+ vec4 pp = projection_matrix*vec4(position, 1.0);
+ return pp.xyz/pp.w;
+}
+
+vec3 unproject(vec3 position)
+{
+ vec4 upp = inverse_projection*vec4(position, 1.0);
+ return upp.xyz/upp.w;
+}
--- /dev/null
+import postprocess;
+import _ambientocclusion;
+
+#pragma MSP stage(fragment)
+void main()
+{
+ vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
+ vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0));
+ float sum = 0.0;
+ float count = 0.0;
+ for(int i=0; i<4; ++i)
+ for(int j=0; j<4; ++j)
+ {
+ vec2 offset = vec2(float(i), float(j))-1.5;
+ vec2 sample_coord = texcoord+offset*tex_scale;
+ float occ = texture(occlusion, sample_coord).r;
+ float sample = texture(depth, sample_coord).r;
+ float z_range = occlusion_radius*length(offset)*edge_depth_threshold;
+ float min_depth = project(vec3(center.xy, center.z+z_range)).z;
+ float max_depth = project(vec3(center.xy, center.z-z_range)).z;
+ if(sample>=min_depth && sample<=max_depth)
+ {
+ sum += occ;
+ count += 1.0;
+ }
+ }
+ vec4 src_color = texture(source, texcoord);
+ frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a);
+}
--- /dev/null
+import postprocess;
+import _ambientocclusion;
+
+#pragma MSP stage(fragment)
+void main()
+{
+ vec4 rv = texture(rotate, gl_FragCoord.xy/4.0)*2.0-1.0;
+ mat3 transform = mat3(rv.xy, 0.0, rv.zx, 0.0, 0.0, 0.0, rv.w)*occlusion_radius;
+ vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
+ float min_depth = project(vec3(center.xy, center.z+occlusion_radius)).z;
+ float occlusion_sum = 0.0;
+ float count = 0.0;
+ for(int i=0; i<n_samples; ++i)
+ {
+ vec3 psp = project(center+transform*sample_points[i]);
+ float sample = texture(depth, psp.xy*0.5+0.5).r;
+ if(sample>=min_depth)
+ {
+ if(sample<psp.z)
+ occlusion_sum += 1.0;
+ count += 1.0;
+ }
+ }
+ frag_color = vec4(1.0-occlusion_sum/count, 0.0, 0.0, 1.0);
+}
--- /dev/null
+uniform sampler2D blurred;
+uniform vec2 delta;
+uniform BloomParams
+{
+ float factors[19];
+ int size;
+ float strength;
+};
--- /dev/null
+import postprocess;
+import _bloom;
+
+#pragma MSP stage(fragment)
+void main()
+{
+ frag_color = vec4(0.0, 0.0, 0.0, 0.0);
+ for(int i=0; i<=size*2; ++i)
+ frag_color += texture(source, texcoord+delta*float(i-size))*factors[i];
+}
--- /dev/null
+import postprocess;
+import _bloom;
+
+#pragma MSP stage(fragment)
+void main()
+{
+ frag_color = mix(texture(source, texcoord), texture(blurred, texcoord), strength);
+}
--- /dev/null
+import postprocess;
+
+uniform sampler1D curve;
+uniform ToneMapping
+{
+ float exposure;
+ vec3 brightness_response;
+};
+
+#pragma MSP stage(fragment)
+void main()
+{
+ vec4 incoming = texture(source, texcoord);
+ float maxc = max(incoming.r, max(incoming.g, incoming.b));
+ if(maxc>0.0)
+ {
+ vec3 saturated = incoming.rgb/maxc;
+ maxc = pow(maxc*exposure+brightness_response.y, brightness_response.x)-brightness_response.z;
+ float c = min(maxc, 1.0);
+ float minc = min(saturated.r, min(saturated.g, saturated.b));
+ incoming.rgb = mix(saturated, vec3(1.0), min((maxc-c)/(1.0-minc), 1.0))*c;
+ }
+ frag_color = vec4(texture(curve, incoming.r).r, texture(curve, incoming.g).r, texture(curve, incoming.b).r, incoming.a);
+}
--- /dev/null
+vertices VERTEX2
+{
+ vertex -1 1;
+ vertex -1 -1;
+ vertex 1 1;
+ vertex 1 -1;
+};
+batch TRIANGLE_STRIP
+{
+ indices 0 1 2 3;
+};
--- /dev/null
+filter LINEAR;
+wrap CLAMP_TO_EDGE;
--- /dev/null
+filter LINEAR;
+wrap CLAMP_TO_EDGE;
+compare LEQUAL;
--- /dev/null
+filter NEAREST;
+wrap CLAMP_TO_EDGE;
--- /dev/null
+import msp_interface;
+#pragma MSP stage(vertex)
+void main()
+{
+ gl_Position = projection_matrix*eye_obj_matrix*vertex;
+}
+#pragma MSP stage(fragment)
+void main()
+{
+ frag_color = vec4(1.0);
+}
--- /dev/null
+vertices VERTEX3
+{
+ vertex 0.0 -0.5257311 -0.8506508;
+ vertex 0.0 0.5257311 -0.8506508;
+ vertex 0.0 -0.5257311 0.8506508;
+ vertex 0.0 0.5257311 0.8506508;
+ vertex -0.8506508 0.0 -0.5257311;
+ vertex -0.8506508 0.0 0.5257311;
+ vertex 0.8506508 0.0 -0.5257311;
+ vertex 0.8506508 0.0 0.5257311;
+ vertex -0.5257311 -0.8506508 0.0;
+ vertex 0.5257311 -0.8506508 0.0;
+ vertex -0.5257311 0.8506508 0.0;
+ vertex 0.5257311 0.8506508 0.0;
+};
+batch TRIANGLES
+{
+ indices 0 1 6;
+ indices 1 0 4;
+ indices 2 3 5;
+ indices 3 2 7;
+ indices 4 5 10;
+ indices 5 4 8;
+ indices 6 7 9;
+ indices 7 6 11;
+ indices 8 9 2;
+ indices 9 8 0;
+ indices 10 11 1;
+ indices 11 10 3;
+ indices 0 8 4;
+ indices 0 6 9;
+ indices 1 4 10;
+ indices 1 11 6;
+ indices 2 5 8;
+ indices 2 9 7;
+ indices 3 10 5;
+ indices 3 7 11;
+};
+winding COUNTERCLOCKWISE;
+++ /dev/null
-const int max_samples = 32;
-
-uniform mat4 projection_matrix;
-
-uniform sampler2D depth;
-uniform sampler2D occlusion;
-uniform sampler2D rotate;
-uniform AmbientOcclusionParams
-{
- mat4 inverse_projection;
- float darkness;
- vec3 sample_points[max_samples];
- int n_samples;
- float occlusion_radius;
- float edge_depth_threshold;
-};
-
-#pragma MSP stage(fragment)
-vec3 project(vec3 position)
-{
- if(position.z>=0.0)
- return vec3(0.0, 0.0, -1.0);
- vec4 pp = projection_matrix*vec4(position, 1.0);
- return pp.xyz/pp.w;
-}
-
-vec3 unproject(vec3 position)
-{
- vec4 upp = inverse_projection*vec4(position, 1.0);
- return upp.xyz/upp.w;
-}
+++ /dev/null
-import postprocess;
-import ambientocclusion;
-
-#pragma MSP stage(fragment)
-void main()
-{
- vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
- vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0));
- float sum = 0.0;
- float count = 0.0;
- for(int i=0; i<4; ++i)
- for(int j=0; j<4; ++j)
- {
- vec2 offset = vec2(float(i), float(j))-1.5;
- vec2 sample_coord = texcoord+offset*tex_scale;
- float occ = texture(occlusion, sample_coord).r;
- float sample = texture(depth, sample_coord).r;
- float z_range = occlusion_radius*length(offset)*edge_depth_threshold;
- float min_depth = project(vec3(center.xy, center.z+z_range)).z;
- float max_depth = project(vec3(center.xy, center.z-z_range)).z;
- if(sample>=min_depth && sample<=max_depth)
- {
- sum += occ;
- count += 1.0;
- }
- }
- vec4 src_color = texture(source, texcoord);
- frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a);
-}
+++ /dev/null
-import postprocess;
-import ambientocclusion;
-
-#pragma MSP stage(fragment)
-void main()
-{
- vec4 rv = texture(rotate, gl_FragCoord.xy/4.0)*2.0-1.0;
- mat3 transform = mat3(rv.xy, 0.0, rv.zx, 0.0, 0.0, 0.0, rv.w)*occlusion_radius;
- vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
- float min_depth = project(vec3(center.xy, center.z+occlusion_radius)).z;
- float occlusion_sum = 0.0;
- float count = 0.0;
- for(int i=0; i<n_samples; ++i)
- {
- vec3 psp = project(center+transform*sample_points[i]);
- float sample = texture(depth, psp.xy*0.5+0.5).r;
- if(sample>=min_depth)
- {
- if(sample<psp.z)
- occlusion_sum += 1.0;
- count += 1.0;
- }
- }
- frag_color = vec4(1.0-occlusion_sum/count, 0.0, 0.0, 1.0);
-}
+++ /dev/null
-uniform sampler2D blurred;
-uniform vec2 delta;
-uniform BloomParams
-{
- float factors[19];
- int size;
- float strength;
-};
+++ /dev/null
-import postprocess;
-import bloom;
-
-#pragma MSP stage(fragment)
-void main()
-{
- frag_color = vec4(0.0, 0.0, 0.0, 0.0);
- for(int i=0; i<=size*2; ++i)
- frag_color += texture(source, texcoord+delta*float(i-size))*factors[i];
-}
+++ /dev/null
-import postprocess;
-import bloom;
-
-#pragma MSP stage(fragment)
-void main()
-{
- frag_color = mix(texture(source, texcoord), texture(blurred, texcoord), strength);
-}
+++ /dev/null
-import postprocess;
-
-uniform sampler1D curve;
-uniform ToneMapping
-{
- float exposure;
- vec3 brightness_response;
-};
-
-#pragma MSP stage(fragment)
-void main()
-{
- vec4 incoming = texture(source, texcoord);
- float maxc = max(incoming.r, max(incoming.g, incoming.b));
- if(maxc>0.0)
- {
- vec3 saturated = incoming.rgb/maxc;
- maxc = pow(maxc*exposure+brightness_response.y, brightness_response.x)-brightness_response.z;
- float c = min(maxc, 1.0);
- float minc = min(saturated.r, min(saturated.g, saturated.b));
- incoming.rgb = mix(saturated, vec3(1.0), min((maxc-c)/(1.0-minc), 1.0))*c;
- }
- frag_color = vec4(texture(curve, incoming.r).r, texture(curve, incoming.g).r, texture(curve, incoming.b).r, incoming.a);
-}
+++ /dev/null
-import msp_interface;
-#pragma MSP stage(vertex)
-void main()
-{
- gl_Position = projection_matrix*eye_obj_matrix*vertex;
-}
-#pragma MSP stage(fragment)
-void main()
-{
- frag_color = vec4(1.0);
-}
pipeline.add_postprocessor(*proc);
else if(i->postprocessor_template)
{
- proc = i->postprocessor_template->create(pipeline.get_width(), pipeline.get_height());
+ proc = i->postprocessor_template->create(tmpl.get_resources(), pipeline.get_width(), pipeline.get_height());
if(proc)
pipeline.add_postprocessor_owned(proc);
}
#include "colorcurve.h"
#include "lighting.h"
#include "pipelinetemplate.h"
+#include "resources.h"
#include "tests.h"
using namespace std;
namespace GL {
PipelineTemplate::PipelineTemplate():
+ resources(0),
hdr(false),
alpha(false),
required_multisample(0),
delete i->postprocessor_template;
}
+Resources &PipelineTemplate::get_resources() const
+{
+ if(!resources)
+ throw logic_error("no resources");
+ return *resources;
+}
+
PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
{
}
-PipelineTemplate::Loader::Loader(PipelineTemplate &t):
- DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
-{
- init();
-}
-
PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
- DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
-{
- init();
-}
-
-void PipelineTemplate::Loader::init()
+ DataFile::CollectionObjectLoader<PipelineTemplate, Resources>(t, &c)
{
add("hdr", &PipelineTemplate::hdr);
add("alpha", &PipelineTemplate::alpha);
add("multisample", &Loader::multisample_range);
add("pass", &Loader::pass);
add("postprocessor", &Loader::postprocessor);
+
+ obj.resources = &c;
}
void PipelineTemplate::Loader::postprocessor_loaded()
};
public:
- class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate>, public PostProcLoader
+ class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate, Resources>, public PostProcLoader
{
public:
- Loader(PipelineTemplate &);
Loader(PipelineTemplate &, Collection &);
- private:
- void init();
virtual void postprocessor_loaded();
void multisample(unsigned);
private:
typedef DataFile::LoadableTypeRegistry<PostProcLoader, PostProcLoader::AddPostProc> PostProcessorRegistry;
+ Resources *resources;
bool hdr;
bool alpha;
unsigned required_multisample;
PipelineTemplate();
~PipelineTemplate();
+ Resources &get_resources() const;
bool get_hdr() const { return hdr; }
bool get_alpha() const { return alpha; }
unsigned get_required_multisample() const { return required_multisample; }
#include "blend.h"
#include "camera.h"
#include "renderer.h"
+#include "resources.h"
#include "shader.h"
#include "tests.h"
namespace Msp {
namespace GL {
-AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
+AmbientOcclusion::AmbientOcclusion(Resources &resources, unsigned w, unsigned h, float):
occlude_target(w, h, (RENDER_COLOR,R8)),
- occlude_shader("ambientocclusion_occlude.glsl"),
- combine_shader("ambientocclusion_combine.glsl"),
- quad(get_fullscreen_quad()),
- linear_sampler(get_linear_sampler()),
- nearest_sampler(get_nearest_sampler())
+ occlude_shader(resources.get<Program>("_ambientocclusion_occlude.glsl")),
+ combine_shader(resources.get<Program>("_ambientocclusion_combine.glsl")),
+ quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
+ linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
+ nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
{
- texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR), linear_sampler.get());
+ texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR), &linear_sampler);
unsigned seed = 1;
rotate_lookup.storage(RGBA8, 4, 4, 1);
}
rotate_lookup.image(0, data);
- texturing.attach(3, rotate_lookup, nearest_sampler.get());
+ texturing.attach(3, rotate_lookup, &nearest_sampler);
shdata.uniform("source", 0);
shdata.uniform("depth", 1);
void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const Texture2D &depth)
{
- texturing.attach(0, color, nearest_sampler.get());
- texturing.attach(1, depth, nearest_sampler.get());
+ texturing.attach(0, color, &nearest_sampler);
+ texturing.attach(1, depth, &nearest_sampler);
if(renderer.get_camera())
shdata.uniform("inverse_projection", invert(renderer.get_camera()->get_projection_matrix()));
{
BindRestore bind_fbo(occlude_target.get_framebuffer());
- quad->draw(renderer);
+ quad.draw(renderer);
}
renderer.set_shader_program(&combine_shader);
- quad->draw(renderer);
+ quad.draw(renderer);
}
edge_depth_threshold(0.1f)
{ }
-AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const
+AmbientOcclusion *AmbientOcclusion::Template::create(Resources &res, unsigned width, unsigned height) const
{
- RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(width/size_divisor, height/size_divisor);
+ RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(res, width/size_divisor, height/size_divisor);
ao->set_n_samples(n_samples);
ao->set_occlusion_radius(occlusion_radius);
ao->set_darkness(darkness);
Template();
- virtual AmbientOcclusion *create(unsigned, unsigned) const;
+ virtual AmbientOcclusion *create(Resources &, unsigned, unsigned) const;
};
private:
Texture2D rotate_lookup;
RenderTarget occlude_target;
Texturing texturing;
- Program occlude_shader;
- Program combine_shader;
+ const Program &occlude_shader;
+ const Program &combine_shader;
mutable ProgramData shdata;
- RefPtr<Mesh> quad;
- RefPtr<Sampler> linear_sampler;
- RefPtr<Sampler> nearest_sampler;
+ const Mesh &quad;
+ const Sampler &linear_sampler;
+ const Sampler &nearest_sampler;
public:
- AmbientOcclusion(unsigned, unsigned, float = 1.0f);
+ AmbientOcclusion(Resources &, unsigned, unsigned, float = 1.0f);
private:
static float random(unsigned &);
#include "bloom.h"
#include "misc.h"
#include "renderer.h"
+#include "resources.h"
#include "shader.h"
#include "tests.h"
#include "texunit.h"
namespace Msp {
namespace GL {
-Bloom::Bloom(unsigned w, unsigned h):
- blur_shader("bloom_blur.glsl"),
- combine_shader("bloom_combine.glsl"),
- quad(get_fullscreen_quad()),
- nearest_sampler(get_nearest_sampler()),
- linear_sampler(get_linear_sampler())
+Bloom::Bloom(Resources &resources, unsigned w, unsigned h):
+ blur_shader(resources.get<Program>("_bloom_blur.glsl")),
+ combine_shader(resources.get<Program>("_bloom_combine.glsl")),
+ quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
+ nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp")),
+ linear_sampler(resources.get<Sampler>("_linear_clamp.samp"))
{
blur_shdata[0].uniform("delta", 1.0f/w, 0.0f);
blur_shdata[1].uniform("delta", 0.0f, 1.0f/h);
common_shdata.uniform("source", 0);
common_shdata.uniform("blurred", 1);
- combine_texturing.attach(1, target[1]->get_target_texture(RENDER_COLOR), linear_sampler.get());
+ combine_texturing.attach(1, target[1]->get_target_texture(RENDER_COLOR), &linear_sampler);
set_radius(2.0f);
set_strength(0.2f);
{
BindRestore bind_fbo(target[i]->get_framebuffer());
Renderer::Push push2(renderer);
- renderer.set_texture(i ? &target[0]->get_target_texture(RENDER_COLOR) : &src, nearest_sampler.get());
+ renderer.set_texture(i ? &target[0]->get_target_texture(RENDER_COLOR) : &src, &nearest_sampler);
renderer.add_shader_data(blur_shdata[i]);
- quad->draw(renderer);
+ quad.draw(renderer);
}
- combine_texturing.attach(0, src, nearest_sampler.get());
+ combine_texturing.attach(0, src, &nearest_sampler);
renderer.set_texturing(&combine_texturing);
renderer.set_shader_program(&combine_shader);
- quad->draw(renderer);
+ quad.draw(renderer);
}
strength(0.2f)
{ }
-Bloom *Bloom::Template::create(unsigned width, unsigned height) const
+Bloom *Bloom::Template::create(Resources &res, unsigned width, unsigned height) const
{
- RefPtr<Bloom> bloom = new Bloom(width/size_divisor, height/size_divisor);
+ RefPtr<Bloom> bloom = new Bloom(res, width/size_divisor, height/size_divisor);
bloom->set_radius(radius);
bloom->set_strength(strength);
return bloom.release();
Template();
- virtual Bloom *create(unsigned, unsigned) const;
+ virtual Bloom *create(Resources &, unsigned, unsigned) const;
};
private:
RenderTarget *target[2];
ProgramData common_shdata;
- Program blur_shader;
+ const Program &blur_shader;
ProgramData blur_shdata[2];
- Program combine_shader;
+ const Program &combine_shader;
+ const Mesh &quad;
+ const Sampler &nearest_sampler;
+ const Sampler &linear_sampler;
Texturing combine_texturing;
- RefPtr<Mesh> quad;
- RefPtr<Sampler> nearest_sampler;
- RefPtr<Sampler> linear_sampler;
public:
- Bloom(unsigned, unsigned);
+ Bloom(Resources &, unsigned, unsigned);
~Bloom();
/** Sets the σ value of the gaussian blur. Values much larger than 4.0 are
#include "colorcurve.h"
#include "mesh.h"
#include "renderer.h"
+#include "resources.h"
#include "shader.h"
#include "texture2d.h"
namespace Msp {
namespace GL {
-ColorCurve::ColorCurve():
- shprog("colorcurve.glsl"),
- quad(get_fullscreen_quad()),
- linear_sampler(get_linear_sampler()),
- nearest_sampler(get_nearest_sampler())
+ColorCurve::ColorCurve(Resources &resources):
+ shprog(resources.get<Program>("_colorcurve.glsl")),
+ quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
+ linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
+ nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
{
shdata.uniform("source", 0);
shdata.uniform("curve", 1);
curve.storage(LUMINANCE8, 256, 1);
- texturing.attach(1, curve, linear_sampler.get());
+ texturing.attach(1, curve, &linear_sampler);
set_exposure_adjust(0.0f);
set_brightness_response(0.4f);
void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
{
- texturing.attach(0, color_buf, nearest_sampler.get());
+ texturing.attach(0, color_buf, &nearest_sampler);
Renderer::Push push(renderer);
renderer.set_shader_program(&shprog, &shdata);
renderer.set_texturing(&texturing);
- quad->draw(renderer);
+ quad.draw(renderer);
}
srgb(false)
{ }
-ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
+ColorCurve *ColorCurve::Template::create(Resources &res, unsigned, unsigned) const
{
- RefPtr<ColorCurve> colorcurve = new ColorCurve;
+ RefPtr<ColorCurve> colorcurve = new ColorCurve(res);
colorcurve->set_exposure_adjust(exposure_adjust);
colorcurve->set_brightness_response(brightness_response);
if(srgb)
Template();
- virtual ColorCurve *create(unsigned, unsigned) const;
+ virtual ColorCurve *create(Resources &, unsigned, unsigned) const;
};
private:
- Program shprog;
+ const Program &shprog;
ProgramData shdata;
Texture1D curve;
Texturing texturing;
- RefPtr<Mesh> quad;
- RefPtr<Sampler> linear_sampler;
- RefPtr<Sampler> nearest_sampler;
+ const Mesh &quad;
+ const Sampler &linear_sampler;
+ const Sampler &nearest_sampler;
public:
- ColorCurve();
+ ColorCurve(Resources &);
/** Set exposure adjustment in EV units. Positive values brighten the
image, negative values darken it. Zero is neutral. */
namespace Msp {
namespace GL {
-WeakPtr<Sampler> Effect::linear_sampler;
-
Effect::Effect(Renderable &r):
renderable(r)
{
enabled_passes.erase(tag);
}
-RefPtr<Sampler> Effect::get_linear_sampler()
-{
- RefPtr<Sampler> sampler = linear_sampler;
- if(!sampler)
- {
- sampler = new Sampler;
- sampler->set_filter(LINEAR);
- sampler->set_wrap(CLAMP_TO_EDGE);
- linear_sampler = sampler;
- }
- return sampler;
-}
-
} // namespace GL
} // namespace Msp
Renderable &renderable;
std::set<Tag> enabled_passes;
-private:
- static WeakPtr<Sampler> linear_sampler;
-
protected:
Effect(Renderable &);
public:
virtual void setup_frame(Renderer &r) { renderable.setup_frame(r); }
virtual void finish_frame() { renderable.finish_frame(); }
-
-protected:
- static RefPtr<Sampler> get_linear_sampler();
};
} // namespace GL
#include <cmath>
#include "environmentmap.h"
#include "renderer.h"
+#include "resources.h"
#include "texunit.h"
using namespace std;
namespace Msp {
namespace GL {
-EnvironmentMap::EnvironmentMap(unsigned s, Renderable &r, Renderable &e):
+EnvironmentMap::EnvironmentMap(Resources &resources, unsigned s, Renderable &r, Renderable &e):
Effect(r),
size(s),
environment(e),
- sampler(get_linear_sampler()),
+ sampler(resources.get<Sampler>("_linear_clamp.samp")),
rendered(false),
update_interval(1),
update_delay(0)
unsigned unit = renderer.allocate_effect_texunit();
shdata.uniform("environment", static_cast<int>(unit));
- Bind _bind_sampler(*sampler, unit);
+ Bind _bind_sampler(sampler, unit);
Bind _bind_env(env_tex, unit);
const Matrix &camera_matrix = renderer.get_camera()->get_object_matrix();
namespace GL {
class Renderable;
+class Resources;
/**
Creates a cube map texture of the surroundings of the renderable. This texture
TextureCube env_tex;
Renderbuffer depth_buf;
Framebuffer fbo[6];
- RefPtr<Sampler> sampler;
+ const Sampler &sampler;
Camera camera;
mutable ProgramData shdata;
bool rendered;
unsigned update_delay;
public:
- EnvironmentMap(unsigned size, Renderable &rend, Renderable &env);
+ EnvironmentMap(Resources &, unsigned size, Renderable &rend, Renderable &env);
void set_depth_clip(float, float);
void set_update_interval(unsigned);
namespace Msp {
namespace GL {
-WeakPtr<Mesh> PostProcessor::fullscreen_quad;
-WeakPtr<Sampler> PostProcessor::nearest_sampler;
-WeakPtr<Sampler> PostProcessor::linear_sampler;
-
void PostProcessor::render(Renderer &, const Texture2D &color, const Texture2D &depth)
{
render(color, depth);
}
-RefPtr<Mesh> PostProcessor::get_fullscreen_quad()
-{
- RefPtr<Mesh> mesh = fullscreen_quad;
- if(!mesh)
- {
- mesh = new Mesh(VERTEX2);
- MeshBuilder builder(*mesh);
- builder.begin(TRIANGLE_STRIP);
- builder.vertex(-1, 1);
- builder.vertex(-1, -1);
- builder.vertex(1, 1);
- builder.vertex(1, -1);
- builder.end();
- fullscreen_quad = mesh;
- }
- return mesh;
-}
-
-RefPtr<Sampler> PostProcessor::get_nearest_sampler()
-{
- RefPtr<Sampler> sampler = nearest_sampler;
- if(!sampler)
- {
- sampler = new Sampler;
- sampler->set_filter(NEAREST);
- sampler->set_wrap(CLAMP_TO_EDGE);
- nearest_sampler = sampler;
- }
- return sampler;
-}
-
-RefPtr<Sampler> PostProcessor::get_linear_sampler()
-{
- RefPtr<Sampler> sampler = linear_sampler;
- if(!sampler)
- {
- sampler = new Sampler;
- sampler->set_filter(LINEAR);
- sampler->set_wrap(CLAMP_TO_EDGE);
- linear_sampler = sampler;
- }
- return sampler;
-}
-
PostProcessor::Template::Template():
size_divisor(1)
class Mesh;
class Renderer;
+class Resources;
class Sampler;
class Shader;
class Texture2D;
Template();
virtual ~Template() { }
- virtual PostProcessor *create(unsigned, unsigned) const = 0;
+ virtual PostProcessor *create(Resources &, unsigned, unsigned) const = 0;
};
-private:
- static WeakPtr<Mesh> fullscreen_quad;
- static WeakPtr<Sampler> nearest_sampler;
- static WeakPtr<Sampler> linear_sampler;
-
protected:
PostProcessor() { }
public:
virtual void render(const Texture2D &, const Texture2D &) { }
virtual void render(Renderer &, const Texture2D &, const Texture2D &);
-
-protected:
- /** Returns a mesh consisting of a single quad, covering the entire screen.
- The vertices are in normalized device coordinates. */
- static RefPtr<Mesh> get_fullscreen_quad();
-
- static RefPtr<Sampler> get_nearest_sampler();
- static RefPtr<Sampler> get_linear_sampler();
};
} // namespace GL
#include "camera.h"
#include "light.h"
#include "renderer.h"
+#include "resources.h"
#include "scene.h"
#include "shadowmap.h"
#include "tests.h"
namespace Msp {
namespace GL {
-WeakPtr<Sampler> ShadowMap::shadow_sampler;
-
-ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l):
+ShadowMap::ShadowMap(Resources &resources, unsigned s, Renderable &r, const Light &l):
Effect(r),
size(s),
light(l),
+ sampler(resources.get<Sampler>("_linear_clamp_shadow.samp")),
radius(1),
depth_bias(4),
rendered(false)
{
- sampler = shadow_sampler;
- if(!sampler)
- {
- sampler = new Sampler;
- sampler->set_filter(LINEAR);
- sampler->set_compare(LEQUAL);
- sampler->set_wrap(CLAMP_TO_EDGE);
- shadow_sampler = sampler;
- }
depth_buf.storage(DEPTH_COMPONENT32F, size, size, 1);
fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
fbo.require_complete();
int iunit = unit;
shdata.uniform("shadow_map", iunit);
- Bind _bind_sampler(*sampler, unit);
+ Bind _bind_sampler(sampler, unit);
Bind _bind_depth(depth_buf, unit);
if(const Camera *camera = renderer.get_camera())
namespace GL {
class Light;
+class Resources;
class Scene;
/**
Framebuffer fbo;
Matrix shadow_matrix;
Texture2D depth_buf;
- RefPtr<Sampler> sampler;
+ const Sampler &sampler;
Vector3 target;
float radius;
float depth_bias;
mutable ProgramData shdata;
bool rendered;
- static WeakPtr<Sampler> shadow_sampler;
-
public:
- ShadowMap(unsigned, Renderable &, const Light &);
+ ShadowMap(Resources &, unsigned, Renderable &, const Light &);
/** Sets the ShadowMap target point and radius. The transformation matrix is
computed so that a sphere with the specified parameters will be completely
#include "camera.h"
#include "occludedscene.h"
#include "renderer.h"
+#include "resources.h"
#include "sphere.h"
using namespace std;
namespace Msp {
namespace GL {
-OccludedScene::OccludedScene():
- bounding_mesh((VERTEX3, NORMAL3)),
- bounding_shader("occluder.glsl"),
+OccludedScene::OccludedScene(Resources &resources):
+ bounding_mesh(resources.get<Mesh>("_occluder.mesh")),
+ bounding_shader(resources.get<Program>("_occluder.glsl")),
occluder_min_size(0.25f),
cache_dirty(false)
{
static Require req(ARB_occlusion_query);
static Require req2(ARB_occlusion_query2);
-
- /* Use a slightly larger radius to ensure that all parts of the renderable
- fit inside the icosahedron */
- IcoSphereBuilder(1.26f, 1).build(bounding_mesh);
- bounding_mesh.set_winding(&WindingTest::counterclockwise());
}
OccludedScene::~OccludedScene()
typedef std::set<Renderable *> RenderableSet;
typedef std::vector<OccludedRenderable> OccludedArray;
- Mesh bounding_mesh;
- Program bounding_shader;
+ const Mesh &bounding_mesh;
+ const Program &bounding_shader;
RenderableSet renderables;
float occluder_min_size;
mutable OccludedArray occluded_cache;
mutable bool cache_dirty;
public:
- OccludedScene();
+ OccludedScene(Resources &);
~OccludedScene();
virtual void add(Renderable &);
namespace GL {
void init_shaderlib(DataFile::BuiltinSource &);
+void init_builtin_data(DataFile::BuiltinSource &);
Resources::Resources():
default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
if(!init_done)
{
+ init_builtin_data(builtins);
init_shaderlib(builtins);
init_done = true;
}