Panda3D
 All Classes Functions Variables Enumerations
graphicsStateGuardianBase.h
00001 // Filename: graphicsStateGuardianBase.h
00002 // Created by:  drose (06Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef GRAPHICSSTATEGUARDIANBASE_H
00016 #define GRAPHICSSTATEGUARDIANBASE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "typedWritableReferenceCount.h"
00021 #include "luse.h"
00022 #include "lightMutex.h"
00023 
00024 // A handful of forward references.
00025 
00026 class Thread;
00027 class RenderBuffer;
00028 class GraphicsWindow;
00029 class NodePath;
00030 class GraphicsOutputBase;
00031 
00032 class VertexBufferContext;
00033 class IndexBufferContext;
00034 class OcclusionQueryContext;
00035 class GeomContext;
00036 class GeomNode;
00037 class Geom;
00038 class GeomPipelineReader;
00039 class GeomVertexData;
00040 class GeomVertexDataPipelineReader;
00041 class GeomVertexArrayData;
00042 class GeomPrimitive;
00043 class GeomPrimitivePipelineReader;
00044 class GeomTriangles;
00045 class GeomTristrips;
00046 class GeomTrifans;
00047 class GeomLines;
00048 class GeomLinestrips;
00049 class GeomPoints;
00050 class GeomMunger;
00051 
00052 class SceneSetup;
00053 class PreparedGraphicsObjects;
00054 class GraphicsOutput;
00055 class Texture;
00056 class TextureContext;
00057 class ShaderContext;
00058 class Shader;
00059 class RenderState;
00060 class TransformState;
00061 class Material;
00062 
00063 class ColorScaleAttrib;
00064 class TexMatrixAttrib;
00065 class ColorAttrib;
00066 class TextureAttrib;
00067 class LightAttrib;
00068 class MaterialAttrib;
00069 class RenderModeAttrib;
00070 class AntialiasAttrib;
00071 class RescaleNormalAttrib;
00072 class ColorBlendAttrib;
00073 class ColorWriteAttrib;
00074 class AlphaTestAttrib;
00075 class DepthTestAttrib;
00076 class DepthWriteAttrib;
00077 class TexGenAttrib;
00078 class ShaderAttrib;
00079 class CullFaceAttrib;
00080 class ClipPlaneAttrib;
00081 class ShadeModelAttrib;
00082 class TransparencyAttrib;
00083 class FogAttrib;
00084 class DepthOffsetAttrib;
00085 
00086 class PointLight;
00087 class DirectionalLight;
00088 class Spotlight;
00089 class AmbientLight;
00090 class LightLensNode;
00091 
00092 class DisplayRegion;
00093 class Lens;
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //       Class : GraphicsStateGuardianBase
00097 // Description : This is a base class for the GraphicsStateGuardian
00098 //               class, which is itself a base class for the various
00099 //               GSG's for different platforms.  This class contains
00100 //               all the function prototypes to support the
00101 //               double-dispatch of GSG to geoms, transitions, etc.  It
00102 //               lives in a separate class in its own package so we
00103 //               can avoid circular build dependency problems.
00104 //
00105 //               GraphicsStateGuardians are not actually writable to
00106 //               bam files, of course, but they may be passed as event
00107 //               parameters, so they inherit from
00108 //               TypedWritableReferenceCount instead of
00109 //               TypedReferenceCount for that convenience.
00110 ////////////////////////////////////////////////////////////////////
00111 class EXPCL_PANDA_GSGBASE GraphicsStateGuardianBase : public TypedWritableReferenceCount {
00112 PUBLISHED:
00113   virtual bool get_incomplete_render() const=0;
00114   virtual bool get_effective_incomplete_render() const=0;
00115 
00116   virtual bool prefers_triangle_strips() const=0;
00117   virtual int get_max_vertices_per_array() const=0;
00118   virtual int get_max_vertices_per_primitive() const=0;
00119 
00120   virtual int get_max_texture_dimension() const=0;
00121   virtual bool get_supports_compressed_texture_format(int compression_mode) const=0;
00122 
00123   virtual bool get_supports_multisample() const=0;
00124   virtual int get_supported_geom_rendering() const=0;
00125   virtual bool get_supports_occlusion_query() const=0;
00126   virtual bool get_supports_shadow_filter() const=0;
00127 
00128 public:
00129   // These are some general interface functions; they're defined here
00130   // mainly to make it easy to call these from code in some directory
00131   // that display depends on.
00132   virtual SceneSetup *get_scene() const=0;
00133 
00134   virtual void clear_before_callback()=0;
00135   virtual void clear_state_and_transform()=0;
00136 
00137   virtual void remove_window(GraphicsOutputBase *window)=0;
00138 
00139 #ifndef CPPPARSER
00140   // We hide this from interrogate, so that it will be properly
00141   // exported from the GraphicsStateGuardian class, later.
00142   virtual PreparedGraphicsObjects *get_prepared_objects()=0;
00143 #endif
00144 
00145   virtual TextureContext *prepare_texture(Texture *tex, int view)=0;
00146   virtual bool update_texture(TextureContext *tc, bool force)=0;
00147   virtual void release_texture(TextureContext *tc)=0;
00148   virtual bool extract_texture_data(Texture *tex)=0;
00149 
00150   virtual GeomContext *prepare_geom(Geom *geom)=0;
00151   virtual void release_geom(GeomContext *gc)=0;
00152 
00153   virtual ShaderContext *prepare_shader(Shader *shader)=0;
00154   virtual void release_shader(ShaderContext *sc)=0;
00155   
00156   virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data)=0;
00157   virtual void release_vertex_buffer(VertexBufferContext *vbc)=0;
00158 
00159   virtual IndexBufferContext *prepare_index_buffer(GeomPrimitive *data)=0;
00160   virtual void release_index_buffer(IndexBufferContext *ibc)=0;
00161 
00162   virtual void begin_occlusion_query()=0;
00163   virtual PT(OcclusionQueryContext) end_occlusion_query()=0;
00164 
00165   virtual PT(GeomMunger) get_geom_munger(const RenderState *state,
00166                                          Thread *current_thread)=0;
00167 
00168   virtual void set_state_and_transform(const RenderState *state,
00169                                        const TransformState *transform)=0;
00170 
00171   // This function may only be called during a render traversal; it
00172   // will compute the distance to the indicated point, assumed to be
00173   // in eye coordinates, from the camera plane.  This is a virtual
00174   // function because different GSG's may define the eye coordinate
00175   // space differently.
00176   virtual PN_stdfloat compute_distance_to(const LPoint3 &point) const=0;
00177 
00178   // These are used to implement decals.  If depth_offset_decals()
00179   // returns true, none of the remaining functions will be called,
00180   // since depth offsets can be used to implement decals fully (and
00181   // usually faster).
00182   virtual bool depth_offset_decals()=0;
00183   virtual CPT(RenderState) begin_decal_base_first()=0;
00184   virtual CPT(RenderState) begin_decal_nested()=0;
00185   virtual CPT(RenderState) begin_decal_base_second()=0;
00186   virtual void finish_decal()=0;
00187 
00188   // Defined here are some internal interface functions for the
00189   // GraphicsStateGuardian.  These are here to support
00190   // double-dispatching from Geoms and NodeTransitions, and are
00191   // intended to be invoked only directly by the appropriate Geom and
00192   // NodeTransition types.  They're public only because it would be too
00193   // inconvenient to declare each of those types to be friends of this
00194   // class.
00195 
00196   virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader, 
00197                                      const GeomMunger *munger,
00198                                      const GeomVertexDataPipelineReader *data_reader, 
00199                                      bool force)=0;
00200   virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader, bool force)=0;
00201   virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
00202   virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader, bool force)=0;
00203   virtual bool draw_lines(const GeomPrimitivePipelineReader *reader, bool force)=0;
00204   virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
00205   virtual bool draw_points(const GeomPrimitivePipelineReader *reader, bool force)=0;
00206   virtual void end_draw_primitives()=0;
00207 
00208   virtual bool framebuffer_copy_to_texture
00209   (Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
00210   virtual bool framebuffer_copy_to_ram
00211   (Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
00212   
00213   virtual CoordinateSystem get_internal_coordinate_system() const=0;
00214   virtual const TransformState *get_cs_transform() const=0;
00215 
00216   virtual void bind_light(PointLight *light_obj, const NodePath &light, 
00217                           int light_id) { }
00218   virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
00219                           int light_id) { }
00220   virtual void bind_light(Spotlight *light_obj, const NodePath &light,
00221                           int light_id) { }
00222 
00223   // This function creates a shadow mapping buffer. This is not put in ShaderGenerator
00224   // because that would cause circular dependencies.
00225   virtual PT(Texture) make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host)=0;
00226 
00227 PUBLISHED:
00228   static GraphicsStateGuardianBase *get_default_gsg();
00229   static void set_default_gsg(GraphicsStateGuardianBase *default_gsg);
00230 
00231   static int get_num_gsgs();
00232   static GraphicsStateGuardianBase *get_gsg(int n);
00233   MAKE_SEQ(get_gsgs, get_num_gsgs, get_gsg);
00234 
00235 public:
00236   static void add_gsg(GraphicsStateGuardianBase *gsg);
00237   static void remove_gsg(GraphicsStateGuardianBase *gsg);
00238 
00239 private:
00240   typedef pvector<GraphicsStateGuardianBase *> GSGs;
00241   static GSGs _gsgs;
00242   static GraphicsStateGuardianBase *_default_gsg;
00243   static LightMutex _lock;
00244 
00245 public:
00246   static TypeHandle get_class_type() {
00247     return _type_handle;
00248   }
00249   static void init_type() {
00250     TypedWritableReferenceCount::init_type();
00251     register_type(_type_handle, "GraphicsStateGuardianBase",
00252                   TypedWritableReferenceCount::get_class_type());
00253   }
00254   virtual TypeHandle get_type() const {
00255     return get_class_type();
00256   }
00257   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00258 
00259 private:
00260   static TypeHandle _type_handle;
00261 };
00262 
00263 #endif
 All Classes Functions Variables Enumerations