Panda3D
graphicsStateGuardianBase.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file graphicsStateGuardianBase.h
10  * @author drose
11  * @date 1999-10-06
12  */
13 
14 #ifndef GRAPHICSSTATEGUARDIANBASE_H
15 #define GRAPHICSSTATEGUARDIANBASE_H
16 
17 #include "pandabase.h"
18 
21 #include "luse.h"
22 #include "lightMutex.h"
23 
24 // A handful of forward references.
25 
26 class Thread;
27 class RenderBuffer;
28 class GraphicsWindow;
29 class NodePath;
30 class GraphicsOutputBase;
31 
33 class IndexBufferContext;
34 class BufferContext;
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 ShaderBuffer;
62 class RenderState;
63 class TransformState;
64 class Material;
65 
66 class ColorScaleAttrib;
67 class TexMatrixAttrib;
68 class ColorAttrib;
69 class TextureAttrib;
70 class LightAttrib;
71 class MaterialAttrib;
72 class RenderModeAttrib;
73 class AntialiasAttrib;
75 class ColorBlendAttrib;
76 class ColorWriteAttrib;
77 class AlphaTestAttrib;
78 class DepthTestAttrib;
79 class DepthWriteAttrib;
80 class TexGenAttrib;
81 class ShaderAttrib;
82 class CullFaceAttrib;
83 class ClipPlaneAttrib;
84 class ShadeModelAttrib;
85 class TransparencyAttrib;
86 class FogAttrib;
87 class DepthOffsetAttrib;
88 
89 class PointLight;
90 class DirectionalLight;
91 class Spotlight;
92 class AmbientLight;
93 class LightLensNode;
94 
95 class DisplayRegion;
96 class Lens;
97 
98 /**
99  * This is a base class for the GraphicsStateGuardian class, which is itself a
100  * base class for the various GSG's for different platforms. This class
101  * contains all the function prototypes to support the double-dispatch of GSG
102  * to geoms, transitions, etc. It lives in a separate class in its own
103  * package so we can avoid circular build dependency problems.
104  *
105  * GraphicsStateGuardians are not actually writable to bam files, of course,
106  * but they may be passed as event parameters, so they inherit from
107  * TypedWritableReferenceCount instead of TypedReferenceCount for that
108  * convenience.
109  */
110 class EXPCL_PANDA_GSGBASE GraphicsStateGuardianBase : public TypedWritableReferenceCount {
111 PUBLISHED:
112  virtual bool get_incomplete_render() const=0;
113  virtual bool get_effective_incomplete_render() const=0;
114 
115  virtual bool prefers_triangle_strips() const=0;
116  virtual int get_max_vertices_per_array() const=0;
117  virtual int get_max_vertices_per_primitive() const=0;
118 
119  virtual int get_max_texture_dimension() const=0;
120  virtual bool get_supports_compressed_texture_format(int compression_mode) const=0;
121 
122  virtual bool get_supports_multisample() const=0;
123  virtual int get_supported_geom_rendering() const=0;
124  virtual bool get_supports_shadow_filter() const=0;
125 
126  virtual bool get_supports_texture_srgb() const=0;
127 
128  virtual bool get_supports_hlsl() const=0;
129 
130 public:
131  // These are some general interface functions; they're defined here mainly
132  // to make it easy to call these from code in some directory that display
133  // depends on.
134  virtual SceneSetup *get_scene() const=0;
135 
136  virtual void clear_before_callback()=0;
137  virtual void clear_state_and_transform()=0;
138 
139  virtual void remove_window(GraphicsOutputBase *window)=0;
140 
141 #ifndef CPPPARSER
142  // We hide this from interrogate, so that it will be properly exported from
143  // the GraphicsStateGuardian class, later.
144  virtual PreparedGraphicsObjects *get_prepared_objects()=0;
145 #endif
146 
147  virtual TextureContext *prepare_texture(Texture *tex, int view)=0;
148  virtual bool update_texture(TextureContext *tc, bool force)=0;
149  virtual void release_texture(TextureContext *tc)=0;
150  virtual bool extract_texture_data(Texture *tex)=0;
151 
152  virtual SamplerContext *prepare_sampler(const SamplerState &sampler)=0;
153  virtual void release_sampler(SamplerContext *sc)=0;
154 
155  virtual GeomContext *prepare_geom(Geom *geom)=0;
156  virtual void release_geom(GeomContext *gc)=0;
157 
158  virtual ShaderContext *prepare_shader(Shader *shader)=0;
159  virtual void release_shader(ShaderContext *sc)=0;
160 
161  virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data)=0;
162  virtual void release_vertex_buffer(VertexBufferContext *vbc)=0;
163 
164  virtual IndexBufferContext *prepare_index_buffer(GeomPrimitive *data)=0;
165  virtual void release_index_buffer(IndexBufferContext *ibc)=0;
166 
167  virtual BufferContext *prepare_shader_buffer(ShaderBuffer *data)=0;
168  virtual void release_shader_buffer(BufferContext *ibc)=0;
169 
170  virtual void dispatch_compute(int size_x, int size_y, int size_z)=0;
171 
172  virtual PT(GeomMunger) get_geom_munger(const RenderState *state,
173  Thread *current_thread)=0;
174 
175  virtual void set_state_and_transform(const RenderState *state,
176  const TransformState *transform)=0;
177 
178  // This function may only be called during a render traversal; it will
179  // compute the distance to the indicated point, assumed to be in eye
180  // coordinates, from the camera plane. This is a virtual function because
181  // different GSG's may define the eye coordinate space differently.
182  virtual PN_stdfloat compute_distance_to(const LPoint3 &point) const=0;
183 
184  // These are used to implement decals. If depth_offset_decals() returns
185  // true, none of the remaining functions will be called, since depth offsets
186  // can be used to implement decals fully (and 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 double-dispatching from
195  // Geoms and NodeTransitions, and are intended to be invoked only directly
196  // by the appropriate Geom and NodeTransition types. They're public only
197  // because it would be too inconvenient to declare each of those types to be
198  // friends of this class.
199 
200  virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,
201  const GeomVertexDataPipelineReader *data_reader,
202  bool force)=0;
203  virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader, bool force)=0;
204  virtual bool draw_triangles_adj(const GeomPrimitivePipelineReader *reader, bool force)=0;
205  virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
206  virtual bool draw_tristrips_adj(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_lines_adj(const GeomPrimitivePipelineReader *reader, bool force)=0;
211  virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force)=0;
212  virtual bool draw_linestrips_adj(const GeomPrimitivePipelineReader *reader, bool force)=0;
213  virtual bool draw_points(const GeomPrimitivePipelineReader *reader, bool force)=0;
214  virtual void end_draw_primitives()=0;
215 
216  virtual bool framebuffer_copy_to_texture
217  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
218  virtual bool framebuffer_copy_to_ram
219  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)=0;
220 
221  virtual CoordinateSystem get_internal_coordinate_system() const=0;
222 
223  virtual void bind_light(PointLight *light_obj, const NodePath &light,
224  int light_id) { }
225  virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
226  int light_id) { }
227  virtual void bind_light(Spotlight *light_obj, const NodePath &light,
228  int light_id) { }
229 
230  virtual void ensure_generated_shader(const RenderState *state)=0;
231 
232  static void mark_rehash_generated_shaders() {
233 #ifdef HAVE_CG
234  ++_generated_shader_seq;
235 #endif
236  }
237 
238  virtual void push_group_marker(const std::string &marker) {}
239  virtual void pop_group_marker() {}
240 
241 PUBLISHED:
242  static GraphicsStateGuardianBase *get_default_gsg();
243  static void set_default_gsg(GraphicsStateGuardianBase *default_gsg);
244 
245  static size_t get_num_gsgs();
246  static GraphicsStateGuardianBase *get_gsg(size_t n);
247  MAKE_SEQ(get_gsgs, get_num_gsgs, get_gsg);
248 
249 public:
250  static void add_gsg(GraphicsStateGuardianBase *gsg);
251  static void remove_gsg(GraphicsStateGuardianBase *gsg);
252 
253  size_t _id;
254 
255 private:
256  struct GSGList {
257  LightMutex _lock;
258 
260  GSGs _gsgs;
261  GraphicsStateGuardianBase *_default_gsg;
262  };
263  static AtomicAdjust::Pointer _gsg_list;
264 
265 protected:
266  static UpdateSeq _generated_shader_seq;
267 
268 public:
269  static TypeHandle get_class_type() {
270  return _type_handle;
271  }
272  static void init_type() {
273  TypedWritableReferenceCount::init_type();
274  register_type(_type_handle, "GraphicsStateGuardianBase",
275  TypedWritableReferenceCount::get_class_type());
276  }
277  virtual TypeHandle get_type() const {
278  return get_class_type();
279  }
280  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
281 
282 private:
283  static TypeHandle _type_handle;
284 };
285 
286 #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:34
Indicates a coordinate-system transform on vertices.
Enables or disables writing to the depth buffer.
This is a generic buffer object that lives in graphics memory.
Definition: shaderBuffer.h:33
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:41
Enables or disables writing to the color buffer.
Defines a series of disconnected points.
Definition: geomPoints.h:23
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:50
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:23
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:38
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:56
Specifies whether flat shading (per-polygon) or smooth shading (per-vertex) is in effect.
Definition: shader.h:49
This is a special class object that holds all the information returned by a particular GSG to indicat...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a series of triangle strips.
Definition: geomTristrips.h:23
A light source that seems to illuminate all points in space at once.
Definition: ambientLight.h:26
This functions similarly to a LightAttrib.
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
Definition: geom.h:405
A table of objects that are saved within the graphics context for reference by handle later.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:31
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
Definition: textureAttrib.h:31
Indicates which faces should be culled based on their vertex ordering.
Applies a Fog to the geometry at and below this node.
Definition: fogAttrib.h:25
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:54
A light originating from a single point in space, and shining in a particular direction,...
Definition: spotlight.h:32
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:43
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:47
Defines a series of disconnected line segments.
Definition: geomLines.h:23
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:36
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:46
A derivative of Light and of Camera.
Definition: lightLensNode.h:33
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:23
Specifies how polygons are to be drawn.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:57
Indicates what color should be applied to renderable geometry.
Definition: colorAttrib.h:27
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:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:32
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
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:32
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
Definition: renderBuffer.h:27
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
A light originating from a single point in space, and shining in all directions.
Definition: pointLight.h:25
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
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:30