Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/ribgsg/ribGraphicsStateGuardian.h

Go to the documentation of this file.
00001 // Filename: ribGraphicsStateGuardian.h
00002 // Created by:  drose (15Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef RIBGRAPHICSSTATEGUARDIAN_H
00020 #define RIBGRAPHICSSTATEGUARDIAN_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include <graphicsStateGuardian.h>
00025 #include <filename.h>
00026 
00027 class Geom;
00028 class Texture;
00029 class Light;
00030 class Material;
00031 class DisplayRegion;
00032 class RenderBuffer;
00033 class PixelBuffer;
00034 class Fog;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : RIBGraphicsStateGuardian
00038 // Description : A GraphicsStateGuardian specialized for creating RIB
00039 //               files, suitable for shipping off to a
00040 //               Renderman-friendly non-real-time renderer.
00041 ////////////////////////////////////////////////////////////////////
00042 class RIBGraphicsStateGuardian : public GraphicsStateGuardian {
00043 public:
00044   RIBGraphicsStateGuardian(GraphicsWindow *win);
00045 
00046   virtual void reset();
00047   void reset_file(ostream &out);
00048   void reset_frame();
00049 
00050   virtual void clear(const RenderBuffer &buffer);
00051   virtual void clear(const RenderBuffer &buffer, const DisplayRegion *region);
00052 
00053   virtual void prepare_display_region();
00054 
00055   virtual void render_frame(const AllAttributesWrapper &initial_state);
00056   virtual void render_scene(Node *root, ProjectionNode *projnode,
00057                             const AllAttributesWrapper &initial_state);
00058   virtual void render_subgraph(RenderTraverser *traverser,
00059                                Node *subgraph, ProjectionNode *projnode,
00060                                const AllAttributesWrapper &initial_state,
00061                                const AllTransitionsWrapper &net_trans);
00062   virtual void render_subgraph(RenderTraverser *traverser,
00063                                Node *subgraph,
00064                                const AllAttributesWrapper &initial_state,
00065                                const AllTransitionsWrapper &net_trans);
00066 
00067   virtual bool wants_normals(void) const;
00068   virtual bool wants_texcoords(void) const;
00069   virtual bool wants_colors(void) const;
00070 
00071   virtual float compute_distance_to(const LPoint3f &point) const;
00072 
00073   virtual void draw_point(const GeomPoint *geom);
00074   virtual void draw_line(const GeomLine *geom);
00075   virtual void draw_linestrip(const GeomLinestrip *) { }
00076   virtual void draw_sprite(const GeomSprite *geom);
00077   virtual void draw_polygon(const GeomPolygon *geom);
00078   virtual void draw_quad(const GeomQuad *geom);
00079   virtual void draw_tri(const GeomTri *geom);
00080   virtual void draw_tristrip(const GeomTristrip *geom);
00081   virtual void draw_trifan(const GeomTrifan *geom);
00082   virtual void draw_sphere(const GeomSphere *geom);
00083 
00084   virtual TextureContext *prepare_texture(Texture *tex);
00085   virtual void apply_texture(TextureContext *tc);
00086   virtual void release_texture(TextureContext *tc);
00087 
00088   virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr);
00089   virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr,
00090                             const RenderBuffer &rb);
00091   virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr);
00092   virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr,
00093                             const RenderBuffer &rb);
00094 
00095   virtual void texture_to_pixel_buffer(TextureContext *, PixelBuffer *) { }
00096   virtual void texture_to_pixel_buffer(TextureContext *, PixelBuffer *,
00097                                 const DisplayRegion *) { }
00098 
00099   virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
00100   virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
00101                                  const RenderBuffer &rb);
00102   virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
00103                                  const NodeAttributes& na=NodeAttributes());
00104   virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
00105                                  const RenderBuffer &rb,
00106                                  const NodeAttributes& na=NodeAttributes());
00107 
00108   virtual void apply_material(Material*) { }
00109   virtual void apply_fog(Fog*) { }
00110 
00111   virtual void apply_light(PointLight*) { }
00112   virtual void apply_light(DirectionalLight*) { }
00113   virtual void apply_light(Spotlight*) { }
00114   virtual void apply_light(AmbientLight*) { }
00115 
00116   virtual void issue_transform(const TransformAttribute *attrib);
00117   virtual void issue_color(const ColorAttribute *attrib);
00118   virtual void issue_texture(const TextureAttribute *attrib);
00119   virtual void issue_light(const LightAttribute *attrib);
00120 
00121   // Normally, these functions are called through the RIBGraphicsWindow.
00122   void set_texture_directory(const string &directory);
00123   string get_texture_directory() const;
00124   void set_texture_extension(const string &extension);
00125   string get_texture_extension() const;
00126 
00127 protected:
00128   virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
00129                                                  CPT(DisplayRegion) dr);
00130   virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
00131 
00132   void set_color(const RGBColorf &color);
00133 
00134   void get_rib_stuff(Node *root, const AllAttributesWrapper &initial_state);
00135   void define_texture(const Texture *tex);
00136   void define_light(const Light *light);
00137   void write_light_color(const Colorf &color) const;
00138   void write_light_from(const Node *light) const;
00139   void write_light_to(const Node *light) const;
00140 
00141   ostream &new_line(int extra_indent = 0) const;
00142   void reset_transform(const LMatrix4f &mat) const;
00143   void concat_transform(const LMatrix4f &mat) const;
00144 
00145   void draw_simple_poly(const Geom *geom);
00146   void write_polygon(int num_verts);
00147 
00148   static void get_color_and_intensity(const RGBColorf &input,
00149                                       RGBColorf &output,
00150                                       float &intensity);
00151 
00152   RGBColorf _current_color;
00153 
00154   string _texture_directory;
00155   string _texture_extension;
00156   ostream *_output;
00157   int _indent_level;
00158   typedef pmap<const Texture *, Filename> TextureNames;
00159   TextureNames _texture_names;
00160   typedef pmap<const Light *, int> LightIDs;
00161   LightIDs _light_ids;
00162   typedef pvector<bool> EnabledLights;
00163   EnabledLights _enabled_lights;
00164 
00165 
00166 public:
00167   static GraphicsStateGuardian *
00168   make_RIBGraphicsStateGuardian(const FactoryParams &params);
00169 
00170   virtual TypeHandle get_type(void) const;
00171   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00172   static TypeHandle get_class_type(void);
00173   static void init_type(void);
00174 
00175 private:
00176   static TypeHandle _type_handle;
00177 
00178   friend class RibStuffTraverser;
00179 };
00180 
00181 #endif
00182 

Generated on Fri May 2 00:43:56 2003 for Panda by doxygen1.3