spec_values["use_reflectivity_map"] = (reflectivity.texture!=0);
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
-{
- attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map");
- attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map");
- attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
- attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
- attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map");
- attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map");
-}
-#pragma GCC diagnostic pop
-
const Texture *BasicMaterial::get_texture(Tag tag) const
{
if(tag==texture_tags[0])
virtual void fill_program_info(std::string &, std::map<std::string, int> &) const;
public:
- DEPRECATED virtual void attach_textures_to(Texturing &, ProgramData &) const;
-
virtual const Tag *get_texture_tags() const { return texture_tags; }
virtual const Texture *get_texture(Tag) const;
#include "gl.h"
#include "pbrmaterial.h"
#include "resources.h"
-#include "texturing.h"
#include "uniform.h"
#include "unlitmaterial.h"
return shprog;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Material::attach_texture_to(const Texture *tex, Texturing &texturing, ProgramData &tex_shdata, const string &name) const
-{
- if(!tex)
- return;
-
- int unit = -1;
-
- if(const Uniform *uni = tex_shdata.find_uniform(name))
- if(const Uniform1i *uni_int = dynamic_cast<const Uniform1i *>(uni))
- unit = uni_int->get();
-
- if(unit<0)
- unit = texturing.find_free_unit(name);
- if(unit<0)
- throw runtime_error("no free texunit");
-
- texturing.attach(unit, *tex, sampler);
- tex_shdata.uniform(name, unit);
-}
-#pragma GCC diagnostic pop
-
void Material::set_debug_name(const string &name)
{
#ifdef DEBUG
namespace Msp {
namespace GL {
-class Texturing;
-
class Material
{
private:
/** Returns the uniforms for the material. */
const ProgramData &get_shader_data() const { return shdata; }
-protected:
- DEPRECATED void attach_texture_to(const Texture *, Texturing &, ProgramData &, const std::string &) const;
-public:
- DEPRECATED virtual void attach_textures_to(Texturing &, ProgramData &) const = 0;
-
virtual const Tag *get_texture_tags() const = 0;
virtual const Texture *get_texture(Tag) const = 0;
const Sampler *get_sampler() const { return sampler; }
spec_values["use_emission_map"] = (emission.texture!=0);
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
-{
- attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
- attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
- attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
- attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
- attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
- attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
-}
-#pragma GCC diagnostic pop
-
const Texture *PbrMaterial::get_texture(Tag tag) const
{
if(tag==texture_tags[0])
virtual void fill_program_info(std::string &, std::map<std::string, int> &) const;
public:
- DEPRECATED virtual void attach_textures_to(Texturing &, ProgramData &) const;
-
virtual const Tag *get_texture_tags() const { return texture_tags; }
virtual const Texture *get_texture(Tag) const;
#include "renderer.h"
#include "texture.h"
#include "texture2d.h"
-#include "texturing.h"
#include "uniform.h"
using namespace std;
class Renderer;
class Sampler;
class Texture;
-class Texturing;
/**
Encapsulates the data that determines the appearance of a rendered surface.
void set_texture(Tag, const Texture *, const Sampler * = 0);
Tag get_texture_tag(const std::string &) const;
DEPRECATED void set_texture(unsigned, const Texture *, const Sampler * = 0);
- DEPRECATED const Texturing *get_texturing() const { return 0; }
DEPRECATED int get_texture_index(const std::string &) const;
void set_back_faces(bool);
bool get_back_faces() const { return back_faces; }
spec_values["use_vertex_color"] = vertex_color;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
-{
- attach_texture_to(texture, texturing, tex_shdata, "color_tex");
-}
-#pragma GCC diagnostic pop
-
const Texture *UnlitMaterial::get_texture(Tag tag) const
{
if(tag==texture_tags[0])
virtual void fill_program_info(std::string &, std::map<std::string, int> &) const;
public:
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- DEPRECATED virtual void attach_textures_to(Texturing &, ProgramData &) const;
-#pragma GCC diagnostic pop
-
virtual const Tag *get_texture_tags() const { return texture_tags; }
virtual const Texture *get_texture(Tag) const;
+++ /dev/null
-#include "object.h"
-#include "objectinstance.h"
-#include "instancescene.h"
-#include "renderer.h"
-
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
-namespace Msp {
-namespace GL {
-
-void InstanceScene::add(Renderable &r)
-{
- renderables[r.get_instance_key()].insert(&r);
-}
-
-void InstanceScene::remove(Renderable &r)
-{
- InstanceMap::iterator i = renderables.find(r.get_instance_key());
- if(i!=renderables.end())
- {
- i->second.erase(&r);
- if(i->second.empty())
- renderables.erase(i);
- }
-}
-
-void InstanceScene::setup_frame(Renderer &renderer)
-{
- for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- (*j)->setup_frame(renderer);
-}
-
-void InstanceScene::finish_frame()
-{
- for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- (*j)->finish_frame();
-}
-
-void InstanceScene::render(Renderer &renderer, Tag tag) const
-{
- if(setup_frustum(renderer))
- {
- for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- if(!frustum_cull(**j))
- renderer.render(**j, tag);
- }
- else
- {
- for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- renderer.render(**j, tag);
- }
-}
-
-} // namespace GL
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GL_INSTANCESCENE_H_
-#define MSP_GL_INSTANCESCENE_H_
-
-#include <map>
-#include <set>
-#include <msp/core/attributes.h>
-#include <msp/core/inttypes.h>
-#include "scene.h"
-
-namespace Msp {
-namespace GL {
-
-/**
-A Scene optimized for rendering instanced Renderables, such as ObjectInstances.
-All Renderables with the same instance key are rendered consecutively; within
-the same key rendering order is unspecified.
-*/
-class DEPRECATED InstanceScene: public Scene
-{
-private:
- typedef std::set<Renderable *> RenderableSet;
- typedef std::map<IntPtr, RenderableSet> InstanceMap;
-
- InstanceMap renderables;
-
-public:
- virtual void add(Renderable &);
- virtual void remove(Renderable &);
-
- virtual void setup_frame(Renderer &);
- virtual void finish_frame();
-
- virtual void render(Renderer &, Tag tag = Tag()) const;
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif
#include "renderer.h"
#include "resourcemanager.h"
#include "technique.h"
-#include "texturing.h"
using namespace std;
ObjectInstance(const Object &);
const Object &get_object() const { return object; }
- DEPRECATED virtual IntPtr get_instance_key() const { return reinterpret_cast<IntPtr>(&object); }
virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return object.get_bounding_sphere(); }
#include <string>
#include <msp/core/attributes.h>
-#include <msp/core/inttypes.h>
#include <msp/geometry/boundingsphere.h>
#include "tag.h"
public:
virtual ~Renderable() { }
- /** Returns a key used for grouping Renderables in an InstanceScene. The
- returned value is treated as opaque. */
- DEPRECATED virtual IntPtr get_instance_key() const { return 0; }
-
/** Returns the model matrix of the Renderable. Null is returned if no such
matrix exists. The matrix should be in world space for some effects to work
correctly. */
#include "renderer.h"
#include "sampler.h"
#include "texture.h"
-#include "texturing.h"
#include "texunit.h"
#include "vertexarray.h"
#include "vertexsetup.h"
namespace Msp {
namespace GL {
-Renderer::Renderer():
- default_camera(0)
-{
- init();
-}
-
-Renderer::Renderer(const Camera *c):
- default_camera(c)
-{
- init();
-
- if(c)
- set_camera(*c);
-}
-
-void Renderer::init()
+Renderer::Renderer()
{
state_stack.reserve(16);
state_stack.push_back(State());
}
void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
-{
- set_texture(tag, -1, tex, samp);
-}
-
-void Renderer::set_texture(Tag tag, int unit, const Texture *tex, const Sampler *samp)
{
if(texture_stack.size()>state->texture_count)
{
BoundTexture &bt = texture_stack[state->texture_count];
- if((!tag.id || bt.tag==tag) && (unit<0 || bt.unit==unit) && bt.texture==tex && bt.sampler==samp)
+ if(bt.tag==tag && bt.texture==tex && bt.sampler==samp)
{
++state->texture_count;
return;
}
for(vector<BoundTexture>::iterator i=texture_stack.end(); i!=texture_stack.begin(); )
- if((--i)->tag==tag && i->unit==unit)
+ if((--i)->tag==tag)
{
i->replaced = texture_stack.size();
break;
texture_stack.push_back(BoundTexture());
BoundTexture &bound_tex = texture_stack.back();
bound_tex.tag = tag;
- bound_tex.unit = unit;
bound_tex.texture = tex;
bound_tex.sampler = samp;
state->texture_count = texture_stack.size();
}
-void Renderer::set_texture(const Texture *t, const Sampler *s)
-{
- set_texture(Tag(), 0, t, s);
-}
-
void Renderer::flush_textures()
{
for(unsigned i=0; i<texture_stack.size(); ++i)
texture_stack.erase(texture_stack.begin()+state->texture_count, texture_stack.end());
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Renderer::set_texturing(const Texturing *t)
-{
- if(t)
- {
- unsigned n_units = TexUnit::get_n_units();
- for(unsigned i=0; i<n_units; ++i)
- if(const Texture *tex = t->get_attached_texture(i))
- set_texture(Tag(), i, tex, t->get_attached_sampler(i));
- }
-}
-#pragma GCC diagnostic pop
-
-unsigned Renderer::allocate_effect_texunit()
-{
- return --state->lowest_effect_texunit;
-}
-
void Renderer::set_material(const Material *m)
{
if(m)
throw invalid_operation("Renderer::end");
*state = State();
- if(default_camera)
- set_camera(*default_camera);
shdata_stack.clear();
excluded.clear();
for(vector<BoundTexture>::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i)
{
- int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit);
+ int unit = state->shprog->get_uniform_binding(i->tag);
if(unit>=0)
{
if(i->texture)
class Renderable;
class Sampler;
class Texture;
-class Texturing;
class VertexSetup;
class WindingTest;
SHADER_DATA = 16
};
- const Camera *default_camera;
unsigned char changed;
std::vector<State> state_stack;
State *state;
public:
Renderer();
- DEPRECATED Renderer(const Camera *);
-private:
- void init();
-public:
~Renderer();
/** Sets the camera to render from. The model matrix is reset to identity. */
void set_texture(Tag, const Texture *, const Sampler * = 0);
private:
- void set_texture(Tag, int, const Texture *, const Sampler *);
void flush_textures();
public:
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- DEPRECATED void set_texture(const Texture *, const Sampler * = 0);
- DEPRECATED void set_texturing(const Texturing *);
- DEPRECATED unsigned allocate_effect_texunit();
-#pragma GCC diagnostic pop
DEPRECATED void set_material(const Material *);
DEPRECATED void set_lighting(const Lighting *);
+++ /dev/null
-#include <msp/core/hash.h>
-#include "texture.h"
-#include "texturing.h"
-#include "texunit.h"
-
-using namespace std;
-
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
-namespace Msp {
-namespace GL {
-
-Texturing::~Texturing()
-{
- if(current()==this)
- unbind();
-}
-
-int Texturing::find_free_unit(const string &name_hint) const
-{
- unsigned max_unit = TexUnit::get_n_units();
- // Leave some space for effect textures
- max_unit -= min(max_unit/4, 8U);
- unsigned initial_unit = (name_hint.empty() ? 0 : hash32(name_hint)%max_unit);
- unsigned unit = initial_unit;
- while(get_attached_texture(unit) || get_attached_sampler(unit))
- {
- unit = (unit+1)%max_unit;
- if(unit==initial_unit)
- return -1;
- }
-
- return unit;
-}
-
-void Texturing::attach(unsigned attch, const Texture &tex, const Sampler *samp)
-{
- set_attachment(attch, &tex, samp);
-}
-
-void Texturing::attach(unsigned attch, const Sampler &samp)
-{
- set_attachment(attch, 0, &samp);
-}
-
-void Texturing::detach(unsigned attch)
-{
- set_attachment(attch, 0, 0);
-}
-
-void Texturing::set_attachment(unsigned unit, const Texture *tex, const Sampler *samp)
-{
- if(unit>=TexUnit::get_n_units())
- throw out_of_range("Texturing::set_attachment");
-
- if(tex || samp)
- {
- vector<Attachment>::iterator i;
- for(i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- {
- i->texture = tex;
- i->sampler = samp;
- if(current()==this)
- bind_attachment(*i);
- return;
- }
-
- attachments.insert(i, Attachment(unit, tex, samp));
- if(current()==this)
- tex->bind_to(unit);
- }
- else
- {
- for(vector<Attachment>::iterator i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- {
- attachments.erase(i);
- if(current()==this)
- unbind_attachment(unit);
- return;
- }
- }
-}
-
-const Texture *Texturing::get_attached_texture(unsigned unit) const
-{
- for(vector<Attachment>::const_iterator i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- return i->texture;
- return 0;
-}
-
-const Sampler *Texturing::get_attached_sampler(unsigned unit) const
-{
- for(vector<Attachment>::const_iterator i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- return i->sampler;
- return 0;
-}
-
-void Texturing::bind() const
-{
- const Texturing *old = current();
- if(set_current(this))
- {
- if(old)
- {
- vector<Attachment>::const_iterator i = attachments.begin();
- vector<Attachment>::const_iterator j = old->attachments.begin();
- while(i!=attachments.end() || j!=old->attachments.end())
- {
- if(i!=attachments.end() && (j==old->attachments.end() || i->unit<=j->unit))
- {
- bind_attachment(*i);
- if(j!=old->attachments.end() && j->unit==i->unit)
- ++j;
- ++i;
- }
- else
- {
- unbind_attachment(j->unit);
- ++j;
- }
- }
- }
- else
- {
- for(vector<Attachment>::const_iterator i=attachments.begin(); i!=attachments.end(); ++i)
- bind_attachment(*i);
- }
- }
-}
-
-void Texturing::bind_attachment(const Attachment &attch) const
-{
- if(attch.sampler)
- attch.sampler->bind_to(attch.unit);
- else
- Sampler::unbind_from(attch.unit);
- if(attch.texture)
- attch.texture->bind_to(attch.unit);
- else
- Texture::unbind_from(attch.unit);
-}
-
-void Texturing::unbind()
-{
- const Texturing *old = current();
- if(set_current(0))
- {
- for(vector<Attachment>::const_iterator i=old->attachments.begin(); i!=old->attachments.end(); ++i)
- unbind_attachment(i->unit);
- }
-}
-
-void Texturing::unbind_attachment(unsigned unit)
-{
- Texture::unbind_from(unit);
- Sampler::unbind_from(unit);
-}
-
-
-Texturing::Attachment::Attachment(unsigned u, const Texture *t, const Sampler *s):
- unit(u),
- texture(t),
- sampler(s)
-{ }
-
-} // namespace GL
-} // namespace Msp;
+++ /dev/null
-#ifndef MSP_GL_TEXTURING_H_
-#define MSP_GL_TEXTURING_H_
-
-#include <vector>
-#include "bindable.h"
-
-namespace Msp {
-namespace GL {
-
-class Texture;
-
-class DEPRECATED Texturing: public Bindable<Texturing>
-{
-private:
- struct Attachment
- {
- unsigned unit;
- const Texture *texture;
- const Sampler *sampler;
-
- Attachment(unsigned, const Texture *, const Sampler *);
- };
-
- std::vector<Attachment> attachments;
-
-public:
- ~Texturing();
-
- int find_free_unit(const std::string & = std::string()) const;
- void attach(unsigned, const Texture &, const Sampler * = 0);
- void attach(unsigned, const Sampler &);
- void detach(unsigned);
-private:
- void set_attachment(unsigned, const Texture *, const Sampler *);
-public:
- const Texture *get_attached_texture(unsigned) const;
- const Sampler *get_attached_sampler(unsigned) const;
-
- void bind() const;
-
- static void unbind();
-
-private:
- void bind_attachment(const Attachment &) const;
- static void unbind_attachment(unsigned);
-};
-
-} // namespace GL
-} // namespace Msp;
-
-#endif