Om
1.0.0
A universal framework for multimedia simulation
|
A class that emulates immediate-mode graphics rendering like older graphics APIs. More...
#include <omGraphicsImmediateRenderer.h>
Public Member Functions | |
ImmediateRenderer () | |
Create a new immediate-mode renderer with no valid context to render to. More... | |
ImmediateRenderer (GraphicsContext *newContext) | |
Create a new immediate-mode renderer which uses the specified graphics context. More... | |
virtual | ~ImmediateRenderer () |
Destroy this immediate renderer and release all associated resources. More... | |
virtual void | setContext (GraphicsContext *newContext) |
Change the graphics context that should be used to draw geometry. More... | |
void | synchronizeContext () |
Ensure that the context has the current rendering state for this immediate renderer. More... | |
Technique * | getTechnique () const |
Return the current technique for the renderer. More... | |
void | setTechnique (Technique *newTechnique) |
Replace the current technique for the renderer. More... | |
void | pushTechnique () |
Push the current technique onto the shader pass stack. The current technique is unchanged. More... | |
void | popTechnique () |
Remove the last technique from the technique stack and make it the current technique. More... | |
RenderMode & | getRenderMode () |
Return the render mode object for the current shader pass. More... | |
const RenderMode & | getRenderMode () const |
Return the render mode object for the current shader pass. More... | |
void | setRenderMode (const RenderMode &newRenderMode) const |
Set the render mode object for the current shader pass. More... | |
void | pushRenderMode () |
Push the current shader pass onto the shader pass stack. The current shader pass is unchanged. More... | |
void | popRenderMode () |
Remove the last render mode from the render mode stack and make the current shader pass use it. More... | |
const Viewport & | getViewport () const |
Return the current viewport for the renderer. More... | |
Size2D | getViewportSize () const |
Return the current viewport size in framebuffer pixels for the renderer. More... | |
void | setViewport (const Viewport &newViewport) |
Replace the current viewport for the renderer. More... | |
void | setViewport (const AABB2f &newViewport) |
Replace the current viewport for the renderer. More... | |
void | pushViewport () |
Push the current viewport onto the viewport stack. The current viewport is unchanged. More... | |
void | popViewport () |
Remove the last viewport from the viewport stack and make it the current viewport. More... | |
const ScissorTest & | getScissorTest () const |
Return the current scissor test for the renderer. More... | |
void | setScissorTest (const ScissorTest &newScissorTest) |
Replace the current scissor test for the renderer. More... | |
void | setScissorTest (const AABB2f &newScissorBounds, Bool enabled=true) |
Replace the current scissor test for the renderer. More... | |
void | pushScissorTest () |
Push the current scissor test onto the scissor test stack. The current scissor test is unchanged. More... | |
void | popScissorTest () |
Remove the last scissor test from the scissor test stack and make it the current one. More... | |
const Matrix4 & | getProjection () const |
Return the current projection matrix for the renderer. More... | |
void | setProjection (const Matrix4 &newProjection) |
Replace the current projection matrix for the renderer. More... | |
void | setProjection (const AABB2 &viewVolume) |
Replace the current projection matrix for the renderer with a 2D orthographic projection matrix. More... | |
void | setProjection (const AABB3 &viewVolume) |
Replace the current projection matrix for the renderer with a 3D orthographic projection matrix. More... | |
void | pushProjection () |
Push the current projection matrix onto the projection matrix stack. The current projection matrix is unchanged. More... | |
void | popProjection () |
Remove the last projection matrix from the projection matrix stack and make it the current projection matrix. More... | |
const Matrix4 & | getTransform () const |
Return the current transformation matrix for the renderer. More... | |
void | setTransform (const Transform2 &newTransform) |
Replace the current transformation for the renderer. More... | |
void | setTransform (const Transform3 &newTransform) |
Replace the current transformation for the renderer. More... | |
void | setTransform (const Matrix4 &newTransform) |
Replace the current transformation matrix for the renderer. More... | |
void | applyTransform (const Transform2 &newTransform) |
Multiply the current transformation matrix for the renderer by another transformation. More... | |
void | applyTransform (const Transform3 &newTransform) |
Multiply the current transformation matrix for the renderer by another transformation. More... | |
void | applyTransform (const Matrix4 &newTransform) |
Multiply the current transformation matrix for the renderer by another matrix. More... | |
void | pushTransform () |
Push the current transformation matrix onto the transformation matrix stack. The current transformation matrix is unchanged. More... | |
void | popTransform () |
Remove the last transformation matrix from the transformation matrix stack and make it the current transformation matrix. More... | |
Float | getLineWidth () const |
Return the width in pixels to use when rendering lines. More... | |
void | setLineWidth (Float newLineWidth) |
Set the width in pixels to use when rendering lines. More... | |
Float | getPointSize () const |
Return the size in pixels to use when rendering points. More... | |
void | setPointSize (Float newPointSize) |
Set the size in pixels to use when rendering points. More... | |
Bool | getConstant (const ConstantUsage &usage, AttributeValue &value) const |
Get the constant value with the specified usage in the output parameter. More... | |
template<typename T > | |
Bool | getConstant (const ConstantUsage &usage, T &value) const |
Get the constant value with the specified usage in the template output parameter. More... | |
Bool | setConstant (const ConstantUsage &usage, const AttributeValue &value) |
Set the value of the specified constant usage for this renderer. More... | |
template<typename T > | |
Bool | setConstant (const ConstantUsage &usage, const T &value) |
Set the value of the specified constant usage for this renderer. More... | |
void | clearConstants () |
Clear all constants that are currently set in this immediate renderer. More... | |
Texture * | getTexture (const TextureUsage &usage) const |
Return the texture for the specified texture usage. More... | |
Bool | setTexture (const TextureUsage &usage, Texture *texture) |
Set the texture for the specified texture usage for this renderer. More... | |
void | clearTextures () |
Clear all textures that are currently set in this immediate renderer. More... | |
virtual void | render () |
Draw all previously buffered geometry to the screen. More... | |
void | begin (const IndexedPrimitiveType &primitiveType) |
Start drawing the specified kind of primitive type. More... | |
void | vertex (const Vector2f &position) |
Submit a 2D vertex with the given position to the immediate renderer. More... | |
void | vertex (const Vector3f &position) |
Submit a 3D vertex with the given position to the immediate renderer. More... | |
void | vertex (const Vector4f &position) |
Submit a 4D vertex with the given position to the immediate renderer. More... | |
void | vertex (Float x, Float y) |
Submit a 2D vertex with the given position to the immediate renderer. More... | |
void | vertex (Float x, Float y, Float z) |
Submit a 3D vertex with the given position to the immediate renderer. More... | |
void | vertex (Float x, Float y, Float z, Float w) |
Submit a 4D vertex with the given position to the immediate renderer. More... | |
void | vertices (const Vector2f *v, Size numVertices) |
Submit the specified number of 2D vertices from an array of vertices. More... | |
void | vertices (const Vector3f *v, Size numVertices) |
Submit the specified number of 3D vertices from an array of vertices. More... | |
void | vertices (const Vector4f *v, Size numVertices) |
Submit the specified number of 4D vertices from an array of vertices. More... | |
void | normal (const Vector3f &normal) |
Set the current normal of the immediate renderer as a 3-component vector. More... | |
void | normal (Float nx, Float ny, Float nz) |
Set the current normal of the immediate renderer as a 3-component vector. More... | |
void | uv (const Vector2f &uv) |
Set the current texture coordinate of the immediate renderer as a 2-component UV coordinate. More... | |
void | uv (Float u, Float v) |
Set the current texture coordinate of the immediate renderer as a 2-component UV coordinate. More... | |
void | color (const Color3f &newColor) |
Set the current color of the immediate renderer as a 3-component RGB color. More... | |
void | color (const Color4f &newColor) |
Set the current color of the immediate renderer as a 4-component RGBA color. More... | |
void | color (Float r, Float g, Float b) |
Set the current color of the immediate renderer as a 3-component RGB color. More... | |
void | color (Float r, Float g, Float b, Float a) |
Set the current color of the immediate renderer as a 3-component RGB color. More... | |
Bool | sphere (const Sphere3f &aSphere) |
Synchronously draw a sphere in the current coordinate frame with the given radius and current color. More... | |
void | box (const AABB3f &bounds) |
Synchronously draw an axis-aligned box in the current coordinate frame with the current color. More... | |
void | boundingBox (const AABB3f &bounds) |
Synchronously draw an axis-aligned bounding box in the current coordinate frame with the current color. More... | |
Public Member Functions inherited from om::graphics::renderers::Renderer | |
virtual | ~Renderer () |
Destroy a renderer object. More... | |
GraphicsContext * | getContext () const |
Return a pointer to the graphics context that the renderer is using. More... | |
void | clearContext () |
Clear the previous context from this object. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from om::graphics::renderers::Renderer | |
Renderer () | |
Create a new graphics renderer that doesn't have an associated graphics context. More... | |
Renderer (GraphicsContext *newContext) | |
Create a new graphics renderer that uses the specified context for rendering. More... | |
Protected Attributes inherited from om::graphics::renderers::Renderer | |
GraphicsContext * | context |
A pointer to the graphics context this object is using. More... | |
A class that emulates immediate-mode graphics rendering like older graphics APIs.
An immediate renderer uses an internal OpenGL-like state machine build on top of modern graphics rendering techniques. This style of rendering can be useful for easily drawing debug information or quick prototyping. This renderer should not be used for performance-sensitive rendering.
om::graphics::renderers::ImmediateRenderer::ImmediateRenderer | ( | ) |
Create a new immediate-mode renderer with no valid context to render to.
om::graphics::renderers::ImmediateRenderer::ImmediateRenderer | ( | GraphicsContext * | newContext | ) |
Create a new immediate-mode renderer which uses the specified graphics context.
|
virtual |
Destroy this immediate renderer and release all associated resources.
|
virtual |
Change the graphics context that should be used to draw geometry.
This method resets any internal context-specific rendering state but keeps the previous drawing state (viewports, transformations, colors, normals, etc).
Reimplemented from om::graphics::renderers::Renderer.
void om::graphics::renderers::ImmediateRenderer::synchronizeContext | ( | ) |
Ensure that the context has the current rendering state for this immediate renderer.
This method should be called before doing any immediate-mode rendering so that the context is ensured to have the same state as what is stored locally as part of the immediate-mode renderer. This information consists of the viewport, scissor viewport, and render mode attributes.
|
inline |
Return the current technique for the renderer.
void om::graphics::renderers::ImmediateRenderer::setTechnique | ( | Technique * | newTechnique | ) |
Replace the current technique for the renderer.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::pushTechnique | ( | ) |
Push the current technique onto the shader pass stack. The current technique is unchanged.
Each call to pushTechnique() should be paired with a call to popTechnique(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popTechnique | ( | ) |
Remove the last technique from the technique stack and make it the current technique.
If there are no technique on the stack, the method sets the current technique to be the default technique.
|
inline |
Return the render mode object for the current shader pass.
|
inline |
Return the render mode object for the current shader pass.
|
inline |
Set the render mode object for the current shader pass.
void om::graphics::renderers::ImmediateRenderer::pushRenderMode | ( | ) |
Push the current shader pass onto the shader pass stack. The current shader pass is unchanged.
Each call to pushShaderPass() should be paired with a call to popShaderPass(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popRenderMode | ( | ) |
Remove the last render mode from the render mode stack and make the current shader pass use it.
If there are no render modes on the stack, the method sets the current shader pass's mode to be the default render mode.
|
inline |
Return the current viewport for the renderer.
|
inline |
Return the current viewport size in framebuffer pixels for the renderer.
void om::graphics::renderers::ImmediateRenderer::setViewport | ( | const Viewport & | newViewport | ) |
Replace the current viewport for the renderer.
This method changes the context's viewport if the context is valid and replaces the locally-stored current viewport regardless of whether or not the context is valid.
This method may cause previously buffered drawing commands to be flushed to the screen.
|
inline |
Replace the current viewport for the renderer.
This method changes the context's viewport if the context is valid and replaces the locally-stored current viewport regardless of whether or not the context is valid.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::pushViewport | ( | ) |
Push the current viewport onto the viewport stack. The current viewport is unchanged.
Each call to pushViewport() should be paired with a call to popViewport(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popViewport | ( | ) |
Remove the last viewport from the viewport stack and make it the current viewport.
If there are no viewports on the stack, the method has no effect.
|
inline |
Return the current scissor test for the renderer.
void om::graphics::renderers::ImmediateRenderer::setScissorTest | ( | const ScissorTest & | newScissorTest | ) |
Replace the current scissor test for the renderer.
This method changes the context's scissor test if the context is valid and replaces the locally-stored current scissor test regardless of whether or not the context is valid.
This method may cause previously buffered drawing commands to be flushed to the screen.
|
inline |
Replace the current scissor test for the renderer.
This method changes the context's scissor test if the context is valid and replaces the locally-stored current scissor test regardless of whether or not the context is valid.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::pushScissorTest | ( | ) |
Push the current scissor test onto the scissor test stack. The current scissor test is unchanged.
Each call to pushScissorTest() should be paired with a call to popScissorTest(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popScissorTest | ( | ) |
Remove the last scissor test from the scissor test stack and make it the current one.
If there are no scissor tests on the stack, the method has no effect.
|
inline |
Return the current projection matrix for the renderer.
void om::graphics::renderers::ImmediateRenderer::setProjection | ( | const Matrix4 & | newProjection | ) |
Replace the current projection matrix for the renderer.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::setProjection | ( | const AABB2 & | viewVolume | ) |
Replace the current projection matrix for the renderer with a 2D orthographic projection matrix.
The resulting projection views the specified volume with its view direction down the negative Z axis. The z near and far planes are set to be 1 and -1, respectively.
void om::graphics::renderers::ImmediateRenderer::setProjection | ( | const AABB3 & | viewVolume | ) |
Replace the current projection matrix for the renderer with a 3D orthographic projection matrix.
The resulting projection views the specified volume with its view direction down the negative Z axis.
void om::graphics::renderers::ImmediateRenderer::pushProjection | ( | ) |
Push the current projection matrix onto the projection matrix stack. The current projection matrix is unchanged.
Each call to pushProjection() should be paired with a call to popProjection(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popProjection | ( | ) |
Remove the last projection matrix from the projection matrix stack and make it the current projection matrix.
If there are no projection matrixs on the stack, the method has no effect.
|
inline |
Return the current transformation matrix for the renderer.
void om::graphics::renderers::ImmediateRenderer::setTransform | ( | const Transform2 & | newTransform | ) |
Replace the current transformation for the renderer.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::setTransform | ( | const Transform3 & | newTransform | ) |
Replace the current transformation for the renderer.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::setTransform | ( | const Matrix4 & | newTransform | ) |
Replace the current transformation matrix for the renderer.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::applyTransform | ( | const Transform2 & | newTransform | ) |
Multiply the current transformation matrix for the renderer by another transformation.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::applyTransform | ( | const Transform3 & | newTransform | ) |
Multiply the current transformation matrix for the renderer by another transformation.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::applyTransform | ( | const Matrix4 & | newTransform | ) |
Multiply the current transformation matrix for the renderer by another matrix.
This method may cause previously buffered drawing commands to be flushed to the screen.
void om::graphics::renderers::ImmediateRenderer::pushTransform | ( | ) |
Push the current transformation matrix onto the transformation matrix stack. The current transformation matrix is unchanged.
Each call to pushTransform() should be paired with a call to popTransform(), otherwise the stack will continue to grow and produce undesired behavior.
void om::graphics::renderers::ImmediateRenderer::popTransform | ( | ) |
Remove the last transformation matrix from the transformation matrix stack and make it the current transformation matrix.
If there are no transformation matrixs on the stack, the method has no effect.
Float om::graphics::renderers::ImmediateRenderer::getLineWidth | ( | ) | const |
Return the width in pixels to use when rendering lines.
void om::graphics::renderers::ImmediateRenderer::setLineWidth | ( | Float | newLineWidth | ) |
Set the width in pixels to use when rendering lines.
Float om::graphics::renderers::ImmediateRenderer::getPointSize | ( | ) | const |
Return the size in pixels to use when rendering points.
void om::graphics::renderers::ImmediateRenderer::setPointSize | ( | Float | newPointSize | ) |
Set the size in pixels to use when rendering points.
|
inline |
Get the constant value with the specified usage in the output parameter.
The method returns whether or not the constant value was able to be retrieved.
|
inline |
Get the constant value with the specified usage in the template output parameter.
The method returns whether or not the constant value was able to be retrieved.
|
inline |
Set the value of the specified constant usage for this renderer.
The method returns whether or not the constant value was able to be set.
|
inline |
Set the value of the specified constant usage for this renderer.
The method returns whether or not the constant value was able to be set.
|
inline |
Clear all constants that are currently set in this immediate renderer.
This method should be called whenever the renderer does not need the previously stored constants anymore in order to reduce the memory used.
|
inline |
Return the texture for the specified texture usage.
|
inline |
Set the texture for the specified texture usage for this renderer.
The method returns whether or not the texture was able to be set.
|
inline |
Clear all textures that are currently set in this immediate renderer.
This method should be called whenever the renderer does not need the previously stored textures anymore in order to reduce the memory used.
|
virtual |
Draw all previously buffered geometry to the screen.
As drawing commands are submitted, the renderer buffers them internally until the rendering state is changed, necessitating flushing the commands. This method should be called after all commands are submitted, in order to ensure that any previously buffered commands are completely drawn.
Reimplemented from om::graphics::renderers::Renderer.
void om::graphics::renderers::ImmediateRenderer::begin | ( | const IndexedPrimitiveType & | primitiveType | ) |
Start drawing the specified kind of primitive type.
All subsequent vertex submissions will be interpreted as a sequence of primitives of this type. For example, if IndexedPrimitiveType::TRIANGLES is used, every 3 vertices correspond to a single triangle that is to be drawn.
This method causes previously buffered drawing commands to be flushed to the screen as the rendering state is prepared for the new primitive type.
|
inline |
Submit a 2D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
2D vertex positions are padded out to 4 components with the Z and W components 0 and 1 when they are submitted.
|
inline |
Submit a 3D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
3D vertex positions are padded out to 4 components with the W component 1 when they are submitted.
void om::graphics::renderers::ImmediateRenderer::vertex | ( | const Vector4f & | position | ) |
Submit a 4D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
Submit a 2D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
2D vertex positions are padded out to 4 components with the Z and W components 0 and 1 when they are submitted.
Submit a 3D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
3D vertex positions are padded out to 4 components with the W component 1 when they are submitted.
|
inline |
Submit a 4D vertex with the given position to the immediate renderer.
This vertex uses the last values for vertex color, normal texture coordinate, etc.
Submit the specified number of 2D vertices from an array of vertices.
All vertices uses the last values for vertex color, normal texture coordinate, etc.
Submit the specified number of 3D vertices from an array of vertices.
All vertices uses the last values for vertex color, normal texture coordinate, etc.
Submit the specified number of 4D vertices from an array of vertices.
All vertices uses the last values for vertex color, normal texture coordinate, etc.
void om::graphics::renderers::ImmediateRenderer::normal | ( | const Vector3f & | normal | ) |
Set the current normal of the immediate renderer as a 3-component vector.
This value affects all subsequent draw calls until the method is called again.
Set the current normal of the immediate renderer as a 3-component vector.
This value affects all subsequent draw calls until the method is called again.
void om::graphics::renderers::ImmediateRenderer::uv | ( | const Vector2f & | uv | ) |
Set the current texture coordinate of the immediate renderer as a 2-component UV coordinate.
This value affects all subsequent draw calls until the method is called again.
Set the current texture coordinate of the immediate renderer as a 2-component UV coordinate.
This value affects all subsequent draw calls until the method is called again.
void om::graphics::renderers::ImmediateRenderer::color | ( | const Color3f & | newColor | ) |
Set the current color of the immediate renderer as a 3-component RGB color.
The color value is padded to 4 components with an alpha component of 1.
This color affects all subsequent draw calls until the method is called again.
void om::graphics::renderers::ImmediateRenderer::color | ( | const Color4f & | newColor | ) |
Set the current color of the immediate renderer as a 4-component RGBA color.
This color affects all subsequent draw calls until the method is called again.
Set the current color of the immediate renderer as a 3-component RGB color.
The color value is padded to 4 components with an alpha component of 1.
This color affects all subsequent draw calls until the method is called again.
|
inline |
Set the current color of the immediate renderer as a 3-component RGB color.
The color value is padded to 4 components with an alpha component of 1.
This color affects all subsequent draw calls until the method is called again.
Synchronously draw a sphere in the current coordinate frame with the given radius and current color.
void om::graphics::renderers::ImmediateRenderer::box | ( | const AABB3f & | bounds | ) |
Synchronously draw an axis-aligned box in the current coordinate frame with the current color.
The box is drawn with filled sides.
void om::graphics::renderers::ImmediateRenderer::boundingBox | ( | const AABB3f & | bounds | ) |
Synchronously draw an axis-aligned bounding box in the current coordinate frame with the current color.
The box is drawn with edges only.