]> git.tdb.fi Git - libs/gl.git/blobdiff - source/material.h
Explicitly define the number of mipmap levels in textures
[libs/gl.git] / source / material.h
index b2ea995ef66a083d265eccde7feef0e5e9997c15..e1bfec4caa0707419941b88476394955ab651244 100644 (file)
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_GL_MATERIAL_H_
 #define MSP_GL_MATERIAL_H_
 
+#include <msp/datafile/objectloader.h>
+#include "bindable.h"
 #include "color.h"
+#include "programdata.h"
 
 namespace Msp {
 namespace GL {
 
-class Material
+/**
+Stores basic material properties.  This includes color and reflection
+parameters, but does not include texturing.  Materials interact with light
+soucres and ambient lighting to produce the base color of a surface.  Textures
+can be used to add detail.
+
+Material provides a set of uniform variables for use with shaders.  Standard
+shaders generated by ProgramBuilder only use it when legacy mode is disabled.
+
+In legacy mode, materials are applied with several calls to glMaterial.
+*/
+class Material: public BindableWithDefault<Material>
 {
+public:
+       class Loader: public DataFile::CollectionObjectLoader<Material>
+       {
+       private:
+               bool srgb;
+
+       public:
+               Loader(Material &);
+               Loader(Material &, Collection &);
+       private:
+               void init();
+
+               Color make_color(float, float, float, float);
+               void ambient(float, float, float, float);
+               void diffuse(float, float, float, float);
+               void specular(float, float, float, float);
+               void emission(float, float, float, float);
+               void shininess(float);
+               void reflectivity(float);
+       };
+
 private:
+       enum ParameterMask
+       {
+               AMBIENT = 1,
+               DIFFUSE = 2,
+               SPECULAR = 4,
+               EMISSION = 8,
+               SHININESS = 16
+       };
+
        Color ambient;
        Color diffuse;
        Color specular;
        Color emission;
        float shininess;
+       float reflectivity;
+       ProgramData shdata;
 
 public:
        Material();
-       void set_ambient(const Color &a);
-       void set_diffuse(const Color &d);
-       void set_specular(const Color &s);
-       void set_emission(const Color &e);
-       void set_shininess(float s);
-       void apply();
+
+private:
+       void update_parameter(int) const;
+
+public:
+       /** Sets the ambient color of the material.  Provided to shaders with the
+       name material.ambient. */
+       void set_ambient(const Color &);
+
+       /** Sets the diffuse (direction-independent) color of the material.
+       Provided to shaders with the name material.diffuse. */
+       void set_diffuse(const Color &);
+
+       /** Sets the specular (direction-dependent) color of the material.  Provided
+       to shaders with the name material.specular. */
+       void set_specular(const Color &);
+       void set_emission(const Color &);
+
+       /** Sets the specular exponent of the material.  Provided to shaders with
+       the name material.shininess. */
+       void set_shininess(float);
+
+       /** Sets the reflectivity of the material.  Provided to shaders with the
+       name reflectivity.  Has no effect when shaders are not used. */
+       void set_reflectivity(float);
+
+       const Color &get_ambient() const { return ambient; }
+       const Color &get_diffuse() const { return diffuse; }
+       const Color &get_specular() const { return specular; }
+       const Color &get_emission() const { return emission; }
+       float get_shininess() const { return shininess; }
+       float get_reflectivity() const { return reflectivity; }
+
+       /** Returns the uniforms for the material.  Not needed for shaders that use
+       the legacy built-in uniform gl_FrontMaterial and have no reflections. */
+       const ProgramData &get_shader_data() const { return shdata; }
+
+       void bind() const;
 };
 
 } // namespace GL