GLCanvas Class Reference

GLCanvas implements Gfx::Canvas using OpenGL. More...

#include <gfx/glcanvas.h>

Inheritance diagram for GLCanvas:

Inheritance graph
[legend]
Collaboration diagram for GLCanvas:

Collaboration graph
[legend]

List of all members.

Public Types

enum  VertexStyle {
  POINTS = 1, LINES = 2, LINE_STRIP = 3, LINE_LOOP = 4,
  TRIANGLES = 5, TRIANGLE_STRIP = 6, TRIANGLE_FAN = 7, QUADS = 8,
  QUAD_STRIP = 9, POLYGON = 10
}
 Symbolic tags for the vertex-series specified by the begin*() functions.
typedef void(Canvas::* Manip )(const char *)
 Function-pointer type for Canvas state-change operations.
typedef void(Canvas::* Unmanip )()
 Function-pointer type for Canvas state-change operations.

Public Member Functions

void makeCurrent ()
void drawBufferFront () throw ()
void drawBufferBack () throw ()
virtual geom::vec3< double > screenFromWorld3 (const geom::vec3< double > &world_pos) const
 Convert a point from world coordinates to screen coordinates.
virtual geom::vec3< double > worldFromScreen3 (const geom::vec3< double > &screen_pos) const
 Convert a point from screen coordinates to world coordinates.
virtual geom::rect< int > getScreenViewport () const
 Get the viewport rect in screen coordinates.
virtual bool isRgba () const
 Query whether the drawable is in RGBA mode.
virtual bool isColorIndex () const
 Query whether the drawable is in color-index mode.
virtual bool isDoubleBuffered () const
 Query whether the drawable is double-buffered.
virtual unsigned int bitsPerPixel () const
 Query the number of bytes per pixel.
virtual void throwIfError (const char *where, const rutz::file_pos &pos) const
 Throw an exception if there has been an error.
virtual void pushAttribs (const char *comment="")
 Save the entire current attrib set.
virtual void popAttribs ()
 Restore the previously saved entire attrib set.
virtual void drawOnFrontBuffer ()
 Select the front buffer for future drawing operations.
virtual void drawOnBackBuffer ()
 Select the back buffer for future drawing operations.
virtual void setColor (const Gfx::RgbaColor &rgba)
 Set the current foreground/drawing color.
virtual void setClearColor (const Gfx::RgbaColor &rgba)
 Set the current background/clear color.
virtual void setColorIndex (unsigned int index)
 Set the current foreground/drawing color index.
virtual void setClearColorIndex (unsigned int index)
 Set the current background/clear color index.
virtual void swapForeBack ()
virtual void setPolygonFill (bool on)
virtual void setPointSize (double size)
 Set the radius of rendered points.
virtual void setLineWidth (double width)
 Set the current line width.
virtual void setLineStipple (unsigned short bit_pattern)
 Set the current line stipple pattern.
virtual void enableAntialiasing ()
 Turn on antialiasing if available.
virtual void viewport (int x, int y, int w, int h)
 Specify a viewport for the canvas.
virtual void orthographic (const geom::rect< double > &bounds, double zNear, double zFar)
 Specify an orthographic projection for the canvas.
virtual void perspective (double fovy, double aspect, double zNear, double zFar)
 Specify an perspective projection for the canvas.
virtual void pushMatrix (const char *comment="")
 Save the current transformation matrix.
virtual void popMatrix ()
 Restore the previously saved transformation matrix.
virtual void translate (const geom::vec3< double > &v)
 Translate the coordinate system by the given vector.
virtual void scale (const geom::vec3< double > &v)
 Scale/reflect the coordinate system by the given vector.
virtual void rotate (const geom::vec3< double > &v, double degrees)
 Rotate the coordinate system around the given vector.
virtual void transform (const geom::txform &tx)
 Apply a generic transformation to the coordinate system.
virtual void loadMatrix (const geom::txform &tx)
 Set the transformation matrix to the given transformation.
void rasterPos (const geom::vec3< double > &world_pos)
 Do a "safe" glRasterPos().
virtual void drawPixels (const media::bmap_data &data, const geom::vec3< double > &world_pos, const geom::vec2< double > &zoom)
 Draw pixmap data at the specified position.
