Panda3D
graphicsStateGuardianBase.h
1 // Filename: graphicsStateGuardianBase.h
2 // Created by: drose (06Oct99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef GRAPHICSSTATEGUARDIANBASE_H
16 #define GRAPHICSSTATEGUARDIANBASE_H
17 
18 #include "pandabase.h"
19 
20 #include "typedWritableReferenceCount.h"
21 #include "nodeCachedReferenceCount.h"
22 #include "luse.h"
23 #include "lightMutex.h"
24 
25 // A handful of forward references.
26 
27 class Thread;
28 class RenderBuffer;
29 class GraphicsWindow;
30 class NodePath;
31 class GraphicsOutputBase;
32 
34 class IndexBufferContext;
35 class GeomContext;
36 class GeomNode;
37 class Geom;
38 class GeomPipelineReader;
39 class GeomVertexData;
42 class GeomPrimitive;
44 class GeomTriangles;
45 class GeomTristrips;
46 class GeomTrifans;
47 class GeomLines;
48 class GeomLinestrips;
49 class GeomPoints;
50 class GeomMunger;
51 
52 class SceneSetup;
54 class GraphicsOutput;
55 class Texture;
56 class TextureContext;
57 class SamplerContext;
58 class SamplerState;
59 class Shader;
60 class ShaderContext;
61 class RenderState;
62 class TransformState;
63 class Material;
64 
65 class ColorScaleAttrib;
66 class TexMatrixAttrib;
67 class ColorAttrib;
68 class TextureAttrib;
69 class LightAttrib;
70 class MaterialAttrib;
71 class RenderModeAttrib;
72 class AntialiasAttrib;
74 class ColorBlendAttrib;
75 class ColorWriteAttrib;
76 class AlphaTestAttrib;
77 class DepthTestAttrib;
78 class DepthWriteAttrib;
79 class TexGenAttrib;
80 class ShaderAttrib;
81 class CullFaceAttrib;
82 class ClipPlaneAttrib;
83 class ShadeModelAttrib;
84 class TransparencyAttrib;
85 class FogAttrib;
86 class DepthOffsetAttrib;
87 
88 class PointLight;
89 class DirectionalLight;
90 class Spotlight;
91 class AmbientLight;
92 class LightLensNode;
93 
94 class DisplayRegion;
95 class Lens;
96 
97 ////////////////////////////////////////////////////////////////////
98 // Class : GraphicsStateGuardianBase
99 // Description : This is a base class for the GraphicsStateGuardian
100 // class, which is itself a base class for the various
101 // GSG's for different platforms. This class contains
102 // all the function prototypes to support the
103 // double-dispatch of GSG to geoms, transitions, etc. It
104 // lives in a separate class in its own package so we
105 // can avoid circular build dependency problems.
106 //
107 // GraphicsStateGuardians are not actually writable to
108 // bam files, of course, but they may be passed as event
109 // parameters, so they inherit from
110 // TypedWritableReferenceCount instead of
111 // TypedReferenceCount for that convenience.
112 ////////////////////////////////////////////////////////////////////
113 class EXPCL_PANDA_GSGBASE GraphicsStateGuardianBase : public TypedWritableReferenceCount {
114 PUBLISHED:
115  virtual bool get_incomplete_render() const=0;
116  virtual bool get_effective_incomplete_render() const=0;
117 
118  virtual bool prefers_triangle_strips() const=0;
119  virtual int get_max_vertices_per_array() const=0;
120  virtual int get_max_vertices_per_primitive() const=0;
121 
122  virtual int get_max_texture_dimension() const=0;
123  virtual bool get_supports_compressed_texture_format(int compression_mode) const=0;
124 
125  virtual bool get_supports_multisample() const=0;
126  virtual int get_supported_geom_rendering() const=0;
127  virtual bool get_supports_shadow_filter() const=0;
128 
129  virtual bool get_supports_texture_srgb() const=0;
130 
131 public:
132  // These are some general interface functions; they're defined here
133  // mainly to make it easy to call these from code in some directory
134  // that display depends on.
135  virtual SceneSetup *get_scene() const=0;
136 
137  virtual void clear_before_callback()=0;
138  virtual void clear_state_and_transform()=0;
139 
140  virtual void remove_window(GraphicsOutputBase *window)=0;
141 
142 #ifndef CPPPARSER
143  // We hide this from interrogate, so that it will be properly
144  // exported from the GraphicsStateGuardian class, later.
145  virtual PreparedGraphicsObjects *get_prepared_objects()=0;
146 #endif
147 
148  virtual TextureContext *prepare_texture(Texture *tex, int view)=0;
149  virtual bool update_texture(TextureContext *tc, bool force)=0;
150  virtual void release_texture(TextureContext *tc)=0;
151  virtual bool extract_texture_data(Texture *tex)=0;
152 
153  virtual SamplerContext *prepare_sampler(const SamplerState &sampler)=0;
154  virtual void release_sampler(SamplerContext *sc)=0;
155 
156  virtual GeomContext *prepare_geom(Geom *geom)=0;
157  virtual void release_geom(GeomContext *gc)=0;
158 
159  virtual ShaderContext *prepare_shader(Shader *shader)=0;
160  virtual void release_shader(ShaderContext *sc)=0;
161 
162  virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data)=0;
163  virtual void release_vertex_buffer(VertexBufferContext *vbc)=0;
164 
165  virtual IndexBufferContext *prepare_index_buffer(GeomPrimitive *data)=0;
166  virtual void release_index_buffer(IndexBufferContext *ibc)=0;
167 
168  virtual void dispatch_compute(int size_x, int size_y, int size_z)=0;
169 
170  virtual PT(GeomMunger) get_geom_munger(const RenderState *state,
171  Thread *current_thread)=0;
172 
173  virtual void set_state_and_transform(const RenderState *state,
174  const TransformState *transform)=0;
175 
176  // This function may only be called during a render traversal; it
177  // will compute the distance to the indicated point, assumed to be
178  // in eye coordinates, from the camera plane. This is a virtual
179  // function because different GSG's may define the eye coordinate
180  // space differently.
181  virtual PN_stdfloat compute_distance_to(const LPoint3 &point) const=0;
182 
183  // These are used to implement decals. If depth_offset_decals()
184  // returns true, none of the remaining functions will be called,
185  // since depth offsets can be used to implement decals fully (and
186  // usually faster).
187  virtual bool depth_offset_decals()=0;
188  virtual CPT(RenderState) begin_decal_base_first()=0;
189  virtual CPT(RenderState) begin_decal_nested()=0;
190  virtual CPT(RenderState) begin_decal_base_second()=0;
191  virtual void finish_decal()=0;
192 
193  // Defined here are some internal interface functions for the
194  // GraphicsStateGuardian. These are here to support
195  // double-dispatching from Geoms and NodeTransitions, and are
196  // intended to be invoked only directly by the appropriate Geom and
197  // NodeTransition types. They're public only because it would be too
198  // inconvenient to declare each of those types to be friends of this
199  // class.
200 
201  virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,
202  const GeomMunger *munger,
203  const GeomVertexDataPipelineReader *data_reader,
204  bool force)=0;
205  virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader, bool force)=0;
206  virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
207  virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader, bool force)=0;
208  virtual bool draw_patches(const GeomPrimitivePipelineReader *reader, bool force)=0;
209  virtual bool draw_lines(const GeomPrimitivePipelineReader *reader, bool force)=0;
210  virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
211  virtual bool draw_points(const GeomPrimitivePipelineReader *reader, bool force)=0;
212  virtual void end_draw_primitives()=0;
213 
214  virtual bool framebuffer_copy_to_texture
215  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
216  virtual bool framebuffer_copy_to_ram
217  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
218 
219  virtual CoordinateSystem get_internal_coordinate_system() const=0;
220 
221  virtual void bind_light(PointLight *light_obj, const NodePath &light,
222  int light_id) { }
223  virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
224  int light_id) { }
225  virtual void bind_light(Spotlight *light_obj, const NodePath &light,
226  int light_id) { }
227 
228  // This function creates a shadow mapping buffer. This is not put in ShaderGenerator
229  // because that would cause circular dependencies.
230  virtual PT(Texture) make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host)=0;
231 
232 PUBLISHED:
233  static GraphicsStateGuardianBase *get_default_gsg();
234  static void set_default_gsg(GraphicsStateGuardianBase *default_gsg);
235 
236  static int get_num_gsgs();
237  static GraphicsStateGuardianBase *get_gsg(int n);
238  MAKE_SEQ(get_gsgs, get_num_gsgs, get_gsg);
239 
240 public:
241  static void add_gsg(GraphicsStateGuardianBase *gsg);
242  static void remove_gsg(GraphicsStateGuardianBase *gsg);
243 
244 private:
246  static GSGs _gsgs;
247  static GraphicsStateGuardianBase *_default_gsg;
248  static LightMutex _lock;
249 
250 public:
251  static TypeHandle get_class_type() {
252  return _type_handle;
253  }
254  static void init_type() {
255  TypedWritableReferenceCount::init_type();
256  register_type(_type_handle, "GraphicsStateGuardianBase",
257  TypedWritableReferenceCount::get_class_type());
258  }
259  virtual TypeHandle get_type() const {
260  return get_class_type();
261  }
262  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
263 
264 private:
265  static TypeHandle _type_handle;
266 };
267 
268 #endif
A light shining from infinitely far away in a particular direction, like sunlight.
This is a special class object that holds all the information returned by a particular GSG to indicat...
Definition: geomContext.h:39
Enables or disables writing to the depth buffer.
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:45
Enables or disables writing to the color buffer.
Defines a series of disconnected points.
Definition: geomPoints.h:25
Indicates which, if any, material should be applied to geometry.
Enables or disables writing to the depth buffer.
Specifies whether or how to enable antialiasing, if supported by the backend renderer.
This controls the enabling of transparency.
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
Definition: geomMunger.h:57
This is a special class object that holds all the information returned by a particular GSG to indicat...
Defines a series of triangle fans.
Definition: geomTrifans.h:25
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
Specifies whether flat shading (per-polygon) or smooth shading (per-vertex) is in effect...
Definition: shader.h:50
This is a special class object that holds all the information returned by a particular GSG to indicat...
Defines a series of triangle strips.
Definition: geomTristrips.h:25
A light source that seems to illuminate all points in space at once.
Definition: ambientLight.h:29
This functions similarly to a LightAttrib.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
Definition: geom.h:401
A table of objects that are saved within the graphics context for reference by handle later...
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
The ShaderContext is meant to contain the compiled version of a shader string.
Definition: shaderContext.h:35
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
Definition: textureAttrib.h:34
Indicates which faces should be culled based on their vertex ordering.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
Applies a Fog to the geometry at and below this node.
Definition: fogAttrib.h:27
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
A light originating from a single point in space, and shining in a particular direction, with a cone-shaped falloff.
Definition: spotlight.h:37
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Enables or disables writing of pixel to framebuffer based on its alpha value relative to a reference ...
This is a base class for the various different classes that represent the result of a frame of render...
Defines the way an object appears in the presence of lighting.
Definition: material.h:34
Applies a scale to colors in the scene graph and on vertices.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
Defines a series of disconnected line segments.
Definition: geomLines.h:25
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:39
This is a special class object that holds a handle to the sampler state object given by the graphics ...
Applies a transform matrix to UV's before they are rendered.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This specifies how colors are blended into the frame buffer, for special effects. ...
A thread; that is, a lightweight process.
Definition: thread.h:51
A derivative of Light and of Camera.
Definition: lightLensNode.h:35
Defines a series of line strips.
This is a special kind of attribute that instructs the graphics driver to apply an offset or bias to ...
This is a special class object that holds all the information returned by a particular GSG to indicat...
Specifies how polygons are to be drawn.
Defines a series of disconnected triangles.
Definition: geomTriangles.h:25
Specifies how polygons are to be drawn.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
Indicates what color should be applied to renderable geometry.
Definition: colorAttrib.h:30
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
An abstract base class for GraphicsOutput, for all the usual reasons.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:35
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
Computes texture coordinates for geometry automatically based on vertex position and/or normal...
Definition: texGenAttrib.h:36
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer, etc.) of a drawing region.
Definition: renderBuffer.h:30
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A light originating from a single point in space, and shining in all directions.
Definition: pointLight.h:27
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
This is the data for one array of a GeomVertexData structure.
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
Definition: lightAttrib.h:33