17 #ifndef GRAPHICSSTATEGUARDIAN_H 18 #define GRAPHICSSTATEGUARDIAN_H 20 #include "pandabase.h" 22 #include "frameBufferProperties.h" 23 #include "preparedGraphicsObjects.h" 25 #include "graphicsStateGuardianBase.h" 26 #include "graphicsThreadingModel.h" 27 #include "graphicsPipe.h" 28 #include "sceneSetup.h" 29 #include "displayRegion.h" 31 #include "coordinateSystem.h" 33 #include "pStatCollector.h" 34 #include "transformState.h" 35 #include "renderState.h" 37 #include "planeNode.h" 38 #include "config_display.h" 39 #include "geomMunger.h" 40 #include "geomVertexData.h" 43 #include "shaderContext.h" 46 #include "occlusionQueryContext.h" 47 #include "timerQueryContext.h" 49 #include "shaderAttrib.h" 50 #include "texGenAttrib.h" 51 #include "textureAttrib.h" 52 #include "shaderGenerator.h" 88 INLINE
void release_all();
89 INLINE
int release_all_textures();
90 INLINE
int release_all_samplers();
91 INLINE
int release_all_geoms();
92 INLINE
int release_all_vertex_buffers();
93 INLINE
int release_all_index_buffers();
95 INLINE
void set_active(
bool active);
96 INLINE
bool is_active()
const;
97 INLINE
bool is_valid()
const;
98 INLINE
bool needs_reset()
const;
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;
104 INLINE
void set_loader(
Loader *loader);
105 INLINE
Loader *get_loader()
const;
114 INLINE
bool is_hardware()
const;
115 virtual INLINE
bool prefers_triangle_strips()
const;
116 virtual INLINE
int get_max_vertices_per_array()
const;
117 virtual INLINE
int get_max_vertices_per_primitive()
const;
119 INLINE
int get_max_texture_stages()
const;
120 virtual INLINE
int get_max_texture_dimension()
const;
121 INLINE
int get_max_3d_texture_dimension()
const;
122 INLINE
int get_max_2d_texture_array_layers()
const;
123 INLINE
int get_max_cube_map_dimension()
const;
125 INLINE
bool get_supports_texture_combine()
const;
126 INLINE
bool get_supports_texture_saved_result()
const;
127 INLINE
bool get_supports_texture_dot3()
const;
129 INLINE
bool get_supports_3d_texture()
const;
130 INLINE
bool get_supports_2d_texture_array()
const;
131 INLINE
bool get_supports_cube_map()
const;
132 INLINE
bool get_supports_tex_non_pow2()
const;
133 INLINE
bool get_supports_texture_srgb()
const;
135 INLINE
bool get_supports_compressed_texture()
const;
136 virtual INLINE
bool get_supports_compressed_texture_format(
int compression_mode)
const;
138 INLINE
int get_max_lights()
const;
139 INLINE
int get_max_clip_planes()
const;
141 INLINE
int get_max_vertex_transforms()
const;
142 INLINE
int get_max_vertex_transform_indices()
const;
144 INLINE
bool get_copy_texture_inverted()
const;
145 virtual bool get_supports_multisample()
const;
146 INLINE
bool get_supports_generate_mipmap()
const;
147 INLINE
bool get_supports_depth_texture()
const;
148 INLINE
bool get_supports_depth_stencil()
const;
149 INLINE
bool get_supports_shadow_filter()
const;
150 INLINE
bool get_supports_sampler_objects()
const;
151 INLINE
bool get_supports_basic_shaders()
const;
152 INLINE
bool get_supports_geometry_shaders()
const;
153 INLINE
bool get_supports_tessellation_shaders()
const;
154 INLINE
bool get_supports_compute_shaders()
const;
155 INLINE
bool get_supports_glsl()
const;
156 INLINE
bool get_supports_stencil()
const;
157 INLINE
bool get_supports_two_sided_stencil()
const;
158 INLINE
bool get_supports_geometry_instancing()
const;
160 INLINE
bool get_supports_occlusion_query()
const;
161 INLINE
bool get_supports_timer_query()
const;
162 INLINE
bool get_timer_queries_active()
const;
164 INLINE
int get_max_color_targets()
const;
165 INLINE
int get_maximum_simultaneous_render_targets()
const;
167 INLINE
int get_shader_model()
const;
168 INLINE
void set_shader_model(
int shader_model);
170 virtual int get_supported_geom_rendering()
const;
171 virtual bool get_supports_cg_profile(
const string &name)
const;
173 INLINE
bool get_color_scale_via_lighting()
const;
174 INLINE
bool get_alpha_scale_via_texture()
const;
175 INLINE
bool get_alpha_scale_via_texture(
const TextureAttrib *tex_attrib)
const;
176 INLINE
bool get_runtime_color_scale()
const;
178 INLINE
static TextureStage *get_alpha_scale_texture_stage();
180 void set_coordinate_system(CoordinateSystem cs);
181 INLINE CoordinateSystem get_coordinate_system()
const;
182 virtual CoordinateSystem get_internal_coordinate_system()
const;
186 virtual bool set_gamma(PN_stdfloat gamma);
187 PN_stdfloat get_gamma(PN_stdfloat gamma);
188 virtual void restore_gamma();
190 INLINE
void set_texture_quality_override(Texture::QualityLevel quality_level);
191 INLINE Texture::QualityLevel get_texture_quality_override()
const;
193 EXTENSION(PyObject *get_prepared_textures()
const);
194 typedef bool TextureCallback(
TextureContext *tc,
void *callback_arg);
195 void traverse_prepared_textures(TextureCallback *func,
void *callback_arg);
198 void set_flash_texture(
Texture *tex);
199 void clear_flash_texture();
200 Texture *get_flash_texture()
const;
204 virtual bool has_extension(
const string &extension)
const;
206 virtual string get_driver_vendor();
207 virtual string get_driver_renderer();
208 virtual string get_driver_version();
209 virtual int get_driver_version_major();
210 virtual int get_driver_version_minor();
211 virtual int get_driver_shader_version_major();
212 virtual int get_driver_shader_version_minor();
221 virtual bool extract_texture_data(
Texture *tex);
238 virtual void begin_occlusion_query();
243 virtual void dispatch_compute(
int size_x,
int size_y,
int size_z);
250 virtual void set_state_and_transform(
const RenderState *state,
251 const TransformState *transform);
253 virtual PN_stdfloat compute_distance_to(
const LPoint3 &point)
const;
258 const LMatrix4 *fetch_specified_part(Shader::ShaderMatInput input, InternalName *name,
263 virtual void clear_before_callback();
264 virtual void clear_state_and_transform();
268 virtual CPT(TransformState) calc_projection_mat(
const Lens *lens);
269 virtual bool prepare_lens();
271 virtual bool begin_frame(
Thread *current_thread);
273 virtual bool begin_scene();
274 virtual void end_scene();
276 virtual void end_frame(
Thread *current_thread);
278 void flush_timer_queries();
282 virtual bool depth_offset_decals();
285 virtual CPT(
RenderState) begin_decal_base_second();
286 virtual void finish_decal();
306 virtual void end_draw_primitives();
308 INLINE
bool reset_if_new();
309 INLINE
void mark_new();
310 virtual void reset();
312 INLINE CPT(TransformState) get_external_transform()
const;
313 INLINE CPT(TransformState) get_internal_transform()
const;
317 INLINE
const DisplayRegion *get_current_display_region()
const;
318 INLINE Lens::StereoChannel get_current_stereo_channel()
const;
319 INLINE
int get_current_tex_view_offset()
const;
320 INLINE
const Lens *get_current_lens()
const;
322 virtual CPT(TransformState) get_cs_transform_for(CoordinateSystem cs)
const;
323 virtual CPT(TransformState) get_cs_transform()
const;
324 INLINE CPT(TransformState) get_inv_cs_transform()
const;
326 void do_issue_clip_plane();
327 void do_issue_color();
328 void do_issue_color_scale();
329 virtual void do_issue_light();
331 virtual bool framebuffer_copy_to_texture
333 virtual bool framebuffer_copy_to_ram
343 static void create_gamma_table (PN_stdfloat gamma,
unsigned short *red_table,
unsigned short *green_table,
unsigned short *blue_table);
348 static void init_frame_pstats();
352 virtual void reissue_transforms();
354 virtual void enable_lighting(
bool enable);
355 virtual void set_ambient_light(
const LColor &
color);
356 virtual void enable_light(
int light_id,
bool enable);
357 virtual void begin_bind_lights();
358 virtual void end_bind_lights();
360 virtual void enable_clip_planes(
bool enable);
361 virtual void enable_clip_plane(
int plane_id,
bool enable);
362 virtual void begin_bind_clip_planes();
363 virtual void bind_clip_plane(
const NodePath &plane,
int plane_id);
364 virtual void end_bind_clip_planes();
366 void determine_target_texture();
368 virtual void free_pointers();
369 virtual void close_gsg();
370 void panic_deactivate();
372 void determine_light_color_scale();
403 CPT(TransformState) _internal_transform;
424 unsigned int _color_write_mask;
427 Lens::StereoChannel _current_stereo_channel;
428 int _current_tex_view_offset;
429 CPT(
Lens) _current_lens;
430 CPT(TransformState) _projection_mat;
431 CPT(TransformState) _projection_mat_inv;
434 CoordinateSystem _coordinate_system;
435 CoordinateSystem _internal_coordinate_system;
436 CPT(TransformState) _cs_transform;
437 CPT(TransformState) _inv_cs_transform;
439 LColor _scene_graph_color;
440 bool _has_scene_graph_color;
441 bool _transform_stale;
442 bool _color_blend_involves_color_scale;
443 bool _texture_involves_color_scale;
444 bool _vertex_colors_enabled;
445 bool _lighting_enabled;
446 bool _clip_planes_enabled;
447 bool _color_scale_enabled;
450 bool _has_material_force_color;
451 LColor _material_force_color;
453 bool _has_texture_alpha_scale;
455 bool _tex_gen_modifies_mat;
456 bool _tex_gen_point_sprite;
457 int _last_max_stage_index;
463 bool _incomplete_render;
464 bool _effective_incomplete_render;
470 bool _prefers_triangle_strips;
471 int _max_vertices_per_array;
472 int _max_vertices_per_primitive;
474 int _max_texture_stages;
475 int _max_texture_dimension;
476 int _max_3d_texture_dimension;
477 int _max_2d_texture_array_layers;
478 int _max_cube_map_dimension;
480 bool _supports_texture_combine;
481 bool _supports_texture_saved_result;
482 bool _supports_texture_dot3;
484 bool _supports_3d_texture;
485 bool _supports_2d_texture_array;
486 bool _supports_cube_map;
487 bool _supports_tex_non_pow2;
488 bool _supports_texture_srgb;
490 bool _supports_compressed_texture;
494 int _max_clip_planes;
496 int _max_vertex_transforms;
497 int _max_vertex_transform_indices;
499 bool _supports_occlusion_query;
502 bool _supports_timer_query;
504 int _pstats_gpu_thread;
505 bool _timer_queries_active;
508 int _last_query_frame;
509 int _last_num_queried;
512 TimerQueryQueue _pending_timer_queries;
515 bool _copy_texture_inverted;
516 bool _supports_multisample;
517 bool _supports_generate_mipmap;
518 bool _supports_depth_texture;
519 bool _supports_depth_stencil;
520 bool _supports_shadow_filter;
521 bool _supports_sampler_objects;
522 bool _supports_basic_shaders;
523 bool _supports_geometry_shaders;
524 bool _supports_tessellation_shaders;
525 bool _supports_compute_shaders;
527 bool _supports_framebuffer_multisample;
528 bool _supports_framebuffer_blit;
530 bool _supports_stencil;
531 bool _supports_stencil_wrap;
532 bool _supports_two_sided_stencil;
533 bool _supports_geometry_instancing;
535 int _max_color_targets;
537 int _supported_geom_rendering;
538 bool _color_scale_via_lighting;
539 bool _alpha_scale_via_texture;
540 bool _runtime_color_scale;
542 int _stereo_buffer_mask;
544 int _auto_detect_shader_model;
552 Texture::QualityLevel _texture_quality_override;
621 static PStatCollector _draw_set_state_shader_parameters_pcollector;
632 int _num_lights_enabled;
633 int _num_clip_planes_enabled;
645 static void init_type() {
646 GraphicsStateGuardianBase::init_type();
647 register_type(_type_handle,
"GraphicsStateGuardian",
648 GraphicsStateGuardianBase::get_class_type());
651 return get_class_type();
653 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
663 #include "graphicsStateGuardian.I" 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 special class object that holds all the information returned by a particular GSG to indicat...
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion, both of which are conceptually rectangular regions into which drawing commands may be issued.
A base class for any number of different kinds of lenses, linear and otherwise.
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
This is a special class object that holds all the information returned by a particular GSG to indicat...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
This is a special class object that holds all the information returned by a particular GSG to indicat...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
A table of objects that are saved within the graphics context for reference by handle later...
This is our own Panda specialization on the default STL deque.
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.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
A lightweight class that represents a single element that may be timed and/or counted via stats...
This is a 4-by-4 transform matrix.
Contains the raw timing and level data for a single frame.
An object to create GraphicsOutputs that share a particular 3-D API.
The ShaderGenerator is a device that effectively replaces the classic fixed function pipeline with a ...
A container for geometry primitives.
A light originating from a single point in space, and shining in a particular direction, with a cone-shaped falloff.
This represents the user's specification of how a particular frame is handled by the various threads...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Represents a set of settings that indicate how a texture is sampled.
This is the base class for all three-component vectors and points.
This is a special class object that holds a handle to the sampler state object given by the graphics ...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
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.
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.
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.
This object holds the camera position, etc., and other general setup information for rendering a part...
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.
Computes texture coordinates for geometry automatically based on vertex position and/or normal...
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer, etc.) of a drawing region.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A light originating from a single point in space, and shining in all directions.
This is the data for one array of a GeomVertexData structure.