virtual void drawBitmap (const media::bmap_data &data, const geom::vec3< double > &world_pos)
 Draw 1-bit bitmap data at the specified position.
virtual void grabPixels (const geom::rect< int > &bounds, media::bmap_data &data_out)
 Read pixel data from the screen rect bounds into data_out.
virtual void clearColorBuffer ()
 Clear the color buffer to the clear color.
virtual void clearColorBuffer (const geom::rect< int > &screen_rect)
 Clear a region of the color buffer to the clear color.
virtual void drawRect (const geom::rect< double > &rect)
 Draw a rectangle.
virtual void drawCircle (double inner_radius, double outer_radius, bool fill, unsigned int slices, unsigned int loops)
 Draw a circle.
virtual void drawCylinder (double base_radius, double top_radius, double height, int slices, int stacks, bool fill)
 Draw a cylinder.
virtual void drawSphere (double radius, int slices, int stacks, bool fill)
 Draw a sphere.
virtual void drawBezier4 (const geom::vec3< double > &p1, const geom::vec3< double > &p2, const geom::vec3< double > &p3, const geom::vec3< double > &p4, unsigned int subdivisions)
 Draw a Bezier curve with 4 control points.
virtual void drawBezierFill4 (const geom::vec3< double > &center, const geom::vec3< double > &p1, const geom::vec3< double > &p2, const geom::vec3< double > &p3, const geom::vec3< double > &p4, unsigned int subdivisions)
 Draw a filled Bezier curve with 4 control points.
virtual void beginPoints (const char *comment="")
 Start a series of points vertices.
virtual void beginLines (const char *comment="")
 Start a set of lines.
virtual void beginLineStrip (const char *comment="")
 Start a continuous strip of lines.
virtual void beginLineLoop (const char *comment="")
 Start a closed loop of lines.
virtual void beginTriangles (const char *comment="")
 Start a set of triangles.
virtual void beginTriangleStrip (const char *comment="")
 Start a continuous strip of triangles.
virtual void beginTriangleFan (const char *comment="")
 Start a fan of triangles with a common anchor point.
virtual void beginQuads (const char *comment="")
 Start a set of quadrilaterals.
virtual void beginQuadStrip (const char *comment="")
 Start a continous strip of quadrilaterals.
virtual void beginPolygon (const char *comment="")
 Start a convex polygon.
virtual void vertex2 (const geom::vec2< double > &v)
 Put a 2-D vertex (with z = 0) into the current vertex-series.
virtual void vertex3 (const geom::vec3< double > &v)
 Put a 3-D vertex into the current vertex-series.
virtual void end ()
 End the current vertex-series.
virtual void drawRasterText (const rutz::fstring &text, const GxRasterFont &font)
 Render text with the given raster font.
virtual void drawVectorText (const rutz::fstring &text, const GxVectorFont &font)
 Render text with the given vector font.
virtual void flushOutput ()
 Flush all pending drawing requests; swap buffers if double-buffering.
