Panda3D
|
An interface to the TinyPanda software rendering code within this module. More...
#include "tinyGraphicsStateGuardian.h"
Classes | |
class | TexCoordData |
Public Member Functions | |
TinyGraphicsStateGuardian (GraphicsEngine *engine, GraphicsPipe *pipe, TinyGraphicsStateGuardian *share_with) | |
virtual bool | begin_draw_primitives (const GeomPipelineReader *geom_reader, const GeomMunger *munger, const GeomVertexDataPipelineReader *data_reader, bool force) |
Called before a sequence of draw_primitive() functions are called, this should prepare the vertex data for rendering. | |
virtual bool | begin_frame (Thread *current_thread) |
Called before each frame is rendered, to allow the GSG a chance to do any internal cleanup before beginning the frame. | |
virtual bool | begin_scene () |
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a "scene" (usually a particular DisplayRegion) within a frame. | |
virtual void | bind_light (Spotlight *light_obj, const NodePath &light, int light_id) |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties. | |
virtual void | bind_light (PointLight *light_obj, const NodePath &light, int light_id) |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties. | |
virtual void | bind_light (DirectionalLight *light_obj, const NodePath &light, int light_id) |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties. | |
virtual void | clear (DrawableRegion *clearable) |
Clears the framebuffer within the current DisplayRegion, according to the flags indicated by the given DrawableRegion object. | |
virtual void | close_gsg () |
This is called by the associated GraphicsWindow when close_window() is called. | |
virtual | CPT (TransformState) calc_projection_mat(const Lens *lens) |
virtual bool | depth_offset_decals () |
Returns true if this GSG can implement decals using a DepthOffsetAttrib, or false if that is unreliable and the three-step rendering process should be used instead. | |
virtual void | do_issue_light () |
This implementation of do_issue_light() assumes we have a limited number of hardware lights available. | |
virtual bool | draw_lines (const GeomPrimitivePipelineReader *reader, bool force) |
Draws a series of disconnected line segments. | |
virtual bool | draw_points (const GeomPrimitivePipelineReader *reader, bool force) |
Draws a series of disconnected points. | |
virtual bool | draw_triangles (const GeomPrimitivePipelineReader *reader, bool force) |
Draws a series of disconnected triangles. | |
virtual bool | draw_tristrips (const GeomPrimitivePipelineReader *reader, bool force) |
Draws a series of triangle strips. | |
virtual void | end_draw_primitives () |
Called after a sequence of draw_primitive() functions are called, this should do whatever cleanup is appropriate. | |
virtual void | end_frame (Thread *current_thread) |
Called after each frame is rendered, to allow the GSG a chance to do any internal cleanup after rendering the frame, and before the window flips. | |
virtual void | end_scene () |
Called between begin_frame() and end_frame() to mark the end of drawing commands for a "scene" (usually a particular DisplayRegion) within a frame. | |
virtual TypeHandle | force_init_type () |
virtual bool | framebuffer_copy_to_ram (Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) |
Copy the pixels within the indicated display region from the framebuffer into system memory, not texture memory. | |
virtual bool | framebuffer_copy_to_texture (Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) |
Copy the pixels within the indicated display region from the framebuffer into texture memory. | |
virtual void | free_pointers () |
Frees some memory that was explicitly allocated within the glgsg. | |
virtual TypeHandle | get_type () const |
virtual void | prepare_display_region (DisplayRegionPipelineReader *dr) |
Prepare a display region for rendering (set up scissor region and viewport) | |
virtual bool | prepare_lens () |
Makes the current lens (whichever lens was most recently specified with set_scene()) active, so that it will transform future rendered geometry. | |
virtual TextureContext * | prepare_texture (Texture *tex, int view) |
Creates whatever structures the GSG requires to represent the texture internally, and returns a newly-allocated TextureContext object with this data. | |
virtual | PT (GeomMunger) make_geom_munger(const RenderState *state |
virtual void | release_texture (TextureContext *tc) |
Frees the GL resources previously allocated for the texture. | |
virtual void | reset () |
Resets all internal state as if the gsg were newly created. | |
virtual void | set_state_and_transform (const RenderState *state, const TransformState *transform) |
Simultaneously resets the render state and the transform state. | |
virtual bool | update_texture (TextureContext *tc, bool force) |
Ensures that the current Texture data is refreshed onto the GSG. | |
bool | update_texture (TextureContext *tc, bool force, int stage_index) |
Ensures that the current Texture data is refreshed onto the GSG. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes | |
ZBuffer * | _current_frame_buffer |
virtual Thread * | current_thread |
An interface to the TinyPanda software rendering code within this module.
TinyPanda takes its name from TinyGL, the public-domain software renderer (see http://fabrice.bellard.free.fr/TinyGL/ ) from which this code originated. It has since been heavily modified, to integrate it closely with Panda, and to add additional features such as blending, filtering, and multitexturing.
Definition at line 43 of file tinyGraphicsStateGuardian.h.
bool TinyGraphicsStateGuardian::begin_draw_primitives | ( | const GeomPipelineReader * | geom_reader, |
const GeomMunger * | munger, | ||
const GeomVertexDataPipelineReader * | data_reader, | ||
bool | force | ||
) | [virtual] |
Called before a sequence of draw_primitive() functions are called, this should prepare the vertex data for rendering.
It returns true if the vertices are ok, false to abort this group of primitives.
Reimplemented from GraphicsStateGuardian.
Definition at line 517 of file tinyGraphicsStateGuardian.cxx.
References GraphicsStateGuardian::begin_draw_primitives(), ColorWriteAttrib::get_channels(), ColorBlendAttrib::get_color(), GeomVertexReader::get_data3(), GeomVertexReader::get_data4(), ShadeModelAttrib::get_mode(), DepthTestAttrib::get_mode(), AlphaTestAttrib::get_mode(), ColorBlendAttrib::get_mode(), TransparencyAttrib::get_mode(), DepthWriteAttrib::get_mode(), TexGenAttrib::get_mode(), ColorBlendAttrib::get_operand_a(), ColorBlendAttrib::get_operand_b(), AlphaTestAttrib::get_reference_alpha(), TextureStage::get_texcoord_name(), GeomVertexReader::has_column(), and GeomVertexReader::set_row_unsafe().
bool TinyGraphicsStateGuardian::begin_frame | ( | Thread * | current_thread | ) | [virtual] |
Called before each frame is rendered, to allow the GSG a chance to do any internal cleanup before beginning the frame.
The return value is true if successful (in which case the frame will be drawn and end_frame() will be called later), or false if unsuccessful (in which case nothing will be drawn and end_frame() will not be called).
Reimplemented from GraphicsStateGuardian.
Definition at line 380 of file tinyGraphicsStateGuardian.cxx.
References GraphicsStateGuardian::begin_frame().
bool TinyGraphicsStateGuardian::begin_scene | ( | ) | [virtual] |
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a "scene" (usually a particular DisplayRegion) within a frame.
All 3-D drawing commands, except the clear operation, must be enclosed within begin_scene() .. end_scene().
The return value is true if successful (in which case the scene will be drawn and end_scene() will be called later), or false if unsuccessful (in which case nothing will be drawn and end_scene() will not be called).
Reimplemented from GraphicsStateGuardian.
Definition at line 422 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::bind_light | ( | PointLight * | light_obj, |
const NodePath & | light, | ||
int | light_id | ||
) | [virtual] |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties.
Reimplemented from GraphicsStateGuardian.
Definition at line 1840 of file tinyGraphicsStateGuardian.cxx.
References PointLight::get_attenuation(), PointLight::get_point(), PointLight::get_specular_color(), and NodePath::get_transform().
void TinyGraphicsStateGuardian::bind_light | ( | DirectionalLight * | light_obj, |
const NodePath & | light, | ||
int | light_id | ||
) | [virtual] |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties.
Reimplemented from GraphicsStateGuardian.
Definition at line 1895 of file tinyGraphicsStateGuardian.cxx.
References DirectionalLight::get_direction(), DirectionalLight::get_specular_color(), NodePath::get_transform(), and LVecBase3f::normalize().
void TinyGraphicsStateGuardian::bind_light | ( | Spotlight * | light_obj, |
const NodePath & | light, | ||
int | light_id | ||
) | [virtual] |
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties.
Reimplemented from GraphicsStateGuardian.
Definition at line 1957 of file tinyGraphicsStateGuardian.cxx.
References Spotlight::get_attenuation(), Spotlight::get_exponent(), Lens::get_hfov(), LensNode::get_lens(), Lens::get_nodal_point(), Spotlight::get_specular_color(), NodePath::get_transform(), Lens::get_view_vector(), and LVecBase3f::normalize().
void TinyGraphicsStateGuardian::clear | ( | DrawableRegion * | clearable | ) | [virtual] |
Clears the framebuffer within the current DisplayRegion, according to the flags indicated by the given DrawableRegion object.
This does not set the DisplayRegion first. You should call prepare_display_region() to specify the region you wish the clear operation to apply to.
Reimplemented from GraphicsStateGuardian.
Definition at line 221 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::close_gsg | ( | ) | [virtual] |
This is called by the associated GraphicsWindow when close_window() is called.
It should null out the _win pointer and possibly free any open resources associated with the GSG.
Reimplemented from GraphicsStateGuardian.
Definition at line 175 of file tinyGraphicsStateGuardian.cxx.
bool TinyGraphicsStateGuardian::depth_offset_decals | ( | ) | [virtual] |
Returns true if this GSG can implement decals using a DepthOffsetAttrib, or false if that is unreliable and the three-step rendering process should be used instead.
Reimplemented from GraphicsStateGuardian.
Definition at line 193 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::do_issue_light | ( | ) | [virtual] |
This implementation of do_issue_light() assumes we have a limited number of hardware lights available.
This function assigns each light to a different hardware light id, trying to keep each light associated with the same id where possible, but reusing id's when necessary. When it is no longer possible to reuse existing id's (e.g. all id's are in use), the next sequential id is assigned (if available).
It will call apply_light() each time a light is assigned to a particular id for the first time in a given frame, and it will subsequently call enable_light() to enable or disable each light as the frame is rendered, as well as enable_lighting() to enable or disable overall lighting.
Reimplemented from GraphicsStateGuardian.
Definition at line 1765 of file tinyGraphicsStateGuardian.cxx.
References PandaNode::as_light(), NodePath::is_empty(), and NodePath::node().
Referenced by set_state_and_transform().
bool TinyGraphicsStateGuardian::draw_lines | ( | const GeomPrimitivePipelineReader * | reader, |
bool | force | ||
) | [virtual] |
Draws a series of disconnected line segments.
Reimplemented from GraphicsStateGuardian.
Definition at line 1172 of file tinyGraphicsStateGuardian.cxx.
bool TinyGraphicsStateGuardian::draw_points | ( | const GeomPrimitivePipelineReader * | reader, |
bool | force | ||
) | [virtual] |
Draws a series of disconnected points.
Reimplemented from GraphicsStateGuardian.
Definition at line 1249 of file tinyGraphicsStateGuardian.cxx.
bool TinyGraphicsStateGuardian::draw_triangles | ( | const GeomPrimitivePipelineReader * | reader, |
bool | force | ||
) | [virtual] |
Draws a series of disconnected triangles.
Reimplemented from GraphicsStateGuardian.
Definition at line 952 of file tinyGraphicsStateGuardian.cxx.
bool TinyGraphicsStateGuardian::draw_tristrips | ( | const GeomPrimitivePipelineReader * | reader, |
bool | force | ||
) | [virtual] |
Draws a series of triangle strips.
Reimplemented from GraphicsStateGuardian.
Definition at line 1034 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::end_draw_primitives | ( | ) | [virtual] |
Called after a sequence of draw_primitive() functions are called, this should do whatever cleanup is appropriate.
Reimplemented from GraphicsStateGuardian.
Definition at line 1324 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::end_frame | ( | Thread * | current_thread | ) | [virtual] |
Called after each frame is rendered, to allow the GSG a chance to do any internal cleanup after rendering the frame, and before the window flips.
Reimplemented from GraphicsStateGuardian.
Definition at line 469 of file tinyGraphicsStateGuardian.cxx.
void TinyGraphicsStateGuardian::end_scene | ( | ) | [virtual] |
Called between begin_frame() and end_frame() to mark the end of drawing commands for a "scene" (usually a particular DisplayRegion) within a frame.
All 3-D drawing commands, except the clear operation, must be enclosed within begin_scene() .. end_scene().
Reimplemented from GraphicsStateGuardian.
Definition at line 436 of file tinyGraphicsStateGuardian.cxx.
bool TinyGraphicsStateGuardian::framebuffer_copy_to_ram | ( | Texture * | tex, |
int | z, | ||
const DisplayRegion * | dr, | ||
const RenderBuffer & | rb | ||
) | [virtual] |
Copy the pixels within the indicated display region from the framebuffer into system memory, not texture memory.
Returns true on success, false on failure.
This completely redefines the ram image of the indicated texture.
Reimplemented from GraphicsStateGuardian.
Definition at line 1404 of file tinyGraphicsStateGuardian.cxx.
References Texture::get_component_type(), Texture::get_expected_ram_page_size(), Texture::get_format(), Texture::get_ram_image_size(), DisplayRegion::get_region_pixels_i(), Texture::get_texture_type(), Texture::get_x_size(), Texture::get_y_size(), Texture::get_z_size(), Texture::modify_ram_image(), and Texture::setup_texture().
bool TinyGraphicsStateGuardian::framebuffer_copy_to_texture | ( | Texture * | tex, |
int | z, | ||
const DisplayRegion * | dr, | ||
const RenderBuffer & | rb | ||
) | [virtual] |
Copy the pixels within the indicated display region from the framebuffer into texture memory.
If z > -1, it is the cube map index into which to copy.
Reimplemented from GraphicsStateGuardian.
Definition at line 1353 of file tinyGraphicsStateGuardian.cxx.
References AdaptiveLruPage::enqueue_lru(), Texture::get_border_color(), GraphicsStateGuardian::get_prepared_objects(), DisplayRegion::get_region_pixels_i(), DisplayRegion::get_tex_view_offset(), Texture::get_x_size(), Texture::get_y_size(), TextureContext::mark_loaded(), Texture::prepare_now(), Texture::setup_2d_texture(), and TextureContext::update_data_size_bytes().
void TinyGraphicsStateGuardian::free_pointers | ( | ) | [virtual] |
Frees some memory that was explicitly allocated within the glgsg.
Reimplemented from GraphicsStateGuardian.
Definition at line 153 of file tinyGraphicsStateGuardian.cxx.
Referenced by reset().
void TinyGraphicsStateGuardian::prepare_display_region | ( | DisplayRegionPipelineReader * | dr | ) | [virtual] |
Prepare a display region for rendering (set up scissor region and viewport)
Reimplemented from GraphicsStateGuardian.
Definition at line 265 of file tinyGraphicsStateGuardian.cxx.
References DisplayRegionPipelineReader::get_region_pixels_i().
bool TinyGraphicsStateGuardian::prepare_lens | ( | ) | [virtual] |
Makes the current lens (whichever lens was most recently specified with set_scene()) active, so that it will transform future rendered geometry.
Normally this is only called from the draw process, and usually it is called by set_scene().
The return value is true if the lens is acceptable, false if it is not.
Reimplemented from GraphicsStateGuardian.
Definition at line 361 of file tinyGraphicsStateGuardian.cxx.
TextureContext * TinyGraphicsStateGuardian::prepare_texture | ( | Texture * | tex, |
int | view | ||
) | [virtual] |
Creates whatever structures the GSG requires to represent the texture internally, and returns a newly-allocated TextureContext object with this data.
It is the responsibility of the calling function to later call release_texture() with this same pointer (which will also delete the pointer).
This function should not be called directly to prepare a texture. Instead, call Texture::prepare().
Implements GraphicsStateGuardianBase.
Definition at line 1612 of file tinyGraphicsStateGuardian.cxx.
References Texture::get_texture_type().
void TinyGraphicsStateGuardian::release_texture | ( | TextureContext * | tc | ) | [virtual] |
Frees the GL resources previously allocated for the texture.
This function should never be called directly; instead, call Texture::release() (or simply let the Texture destruct).
Reimplemented from GraphicsStateGuardian.
Definition at line 1737 of file tinyGraphicsStateGuardian.cxx.
References AdaptiveLruPage::dequeue_lru().
void TinyGraphicsStateGuardian::reset | ( | ) | [virtual] |
Resets all internal state as if the gsg were newly created.
Reimplemented from GraphicsStateGuardian.
Definition at line 92 of file tinyGraphicsStateGuardian.cxx.
References GraphicsStateGuardianBase::add_gsg(), BitMask< WType, nbits >::clear_bit(), and free_pointers().
void TinyGraphicsStateGuardian::set_state_and_transform | ( | const RenderState * | target, |
const TransformState * | transform | ||
) | [virtual] |
Simultaneously resets the render state and the transform state.
This transform specified is the "internal" net transform, already converted into the GSG's internal coordinate space by composing it to get_cs_transform(). (Previously, this used to be the "external" net transform, with the assumption that that GSG would convert it internally, but that is no longer the case.)
Special case: if (state==NULL), then the target state is already stored in _target.
Reimplemented from GraphicsStateGuardian.
Definition at line 1491 of file tinyGraphicsStateGuardian.cxx.
References GraphicsStateGuardian::determine_target_texture(), GraphicsStateGuardian::do_issue_color(), do_issue_light(), BitMask< WType, nbits >::get_bit(), and BitMask< WType, nbits >::set_bit().
bool TinyGraphicsStateGuardian::update_texture | ( | TextureContext * | tc, |
bool | force | ||
) | [virtual] |
Ensures that the current Texture data is refreshed onto the GSG.
This means updating the texture properties and/or re-uploading the texture image, if necessary. This should only be called within the draw thread.
If force is true, this function will not return until the texture has been fully uploaded. If force is false, the function may choose to upload a simple version of the texture instead, if the texture is not fully resident (and if get_incomplete_render() is true).
Reimplemented from GraphicsStateGuardian.
Definition at line 1661 of file tinyGraphicsStateGuardian.cxx.
References AdaptiveLruPage::enqueue_lru(), TextureContext::get_texture(), and TextureContext::was_image_modified().
Referenced by update_texture().
bool TinyGraphicsStateGuardian::update_texture | ( | TextureContext * | tc, |
bool | force, | ||
int | stage_index | ||
) |
Ensures that the current Texture data is refreshed onto the GSG.
This means updating the texture properties and/or re-uploading the texture image, if necessary. This should only be called within the draw thread.
If force is true, this function will not return until the texture has been fully uploaded. If force is false, the function may choose to upload a simple version of the texture instead, if the texture is not fully resident (and if get_incomplete_render() is true).
Definition at line 1699 of file tinyGraphicsStateGuardian.cxx.
References update_texture().