libcrbn/graphics/grcontext.hpp

00001 
00002 #ifndef __graphics_context_hpp__
00003 #define __graphics_context_hpp__
00004 
00005 #include <crbn/graphics/grinterface.hpp>
00006 #include <crbn/graphics/grcinterface.hpp>
00007 
00008 #include "../geometry/gcontext.hpp"
00009 #include "../matter/mcontext.hpp"
00010 #include "../objectset/oscontext.hpp"
00011 #include "../shader/shcontext.hpp"
00012 
00013 #include <crbn/basic/basic.h>
00014 #include <crbn/basic/vec3.hpp>
00015 #include <crbn/basic/mat4.hpp>
00016 #include <crbn/basic/bbox.hpp>
00017 
00018 typedef struct graphics_entry_t
00019 {
00020   char* name;
00021   bool replicant;
00022   uint32 geometry_id;
00023 
00024   int32 shader_id;
00025   int32 matter_id;
00026 
00027   bool matrix_id;
00028   mat4 matrix;
00029   mat4 invers;
00030   bbox aabb;
00031   float radiance;
00032   vec3 color;
00033 };
00034 
00035 class GraphicsContext : public GraphicsInterface, public GraphicsCacheInterface
00036 {
00037 public:
00038   GraphicsContext();
00039 
00040   virtual ~GraphicsContext();
00041 
00042   void clear();
00043 
00044   bool initialize();
00045   bool finalize();
00046 
00047   void set_light_sampling( paramlist& pl );
00048 
00049   /* The GraphicsInterface inherit.
00050    */
00051   bool search_intersection( ray& r, graphics_data_t& gdata );
00052   void illuminate( ray& r, intersection& inter, vec3& light_value );
00053 
00054   /* The GraphicsCacheInterface inherit.
00055    */
00056   bool intersect( uint32 graphics_id, ray& r, float& distance, packed& data );
00057   void compute_intersection( uint32 graphics_id, ray& r, intersection& inter, packed& data );
00058   void sample_surface( uint32 graphics_id, uint32 number, vec3* vtab, vec3* ntab );
00059 
00060   /* A lots of setter for contexts which GraphicsContext depends on.
00061    */
00062   void set_gcontext( GeometryContext* gcontext ) { _gcontext = gcontext; }
00063   void set_mcontext( MatterContext* mcontext ) { _mcontext = mcontext; }
00064   void set_oscontext( ObjectSetContext* oscontext ) { _oscontext = oscontext; }
00065   void set_shcontext( ShaderContext* shcontext ) { _shcontext = shcontext; }
00066 
00068   //
00069   // About geometries.
00070   //
00072 
00073   void geometry_add( uint32 geometry_id, paramlist& pl, bool replicant = false );
00074   uint32 geometry_duplicate( const char* name );
00075 
00077   //
00078   // About tranformations.
00079   //
00081 
00082   // replaces current transformation and invers matrix with identity.
00083   void matrix_id();
00084 
00085   // replaces current transformation and invers matrix with new ones.
00086   void matrix_load( mat4& matrix, mat4& invers );
00087 
00088   // multiplies current transformation and invers matrix with news.
00089   void matrix_mul( mat4& matrix, mat4& invers );
00090 
00092   //
00093   // About tranformations.
00094   //
00096 
00097   // sets the current texture shader ID.
00098   void set_shader_id( uint32 id );
00099 
00100   // set the current matter ID.
00101   void set_matter_id( int32 id );
00102 
00103   // sets a user defined bbox for next object declaration with :
00104   // 'a' and 'b' the 2 opposite corner of the bbox.
00105   void set_bbox( vec3& a, vec3& b );
00106 
00107   // enables/disables the emission of light from the next objects.
00108   void set_radiance( float radiance );
00109 
00110   // set color (only rgb colors are supported atm)
00111   void set_color( float r, float g, float b );
00112 
00113 private:
00114   graphics_entry_t* search_name( const char* name );
00115 
00116   int _ls_temp_min, _ls_temp_max, _ls_temp_step;
00117   int _ls_min, _ls_max, _ls_step;
00118   vec3* _vtab, *_ntab;
00119 
00120   // some list
00121   std::vector<graphics_entry_t> _list;
00122   std::vector<uint32> _light_list;
00123 
00124   // global info
00125   bbox _global_bbox;
00126 
00127   // graphics's informations
00128   int32 _current_shader_id;
00129   int32 _current_matter_id;
00130   float _current_radiance;
00131   vec3 _current_color;
00132 
00133   // transformations
00134   mat4 _current_matrix, _current_invers;
00135   bool _current_matrix_id;
00136 
00137   // bounding box
00138   bool _current_bbox_set;
00139   vec3 _current_bbox_a, _current_bbox_b;
00140 
00141   // contexts
00142   GeometryContext* _gcontext;
00143   MatterContext* _mcontext;
00144   ObjectSetContext* _oscontext;
00145   ObjectSet* _objectset;
00146   ShaderContext* _shcontext;
00147 };
00148 
00149 #endif // __graphics_context_hpp__

Generated on Tue Nov 14 15:40:08 2006 for libcrbn by  doxygen 1.5.0