virtual void finishDrawing ()
 Wait (i.e., don't return) until all pending drawing requests are completed.
void newList (int i, bool do_execute)
 Start recording the display list given by i.
void endList ()
 Stop recording display list commands.
bool isList (int i)
 Check if the given index refers to a valid display list.
void callList (int i)
 Trigger the commands recorded in the given display list.
void light (int lightnum, const Gfx::RgbaColor *specular, const Gfx::RgbaColor *diffuse, const Gfx::RgbaColor *ambient, const geom::vec3< double > *position, const geom::vec3< double > *spotDirection, double attenuation, double spotExponent, double spotCutoff)
 Specify colors and positions associated with a light source.
void material (const Gfx::RgbaColor *specular, const Gfx::RgbaColor *diffuse, const Gfx::RgbaColor *ambient, const double *shininess)
 Specify colors and attributes for a material.
geom::vec2< double > screenFromWorld2 (const geom::vec2< double > &world_pos) const
 Convert a point from world coordinates to screen coordinates.
geom::rect< int > screenBoundsFromWorldRect (const geom::rect< double > &world_pos) const
 Convert a rect from screen coordinates to world coordinates.
void drawRect (const geom::rect< double > &rect, bool filled)
 Draw a rectangle, forcing whether it is filled or not.
virtual void drawBox (const geom::box< double > &box)
 Draw a cube.
virtual void drawNurbsCurve (const rutz::dynamic_block< float > &knots, const rutz::dynamic_block< geom::vec3< float > > &pts)
 Draw a NURBS curve.
void begin (VertexStyle s, const char *comment="")
 Start a series of vertices according to the given Vertex Style.
nub::uid id () const throw ()
rutz::fstring real_typename () const
 Returns the typename of the full object.
virtual rutz::fstring obj_typename () const
 Returns the (apparent) typename of the full object.
rutz::fstring unique_name () const
 Returns a short string describing the object by its typename and id.
void * operator new (size_t bytes)
void operator delete (void *space, size_t bytes)
void mark_as_volatile () throw ()
 Mark this object as a volatile (unshareable) object.
void incr_ref_count () const throw ()
 Increment the object's reference count.
void decr_ref_count () const throw ()
 Decrement the object's reference count.
void decr_ref_count_no_delete () const throw ()
 Decrement the object's reference count, but don't delete it.
bool is_shared () const throw ()
 Returns true if no external client has sole ownership of the object.
bool is_unshared () const throw ()
 Returns true if there is a sole external owner of the object.
bool is_not_shareable () const throw ()
ref_counts * get_counts () const throw ()
 Returns the object's reference count manager.
int dbg_ref_count () const throw ()
 FOR TEST/DEBUG ONLY! Returns the object's (strong) reference count.
int dbg_weak_ref_count () const throw ()
 FOR TEST/DEBUG ONLY! Returns the object's weak reference count.
void destroy ()

Static Public Member Functions

static GLCanvasmake (rutz::shared_ptr< GlxOpts > opts, rutz::shared_ptr< GlWindowInterface > glx)
 Factory function.
static nub::soft_ref< GLCanvasgetCurrent ()
static int genLists (int num)
 Create space for a consecutive sequence of num display lists.
static void deleteLists (int start, int num)
 Deallocate num display lists starting with the one given by start.

Protected Member Functions

 GLCanvas (rutz::shared_ptr< GlxOpts > opts, rutz::shared_ptr< GlWindowInterface > glx)
 Construct from windowsystem options and a windowsystem wrapper.

Classes

class  Impl


Detailed Description

GLCanvas implements Gfx::Canvas using OpenGL.

Definition at line 51 of file glcanvas.h.


Member Function Documentation

void GLCanvas::swapForeBack (  )  [virtual]

Swaps the foreground and background colors, in a way that is appropriate to color-index/RGBA modes.

Implements Gfx::Canvas.

Definition at line 474 of file glcanvas.cc.

References isRgba().

void GLCanvas::setPolygonFill ( bool  on  )  [virtual]

Control whether polygons will be filled (if true), or outlined (if false).

Implements Gfx::Canvas.

Definition at line 504 of file glcanvas.cc.

void GLCanvas::rasterPos ( const geom::vec3< double > &  world_pos  ) 

Do a "safe" glRasterPos().

If the given position does not fall in the screen viewport, then we use the "fake glBitmap()" hack to get a valid raster position outside the viewport.

Definition at line 675 of file glcanvas.cc.

References getScreenViewport(), screenFromWorld3(), worldFromScreen3(), geom::vec3< V >::x(), geom::vec3< V >::y(), and geom::vec3< V >::z().

Referenced by drawRasterText().

void GLCanvas::finishDrawing (  )  [virtual]

Wait (i.e., don't return) until all pending drawing requests are completed.

Default implementation is a no-op.

Reimplemented from Gfx::Canvas.

Definition at line 1167 of file glcanvas.cc.

int GLCanvas::genLists ( int  num  )  [static]

Create space for a consecutive sequence of num display lists.

The index of the first display list is returned.

Definition at line 1173 of file glcanvas.cc.

References SRC_POS.

Referenced by GxCache::draw().

void GLCanvas::newList ( int  i,
bool  do_execute 
)

Start recording the display list given by i.

Optionally execute the commands at the same time if do_execute is true.

Definition at line 1190 of file glcanvas.cc.

Referenced by GxCache::draw().

void Gfx::Canvas::drawNurbsCurve ( const rutz::dynamic_block< float > &  knots,
const rutz::dynamic_block< geom::vec3< float > > &  pts 
) [virtual, inherited]

Draw a NURBS curve.

The default implementation splits the NURBS curve into 4-pt Bezier curve components, and then draws those with drawBezier4().

Definition at line 195 of file canvas.cc.

References Gfx::Canvas::drawBezier4(), and rutz::dynamic_block< T >::size().

Referenced by Fish::grRender().

nub::uid nub::object::id (  )  const throw () [inherited]

Returns the unique id for this object. The unique id will always be strictly positive; zero is always an invalid unique id.

Definition at line 62 of file object.cc.

rutz::fstring nub::object::real_typename (  )  const [inherited]

Returns the typename of the full object.

The result is a demangled version of typeid(*this).name(), which should very closely resemble the way the object was declared in source code.

Definition at line 67 of file object.cc.

References rutz::demangled_name().

Referenced by nub::object::obj_typename().

rutz::fstring nub::object::obj_typename (  )  const [virtual, inherited]

Returns the (apparent) typename of the full object.

The default implementation just returns real_typename(). However, certain kinds of objects -- e.g., proxy objects -- might usefully choose to have obj_typename() return something besides the real_typename(), in order to masquerade as a different type of object.

Reimplemented in io::proxy< C >, io::const_proxy< C >, MtxObj, and TrialMemFuncEvent.

Definition at line 73 of file object.cc.

References nub::object::real_typename().

Referenced by io::legacy_reader::read_root(), and nub::object::unique_name().

void * nub::ref_counted::operator new ( size_t  bytes  )  [inherited]

Class-specific operator new; protected to ensure that clients use factory functions.

Definition at line 157 of file refcounted.cc.

void nub::ref_counted::operator delete ( void *  space,
size_t  bytes 
) [inherited]

Class-specific operator delete; private since deletion should only happen in ref_counted::decr_ref_count.

Definition at line 163 of file refcounted.cc.

void nub::ref_counted::incr_ref_count (  )  const throw () [inherited]

Increment the object's reference count.

This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 207 of file refcounted.cc.

References nub::ref_counts::acquire_strong().

Referenced by GxEmptyNode::make().

void nub::ref_counted::decr_ref_count (  )  const throw () [inherited]

Decrement the object's reference count.

If this causes the reference count to fall to zero or below, the pointee and the pointer will be destroyed by a call to 'delete this'. This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 212 of file refcounted.cc.

References nub::ref_counts::release_strong().

void nub::ref_counted::decr_ref_count_no_delete (  )  const throw () [inherited]

Decrement the object's reference count, but don't delete it.

Unlike decr_ref_count(), the object will NOT be delete'd if the reference count falls to zero. This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 221 of file refcounted.cc.

References nub::ref_counts::release_strong_no_delete().

bool nub::ref_counted::is_shared (  )  const throw () [inherited]

Returns true if no external client has sole ownership of the object.

This may occur if either (1) the reference count is greater than one, or (2) the object is_not_shareable(), meaning that the object itself is the only "owner".

Definition at line 226 of file refcounted.cc.

References rutz::mutex_atomic_int::atomic_get(), nub::ref_counted::is_not_shareable(), and nub::ref_counts::m_strong.

Referenced by nub::ref_counted::is_unshared().

bool nub::ref_counted::is_unshared (  )  const throw () [inherited]

Returns true if there is a sole external owner of the object.

This occurs if the reference count is one or less and the object is shareable.

Definition at line 236 of file refcounted.cc.

References nub::ref_counted::is_shared().

bool nub::ref_counted::is_not_shareable (  )  const throw () [inherited]

Returns true if the object is not shareable for any reason. This could be because its lifespan is volatile (such as objects representing on-screen windows that can be dismissed by the user). The default is for objects to be shareable; objects can declare themselves as unshareable by calling mark_as_volatile().

Definition at line 242 of file refcounted.cc.

References nub::ref_counts::m_volatile.

Referenced by nub::ref_counted::is_shared().


The documentation for this class was generated from the following files:

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:54:33 2008 by Doxygen version 1.5.5.