Panda3D
graphicsStateGuardian.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 graphicsStateGuardian.h
10  * @author drose
11  * @date 1999-02-02
12  * @author fperazzi, PandaSE
13  * @date 2010-05-05
14  * _max_2d_texture_array_layers on z axis, get_supports_cg_profile)
15  */
16 
17 #ifndef GRAPHICSSTATEGUARDIAN_H
18 #define GRAPHICSSTATEGUARDIAN_H
19 
20 #include "pandabase.h"
21 
22 #include "frameBufferProperties.h"
24 #include "lens.h"
26 #include "graphicsThreadingModel.h"
27 #include "graphicsPipe.h"
28 #include "sceneSetup.h"
29 #include "displayRegion.h"
30 #include "luse.h"
31 #include "coordinateSystem.h"
32 #include "factory.h"
33 #include "pStatCollector.h"
34 #include "transformState.h"
35 #include "renderState.h"
36 #include "light.h"
37 #include "planeNode.h"
38 #include "config_display.h"
39 #include "geomMunger.h"
40 #include "geomVertexData.h"
41 #include "pnotify.h"
42 #include "pvector.h"
43 #include "shaderContext.h"
44 #include "bitMask.h"
45 #include "texture.h"
46 #include "occlusionQueryContext.h"
47 #include "timerQueryContext.h"
48 #include "loader.h"
49 #include "shaderAttrib.h"
50 #include "texGenAttrib.h"
51 #include "textureAttrib.h"
52 #include "shaderGenerator.h"
53 
54 class DrawableRegion;
55 class GraphicsEngine;
56 
57 /**
58  * Encapsulates all the communication with a particular instance of a given
59  * rendering backend. Tries to guarantee that redundant state-change requests
60  * are not issued (hence "state guardian").
61  *
62  * There will be one of these objects for each different graphics context
63  * active in the system.
64  */
65 class EXPCL_PANDA_DISPLAY GraphicsStateGuardian : public GraphicsStateGuardianBase {
66  // Interfaces all GSGs should have
67 public:
68  GraphicsStateGuardian(CoordinateSystem internal_coordinate_system,
69  GraphicsEngine *engine, GraphicsPipe *pipe);
70  virtual ~GraphicsStateGuardian();
71 
72 PUBLISHED:
73 
74  enum ShaderModel {
75  SM_00,
76  SM_11,
77  SM_20,
78  SM_2X,
79  SM_30,
80  SM_40,
81  SM_50,
82  SM_51,
83  };
84 
85  INLINE void release_all();
86  INLINE int release_all_textures();
87  INLINE int release_all_samplers();
88  INLINE int release_all_geoms();
89  INLINE int release_all_vertex_buffers();
90  INLINE int release_all_index_buffers();
91  INLINE int release_all_shader_buffers();
92 
93  INLINE void set_active(bool active);
94  INLINE bool is_active() const;
95  INLINE bool is_valid() const;
96  INLINE bool needs_reset() const;
97  MAKE_PROPERTY(active, is_active, set_active);
98  MAKE_PROPERTY(valid, is_valid);
99 
100  INLINE void set_incomplete_render(bool incomplete_render);
101  virtual INLINE bool get_incomplete_render() const;
102  virtual INLINE bool get_effective_incomplete_render() const;
103  MAKE_PROPERTY(incomplete_render, get_incomplete_render, set_incomplete_render);
104  MAKE_PROPERTY(effective_incomplete_render, get_effective_incomplete_render);
105 
106  INLINE void set_loader(Loader *loader);
107  INLINE Loader *get_loader() const;
108  MAKE_PROPERTY(loader, get_loader, set_loader);
109 
110  INLINE void set_shader_generator(ShaderGenerator *shader_generator);
111  INLINE ShaderGenerator *get_shader_generator() const;
112  MAKE_PROPERTY(shader_generator, get_shader_generator, set_shader_generator);
113 
114  INLINE GraphicsPipe *get_pipe() const;
115  GraphicsEngine *get_engine() const;
116  INLINE const GraphicsThreadingModel &get_threading_model() const;
117  MAKE_PROPERTY(pipe, get_pipe);
118 
119  INLINE bool is_hardware() const;
120  virtual INLINE bool prefers_triangle_strips() const;
121  virtual INLINE int get_max_vertices_per_array() const;
122  virtual INLINE int get_max_vertices_per_primitive() const;
123 
124  INLINE int get_max_texture_stages() const;
125  virtual INLINE int get_max_texture_dimension() const;
126  INLINE int get_max_3d_texture_dimension() const;
127  INLINE int get_max_2d_texture_array_layers() const; //z axis
128  INLINE int get_max_cube_map_dimension() const;
129  INLINE int get_max_buffer_texture_size() const;
130 
131  INLINE bool get_supports_texture_combine() const;
132  INLINE bool get_supports_texture_saved_result() const;
133  INLINE bool get_supports_texture_dot3() const;
134 
135  INLINE bool get_supports_3d_texture() const;
136  INLINE bool get_supports_2d_texture_array() const;
137  INLINE bool get_supports_cube_map() const;
138  INLINE bool get_supports_buffer_texture() const;
139  INLINE bool get_supports_cube_map_array() const;
140  INLINE bool get_supports_tex_non_pow2() const;
141  INLINE bool get_supports_texture_srgb() const;
142 
143  INLINE bool get_supports_compressed_texture() const;
144  virtual INLINE bool get_supports_compressed_texture_format(int compression_mode) const;
145 
146  INLINE int get_max_lights() const;
147  INLINE int get_max_clip_planes() const;
148 
149  INLINE int get_max_vertex_transforms() const;
150  INLINE int get_max_vertex_transform_indices() const;
151 
152  INLINE bool get_copy_texture_inverted() const;
153  virtual bool get_supports_multisample() const;
154  INLINE bool get_supports_generate_mipmap() const;
155  INLINE bool get_supports_depth_texture() const;
156  INLINE bool get_supports_depth_stencil() const;
157  INLINE bool get_supports_luminance_texture() const;
158  INLINE bool get_supports_shadow_filter() const;
159  INLINE bool get_supports_sampler_objects() const;
160  INLINE bool get_supports_basic_shaders() const;
161  INLINE bool get_supports_geometry_shaders() const;
162  INLINE bool get_supports_tessellation_shaders() const;
163  INLINE bool get_supports_compute_shaders() const;
164  INLINE bool get_supports_glsl() const;
165  INLINE bool get_supports_hlsl() const;
166  INLINE bool get_supports_stencil() const;
167  INLINE bool get_supports_two_sided_stencil() const;
168  INLINE bool get_supports_geometry_instancing() const;
169  INLINE bool get_supports_indirect_draw() const;
170 
171  INLINE bool get_supports_occlusion_query() const;
172  INLINE bool get_supports_timer_query() const;
173  INLINE bool get_timer_queries_active() const;
174 
175  INLINE int get_max_color_targets() const;
176  INLINE int get_maximum_simultaneous_render_targets() const;
177  INLINE bool get_supports_dual_source_blending() const;
178 
179  MAKE_PROPERTY(max_vertices_per_array, get_max_vertices_per_array);
180  MAKE_PROPERTY(max_vertices_per_primitive, get_max_vertices_per_primitive);
181  MAKE_PROPERTY(max_texture_stages, get_max_texture_stages);
182  MAKE_PROPERTY(max_texture_dimension, get_max_texture_dimension);
183  MAKE_PROPERTY(max_3d_texture_dimension, get_max_3d_texture_dimension);
184  MAKE_PROPERTY(max_2d_texture_array_layers, get_max_2d_texture_array_layers);
185  MAKE_PROPERTY(max_cube_map_dimension, get_max_cube_map_dimension);
186  MAKE_PROPERTY(max_buffer_texture_size, get_max_buffer_texture_size);
187  MAKE_PROPERTY(supports_texture_combine, get_supports_texture_combine);
188  MAKE_PROPERTY(supports_texture_saved_result, get_supports_texture_saved_result);
189  MAKE_PROPERTY(supports_texture_dot3, get_supports_texture_dot3);
190  MAKE_PROPERTY(supports_3d_texture, get_supports_3d_texture);
191  MAKE_PROPERTY(supports_2d_texture_array, get_supports_2d_texture_array);
192  MAKE_PROPERTY(supports_cube_map, get_supports_cube_map);
193  MAKE_PROPERTY(supports_buffer_texture, get_supports_buffer_texture);
194  MAKE_PROPERTY(supports_cube_map_array, get_supports_cube_map_array);
195  MAKE_PROPERTY(supports_tex_non_pow2, get_supports_tex_non_pow2);
196  MAKE_PROPERTY(supports_texture_srgb, get_supports_texture_srgb);
197  MAKE_PROPERTY(supports_compressed_texture, get_supports_compressed_texture);
198  MAKE_PROPERTY(max_lights, get_max_lights);
199  MAKE_PROPERTY(max_clip_planes, get_max_clip_planes);
200  MAKE_PROPERTY(max_vertex_transforms, get_max_vertex_transforms);
201  MAKE_PROPERTY(max_vertex_transform_indices, get_max_vertex_transform_indices);
202  MAKE_PROPERTY(copy_texture_inverted, get_copy_texture_inverted);
203  MAKE_PROPERTY(supports_multisample, get_supports_multisample);
204  MAKE_PROPERTY(supports_generate_mipmap, get_supports_generate_mipmap);
205  MAKE_PROPERTY(supports_depth_texture, get_supports_depth_texture);
206  MAKE_PROPERTY(supports_depth_stencil, get_supports_depth_stencil);
207  MAKE_PROPERTY(supports_luminance_texture, get_supports_luminance_texture);
208  MAKE_PROPERTY(supports_shadow_filter, get_supports_shadow_filter);
209  MAKE_PROPERTY(supports_sampler_objects, get_supports_sampler_objects);
210  MAKE_PROPERTY(supports_basic_shaders, get_supports_basic_shaders);
211  MAKE_PROPERTY(supports_geometry_shaders, get_supports_geometry_shaders);
212  MAKE_PROPERTY(supports_tessellation_shaders, get_supports_tessellation_shaders);
213  MAKE_PROPERTY(supports_compute_shaders, get_supports_compute_shaders);
214  MAKE_PROPERTY(supports_glsl, get_supports_glsl);
215  MAKE_PROPERTY(supports_hlsl, get_supports_hlsl);
216  MAKE_PROPERTY(supports_stencil, get_supports_stencil);
217  MAKE_PROPERTY(supports_two_sided_stencil, get_supports_two_sided_stencil);
218  MAKE_PROPERTY(supports_geometry_instancing, get_supports_geometry_instancing);
219  MAKE_PROPERTY(supports_indirect_draw, get_supports_indirect_draw);
220  MAKE_PROPERTY(supports_occlusion_query, get_supports_occlusion_query);
221  MAKE_PROPERTY(supports_timer_query, get_supports_timer_query);
222  MAKE_PROPERTY(timer_queries_active, get_timer_queries_active);
223  MAKE_PROPERTY(max_color_targets, get_max_color_targets);
224  MAKE_PROPERTY(supports_dual_source_blending, get_supports_dual_source_blending);
225 
226  INLINE ShaderModel get_shader_model() const;
227  INLINE void set_shader_model(ShaderModel shader_model);
228  MAKE_PROPERTY(shader_model, get_shader_model, set_shader_model);
229 
230  virtual int get_supported_geom_rendering() const;
231  virtual bool get_supports_cg_profile(const std::string &name) const;
232 
233  INLINE bool get_color_scale_via_lighting() const;
234  INLINE bool get_alpha_scale_via_texture() const;
235  INLINE bool get_alpha_scale_via_texture(const TextureAttrib *tex_attrib) const;
236  INLINE bool get_runtime_color_scale() const;
237 
238  INLINE static TextureStage *get_alpha_scale_texture_stage();
239 
240  void set_coordinate_system(CoordinateSystem cs);
241  INLINE CoordinateSystem get_coordinate_system() const;
242  virtual CoordinateSystem get_internal_coordinate_system() const;
243  MAKE_PROPERTY(coordinate_system, get_coordinate_system, set_coordinate_system);
244 
245  virtual PreparedGraphicsObjects *get_prepared_objects();
246  MAKE_PROPERTY(prepared_objects, get_prepared_objects);
247 
248  virtual bool set_gamma(PN_stdfloat gamma);
249  PN_stdfloat get_gamma() const;
250  virtual void restore_gamma();
251  MAKE_PROPERTY(gamma, get_gamma, set_gamma);
252 
253  INLINE void set_texture_quality_override(Texture::QualityLevel quality_level);
254  INLINE Texture::QualityLevel get_texture_quality_override() const;
255  MAKE_PROPERTY(texture_quality_override, get_texture_quality_override,
256  set_texture_quality_override);
257 
258  EXTENSION(PyObject *get_prepared_textures() const);
259  typedef bool TextureCallback(TextureContext *tc, void *callback_arg);
260  void traverse_prepared_textures(TextureCallback *func, void *callback_arg);
261 
262 #ifndef NDEBUG
263  void set_flash_texture(Texture *tex);
264  void clear_flash_texture();
265  Texture *get_flash_texture() const;
266  MAKE_PROPERTY(flash_texture, get_flash_texture, set_flash_texture);
267 #endif
268 
269 PUBLISHED:
270  virtual bool has_extension(const std::string &extension) const;
271 
272  virtual std::string get_driver_vendor();
273  virtual std::string get_driver_renderer();
274  virtual std::string get_driver_version();
275  virtual int get_driver_version_major();
276  virtual int get_driver_version_minor();
277  virtual int get_driver_shader_version_major();
278  virtual int get_driver_shader_version_minor();
279 
280  MAKE_PROPERTY(driver_vendor, get_driver_vendor);
281  MAKE_PROPERTY(driver_renderer, get_driver_renderer);
282  MAKE_PROPERTY(driver_version, get_driver_version);
283  MAKE_PROPERTY(driver_version_major, get_driver_version_major);
284  MAKE_PROPERTY(driver_version_minor, get_driver_version_minor);
285  MAKE_PROPERTY(driver_shader_version_major, get_driver_shader_version_major);
286  MAKE_PROPERTY(driver_shader_version_minor, get_driver_shader_version_minor);
287 
288  bool set_scene(SceneSetup *scene_setup);
289  virtual SceneSetup *get_scene() const final;
290  MAKE_PROPERTY(scene, get_scene, set_scene);
291 
292 public:
293  virtual TextureContext *prepare_texture(Texture *tex, int view);
294  virtual bool update_texture(TextureContext *tc, bool force);
295  virtual void release_texture(TextureContext *tc);
296  virtual bool extract_texture_data(Texture *tex);
297 
298  virtual SamplerContext *prepare_sampler(const SamplerState &sampler);
299  virtual void release_sampler(SamplerContext *sc);
300 
301  virtual GeomContext *prepare_geom(Geom *geom);
302  virtual void release_geom(GeomContext *gc);
303 
304  virtual ShaderContext *prepare_shader(Shader *shader);
305  virtual void release_shader(ShaderContext *sc);
306 
307  virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data);
308  virtual void release_vertex_buffer(VertexBufferContext *vbc);
309 
310  virtual IndexBufferContext *prepare_index_buffer(GeomPrimitive *data);
311  virtual void release_index_buffer(IndexBufferContext *ibc);
312 
313  virtual BufferContext *prepare_shader_buffer(ShaderBuffer *data);
314  virtual void release_shader_buffer(BufferContext *ibc);
315 
316  virtual void begin_occlusion_query();
317  virtual PT(OcclusionQueryContext) end_occlusion_query();
318 
319  virtual PT(TimerQueryContext) issue_timer_query(int pstats_index);
320 
321  virtual void dispatch_compute(int size_x, int size_y, int size_z);
322 
323  virtual PT(GeomMunger) get_geom_munger(const RenderState *state,
324  Thread *current_thread);
325  virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
326  Thread *current_thread);
327 
328  virtual void set_state_and_transform(const RenderState *state,
329  const TransformState *transform);
330 
331  PN_stdfloat compute_distance_to(const LPoint3 &point) const;
332 
333  virtual void clear(DrawableRegion *clearable);
334 
335  const LMatrix4 *fetch_specified_value(Shader::ShaderMatSpec &spec, int altered);
336  const LMatrix4 *fetch_specified_part(Shader::ShaderMatInput input, InternalName *name,
337  LMatrix4 &t, int index);
338  const LMatrix4 *fetch_specified_member(const NodePath &np, CPT_InternalName member, LMatrix4 &t);
339  PT(Texture) fetch_specified_texture(Shader::ShaderTexSpec &spec,
340  SamplerState &sampler, int &view);
341  const Shader::ShaderPtrData *fetch_ptr_parameter(const Shader::ShaderPtrSpec& spec);
342 
343  virtual void prepare_display_region(DisplayRegionPipelineReader *dr);
344  virtual void clear_before_callback();
345  virtual void clear_state_and_transform();
346 
347  virtual void remove_window(GraphicsOutputBase *window);
348 
349  virtual CPT(TransformState) calc_projection_mat(const Lens *lens);
350  virtual bool prepare_lens();
351 
352  virtual bool begin_frame(Thread *current_thread);
353 PUBLISHED:
354  virtual bool begin_scene();
355  virtual void end_scene();
356 public:
357  virtual void end_frame(Thread *current_thread);
358 
359  void flush_timer_queries();
360 
361  void set_current_properties(const FrameBufferProperties *properties);
362 
363  virtual bool depth_offset_decals();
364  virtual CPT(RenderState) begin_decal_base_first();
365  virtual CPT(RenderState) begin_decal_nested();
366  virtual CPT(RenderState) begin_decal_base_second();
367  virtual void finish_decal();
368 
369  virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,
370  const GeomVertexDataPipelineReader *data_reader,
371  bool force);
372  virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader,
373  bool force);
374  virtual bool draw_triangles_adj(const GeomPrimitivePipelineReader *reader,
375  bool force);
376  virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader,
377  bool force);
378  virtual bool draw_tristrips_adj(const GeomPrimitivePipelineReader *reader,
379  bool force);
380  virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader,
381  bool force);
382  virtual bool draw_patches(const GeomPrimitivePipelineReader *reader,
383  bool force);
384  virtual bool draw_lines(const GeomPrimitivePipelineReader *reader,
385  bool force);
386  virtual bool draw_lines_adj(const GeomPrimitivePipelineReader *reader,
387  bool force);
388  virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader,
389  bool force);
390  virtual bool draw_linestrips_adj(const GeomPrimitivePipelineReader *reader,
391  bool force);
392  virtual bool draw_points(const GeomPrimitivePipelineReader *reader,
393  bool force);
394  virtual void end_draw_primitives();
395 
396  INLINE bool reset_if_new();
397  INLINE void mark_new();
398  virtual void reset();
399 
400  INLINE CPT(TransformState) get_external_transform() const;
401  INLINE CPT(TransformState) get_internal_transform() const;
402 
403  RenderBuffer get_render_buffer(int buffer_type, const FrameBufferProperties &prop);
404 
405  INLINE const DisplayRegion *get_current_display_region() const;
406  INLINE Lens::StereoChannel get_current_stereo_channel() const;
407  INLINE int get_current_tex_view_offset() const;
408  INLINE const Lens *get_current_lens() const;
409 
410  virtual CPT(TransformState) get_cs_transform_for(CoordinateSystem cs) const;
411  virtual CPT(TransformState) get_cs_transform() const;
412  INLINE CPT(TransformState) get_inv_cs_transform() const;
413 
414  void do_issue_clip_plane();
415  void do_issue_color();
416  void do_issue_color_scale();
417  virtual void do_issue_light();
418 
419  virtual bool framebuffer_copy_to_texture
420  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb);
421  virtual bool framebuffer_copy_to_ram
422  (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb);
423 
424  virtual void bind_light(PointLight *light_obj, const NodePath &light,
425  int light_id);
426  virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
427  int light_id);
428  virtual void bind_light(Spotlight *light_obj, const NodePath &light,
429  int light_id);
430 
431  static void create_gamma_table (PN_stdfloat gamma, unsigned short *red_table, unsigned short *green_table, unsigned short *blue_table);
432 
433  PT(Texture) get_shadow_map(const NodePath &light_np, GraphicsOutputBase *host=nullptr);
434  PT(Texture) get_dummy_shadow_map(Texture::TextureType texture_type) const;
435  virtual GraphicsOutput *make_shadow_buffer(LightLensNode *light, Texture *tex, GraphicsOutput *host);
436 
437  virtual void ensure_generated_shader(const RenderState *state);
438 
439 #ifdef DO_PSTATS
440  static void init_frame_pstats();
441 #endif
442 
443 protected:
444  virtual void reissue_transforms();
445 
446  virtual void enable_lighting(bool enable);
447  virtual void set_ambient_light(const LColor &color);
448  virtual void enable_light(int light_id, bool enable);
449  virtual void begin_bind_lights();
450  virtual void end_bind_lights();
451 
452  virtual void enable_clip_planes(bool enable);
453  virtual void enable_clip_plane(int plane_id, bool enable);
454  virtual void begin_bind_clip_planes();
455  virtual void bind_clip_plane(const NodePath &plane, int plane_id);
456  virtual void end_bind_clip_planes();
457 
458  void determine_target_texture();
459  void determine_target_shader();
460 
461  virtual void free_pointers();
462  virtual void close_gsg();
463  void panic_deactivate();
464 
465  void determine_light_color_scale();
466 
467  static CPT(RenderState) get_unlit_state();
468  static CPT(RenderState) get_unclipped_state();
469  static CPT(RenderState) get_untextured_state();
470 
471  AsyncFuture *async_reload_texture(TextureContext *tc);
472 
473 protected:
474  PT(SceneSetup) _scene_null;
475  PT(SceneSetup) _scene_setup;
476 
477  // The current state of the graphics context, as of the last call to
478  // set_state_and_transform().
479  CPT(RenderState) _state_rs;
480 
481  // The desired state of the graphics context, during processing of
482  // set_state_and_transform().
483  CPT(RenderState) _target_rs;
484 
485  // This bitmask contains a 1 bit everywhere that _state_rs has a known
486  // value. If a bit is 0, the corresponding state must be re-sent. Derived
487  // GSGs should initialize _inv_state_mask in reset() as a mask of 1's where
488  // they don't care, and 0's where they do care, about the state.
489  RenderState::SlotMask _state_mask;
490  RenderState::SlotMask _inv_state_mask;
491 
492  // The current transform, as of the last call to set_state_and_transform().
493  CPT(TransformState) _internal_transform;
494 
495  // The current TextureAttrib is a special case; we may further restrict it
496  // (according to graphics cards limits) or extend it (according to
497  // ColorScaleAttribs in effect) beyond what is specifically requested in the
498  // scene graph.
499  CPT(TextureAttrib) _target_texture;
500  CPT(TextureAttrib) _state_texture;
501  CPT(TexGenAttrib) _target_tex_gen;
502  CPT(TexGenAttrib) _state_tex_gen;
503 
504  // Also, the shader might be the explicitly-requested shader, or it might be
505  // an auto-generated one.
506  CPT(ShaderAttrib) _state_shader;
507  CPT(ShaderAttrib) _target_shader;
508 
509  // This is set by begin_draw_primitives(), and are only valid between
510  // begin_draw_primitives() and end_draw_primitives().
511  const GeomVertexDataPipelineReader *_data_reader;
512 
513  unsigned int _color_write_mask;
514 
515  PT(DisplayRegion) _current_display_region;
516  Lens::StereoChannel _current_stereo_channel;
517  int _current_tex_view_offset;
518  CPT(Lens) _current_lens;
519  CPT(TransformState) _projection_mat;
520  CPT(TransformState) _projection_mat_inv;
521  const FrameBufferProperties *_current_properties;
522 
523  CoordinateSystem _coordinate_system;
524  CoordinateSystem _internal_coordinate_system;
525  CPT(TransformState) _cs_transform;
526  CPT(TransformState) _inv_cs_transform;
527 
528  LColor _scene_graph_color;
529  bool _has_scene_graph_color;
530  bool _transform_stale;
531  bool _color_blend_involves_color_scale;
532  bool _texture_involves_color_scale;
533  bool _vertex_colors_enabled;
534  bool _lighting_enabled;
535  bool _clip_planes_enabled;
536  bool _color_scale_enabled;
537  LVecBase4 _current_color_scale;
538 
539  bool _has_material_force_color;
540  LColor _material_force_color;
541  LVecBase4 _light_color_scale;
542  bool _has_texture_alpha_scale;
543 
544  bool _tex_gen_modifies_mat;
545  bool _tex_gen_point_sprite;
546  int _last_max_stage_index;
547 
548  bool _needs_reset;
549  bool _is_valid;
550  bool _closing_gsg;
551  bool _active;
552  bool _incomplete_render;
553  bool _effective_incomplete_render;
554  PT(Loader) _loader;
555 
556  PT(PreparedGraphicsObjects) _prepared_objects;
557 
558  bool _is_hardware;
559  bool _prefers_triangle_strips;
560  int _max_vertices_per_array;
561  int _max_vertices_per_primitive;
562 
563  int _max_texture_stages;
564  int _max_texture_dimension;
565  int _max_3d_texture_dimension;
566  int _max_2d_texture_array_layers; //on the z axis
567  int _max_cube_map_dimension;
568  int _max_buffer_texture_size;
569 
570  bool _supports_texture_combine;
571  bool _supports_texture_saved_result;
572  bool _supports_texture_dot3;
573 
574  bool _supports_3d_texture;
575  bool _supports_2d_texture_array;
576  bool _supports_cube_map;
577  bool _supports_buffer_texture;
578  bool _supports_cube_map_array;
579  bool _supports_tex_non_pow2;
580  bool _supports_texture_srgb;
581 
582  bool _supports_compressed_texture;
583  BitMask32 _compressed_texture_formats;
584 
585  int _max_lights;
586  int _max_clip_planes;
587 
588  int _max_vertex_transforms;
589  int _max_vertex_transform_indices;
590 
591  bool _supports_occlusion_query;
592  PT(OcclusionQueryContext) _current_occlusion_query;
593 
594  bool _supports_timer_query;
595 #ifdef DO_PSTATS
596  int _pstats_gpu_thread;
597  bool _timer_queries_active;
598  PStatFrameData _pstats_gpu_data;
599 
600  int _last_query_frame;
601  int _last_num_queried;
602  // double _timer_delta;
603  typedef pdeque<PT(TimerQueryContext)> TimerQueryQueue;
604  TimerQueryQueue _pending_timer_queries;
605 #endif
606 
607  bool _copy_texture_inverted;
608  bool _supports_multisample;
609  bool _supports_generate_mipmap;
610  bool _supports_depth_texture;
611  bool _supports_depth_stencil;
612  bool _supports_luminance_texture;
613  bool _supports_shadow_filter;
614  bool _supports_sampler_objects;
615  bool _supports_basic_shaders;
616  bool _supports_geometry_shaders;
617  bool _supports_tessellation_shaders;
618  bool _supports_compute_shaders;
619  bool _supports_glsl;
620  bool _supports_hlsl;
621  bool _supports_framebuffer_multisample;
622  bool _supports_framebuffer_blit;
623 
624  bool _supports_stencil;
625  bool _supports_stencil_wrap;
626  bool _supports_two_sided_stencil;
627  bool _supports_geometry_instancing;
628  bool _supports_indirect_draw;
629 
630  int _max_color_targets;
631  bool _supports_dual_source_blending;
632 
633  int _supported_geom_rendering;
634  bool _color_scale_via_lighting;
635  bool _alpha_scale_via_texture;
636  bool _runtime_color_scale;
637 
638  int _stereo_buffer_mask;
639 
640  ShaderModel _auto_detect_shader_model;
641  ShaderModel _shader_model;
642 
643  static PT(TextureStage) _alpha_scale_texture_stage;
644 
645  Shader::ShaderCaps _shader_caps;
646 
647  PN_stdfloat _gamma;
648  Texture::QualityLevel _texture_quality_override;
649 
650  PT(ShaderGenerator) _shader_generator;
651 
652 #ifndef NDEBUG
653  PT(Texture) _flash_texture;
654 #endif
655 
656 public:
657  // Statistics
658  static PStatCollector _vertex_buffer_switch_pcollector;
659  static PStatCollector _index_buffer_switch_pcollector;
660  static PStatCollector _shader_buffer_switch_pcollector;
661  static PStatCollector _load_vertex_buffer_pcollector;
662  static PStatCollector _load_index_buffer_pcollector;
663  static PStatCollector _load_shader_buffer_pcollector;
664  static PStatCollector _create_vertex_buffer_pcollector;
665  static PStatCollector _create_index_buffer_pcollector;
666  static PStatCollector _create_shader_buffer_pcollector;
667  static PStatCollector _load_texture_pcollector;
668  static PStatCollector _data_transferred_pcollector;
669  static PStatCollector _texmgrmem_total_pcollector;
670  static PStatCollector _texmgrmem_resident_pcollector;
671  static PStatCollector _primitive_batches_pcollector;
672  static PStatCollector _primitive_batches_tristrip_pcollector;
673  static PStatCollector _primitive_batches_trifan_pcollector;
674  static PStatCollector _primitive_batches_tri_pcollector;
675  static PStatCollector _primitive_batches_patch_pcollector;
676  static PStatCollector _primitive_batches_other_pcollector;
677  static PStatCollector _vertices_tristrip_pcollector;
678  static PStatCollector _vertices_trifan_pcollector;
679  static PStatCollector _vertices_tri_pcollector;
680  static PStatCollector _vertices_patch_pcollector;
681  static PStatCollector _vertices_other_pcollector;
682  static PStatCollector _vertices_indexed_tristrip_pcollector;
683  static PStatCollector _state_pcollector;
684  static PStatCollector _transform_state_pcollector;
685  static PStatCollector _texture_state_pcollector;
686  static PStatCollector _draw_primitive_pcollector;
687  static PStatCollector _draw_set_state_pcollector;
688  static PStatCollector _flush_pcollector;
689  static PStatCollector _compute_dispatch_pcollector;
690  static PStatCollector _wait_occlusion_pcollector;
691  static PStatCollector _wait_timer_pcollector;
692  static PStatCollector _timer_queries_pcollector;
693  static PStatCollector _command_latency_pcollector;
694 
695  static PStatCollector _prepare_pcollector;
696  static PStatCollector _prepare_texture_pcollector;
697  static PStatCollector _prepare_sampler_pcollector;
698  static PStatCollector _prepare_geom_pcollector;
699  static PStatCollector _prepare_shader_pcollector;
700  static PStatCollector _prepare_vertex_buffer_pcollector;
701  static PStatCollector _prepare_index_buffer_pcollector;
702  static PStatCollector _prepare_shader_buffer_pcollector;
703 
704  // A whole slew of collectors to measure the cost of individual state
705  // changes. These are disabled by default.
706  static PStatCollector _draw_set_state_transform_pcollector;
707  static PStatCollector _draw_set_state_alpha_test_pcollector;
708  static PStatCollector _draw_set_state_antialias_pcollector;
709  static PStatCollector _draw_set_state_clip_plane_pcollector;
710  static PStatCollector _draw_set_state_color_pcollector;
711  static PStatCollector _draw_set_state_cull_face_pcollector;
712  static PStatCollector _draw_set_state_depth_offset_pcollector;
713  static PStatCollector _draw_set_state_depth_test_pcollector;
714  static PStatCollector _draw_set_state_depth_write_pcollector;
715  static PStatCollector _draw_set_state_render_mode_pcollector;
716  static PStatCollector _draw_set_state_rescale_normal_pcollector;
717  static PStatCollector _draw_set_state_shade_model_pcollector;
718  static PStatCollector _draw_set_state_blending_pcollector;
719  static PStatCollector _draw_set_state_shader_pcollector;
720  static PStatCollector _draw_set_state_shader_parameters_pcollector;
721  static PStatCollector _draw_set_state_texture_pcollector;
722  static PStatCollector _draw_set_state_tex_matrix_pcollector;
723  static PStatCollector _draw_set_state_tex_gen_pcollector;
724  static PStatCollector _draw_set_state_material_pcollector;
725  static PStatCollector _draw_set_state_light_pcollector;
726  static PStatCollector _draw_set_state_stencil_pcollector;
727  static PStatCollector _draw_set_state_fog_pcollector;
728  static PStatCollector _draw_set_state_scissor_pcollector;
729 
730 private:
731  int _num_lights_enabled;
732  int _num_clip_planes_enabled;
733 
734  PT(GraphicsPipe) _pipe;
735  GraphicsEngine *_engine;
736  GraphicsThreadingModel _threading_model;
737 
738 public:
739  static TypeHandle get_class_type() {
740  return _type_handle;
741  }
742 
743 public:
744  static void init_type() {
745  GraphicsStateGuardianBase::init_type();
746  register_type(_type_handle, "GraphicsStateGuardian",
747  GraphicsStateGuardianBase::get_class_type());
748  }
749  virtual TypeHandle get_type() const {
750  return get_class_type();
751  }
752  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
753 
754 private:
755  static TypeHandle _type_handle;
756 
757  friend class GraphicsPipe;
758  friend class GraphicsWindow;
759  friend class GraphicsEngine;
760 };
761 
762 EXPCL_PANDA_DISPLAY std::ostream &operator << (std::ostream &out, GraphicsStateGuardian::ShaderModel sm);
763 
764 #include "graphicsStateGuardian.I"
765 
766 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A light shining from infinitely far away in a particular direction, like sunlight.
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
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.
This class represents a thread-safe handle to a promised future result of an asynchronous operation,...
Definition: asyncFuture.h:61
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion,...
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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
Definition: shader.h:49
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition: loader.h:42
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
This is our own Panda specialization on the default STL deque.
Definition: pdeque.h:36
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight class that represents a single element that may be timed and/or counted via stats.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Contains the raw timing and level data for a single frame.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
Definition: geom.h:54
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A light originating from a single point in space, and shining in a particular direction,...
Definition: spotlight.h:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for the various different classes that represent the result of a frame of render...
This represents the user's specification of how a particular frame is handled by the various threads.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a special class object that holds a handle to the sampler state object given by the graphics ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A derivative of Light and of Camera.
Definition: lightLensNode.h:33
This is a special class object that holds all the information returned by a particular GSG to indicat...
Encapsulates all the communication with a particular instance of a given rendering backend.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:57
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An abstract base class for GraphicsOutput, for all the usual reasons.
Returned from a GSG in response to begin_occlusion_query() .
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:32
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:35
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A light originating from a single point in space, and shining in all directions.
Definition: pointLight.h:25
This is the data for one array of a GeomVertexData structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.