Cortex  10.0.0-a4
Public Member Functions | Protected Member Functions | List of all members
IECoreGL::Primitive Class Referenceabstract

#include <Primitive.h>

+ Inheritance diagram for IECoreGL::Primitive:

Public Member Functions

 IE_CORE_DECLARERUNTIMETYPEDEXTENSION (IECoreGL::Primitive, PrimitiveTypeId, Renderable)
 
virtual void addPrimitiveVariable (const std::string &name, const IECore::PrimitiveVariable &primVar)=0
 
Imath::Box3f bound () const override=0
 Returns the bounding box for the primitive.
 
void render (State *currentState) const override
 
Lower level rendering methods

These methods are used to implement the higher level render() method - they may also be called directly to implement custom rendering.

This method returns a Shader::Setup binding the primitive to a shader for rendering in a particular state. It may be used in conjunction with renderInstances() to provide finer grained control over rendering. All vertex attributes are mapped to shader parameters prefixed with "vertex" so for instance "P" will be mapped to "vertexP". Uniform attributes are mapped directly to shader uniforms with no prefix. This naming convention corresponds to the inputs defined by the default source defined in the Shader class, and should be adopted when writing custom shaders.

Most classes will not need to override this method - reasons for overriding would be to substitute in custom geometry or vertex shaders and/or to bind in attributes not already specified with addUniformAttribute() or addVertexAttribute().

Todo:
We need to rethink this mechanism. The problem is that we've ended up using this method for two things - firstly to get a ShaderSetup where all the primitive variables are bound (good), and secondly we've abused it to actually change the shader in PointsPrimitive and CurvePrimitive. Asking for a setup for one shader and getting back a setup for another doesn't make a great deal of sense. There are several competing sources of source code for shaders :
  • The user-provided source coming through Renderer::shader().
  • The vertex and geometry shaders that PointsPrimitive and CurvesPrimitive need to insert.
  • The constant fragment shader that Primitive needs to insert to do wireframe shading etc.
  • The ID fragment shader needed for the Selector.

We should redesign our API so that we first resolve these requirements to generate a shader, and then use shaderSetup() just to apply primitive variables to it.

virtual const Shader::SetupshaderSetup (const Shader *shader, State *state) const
 
void addPrimitiveVariablesToShaderSetup (Shader::Setup *shaderSetup, const std::string &vertexPrefix="vertex", GLuint vertexDivisor=0) const
 
virtual void render (const State *currentState, IECore::TypeId style) const
 
virtual void renderInstances (size_t numInstances=1) const =0
 
- Public Member Functions inherited from IECoreGL::Renderable
 IE_CORE_DECLARERUNTIMETYPEDEXTENSION (IECoreGL::Renderable, RenderableTypeId, IECore::RunTimeTyped)
 
- Public Member Functions inherited from IECore::RunTimeTyped
 IE_CORE_DECLAREMEMBERPTR (RunTimeTyped)
 
virtual TypeId typeId () const
 
virtual const char * typeName () const
 
virtual bool isInstanceOf (TypeId typeId) const
 
virtual bool isInstanceOf (const char *typeName) const
 
- Public Member Functions inherited from IECore::RefCounted
 IE_CORE_DECLAREMEMBERPTR (RefCounted)
 
void addRef () const
 Add a reference to the current object.
 
void removeRef () const
 Remove a reference from the current object.
 
RefCount refCount () const
 Returns the current reference count.
 

Protected Member Functions

void addUniformAttribute (const std::string &name, IECore::ConstDataPtr data)
 Called by derived classes to register a uniform attribute. There are no type or length checks on this call.
 
void addVertexAttribute (const std::string &name, IECore::ConstDataPtr data)
 Called by derived classes to register a vertex attribute. There are no type or length checks on this call.
 
bool depthSortRequested (const State *state) const
 

StateComponents

The following StateComponent classes have an effect only on Primitive objects.

typedef TypedStateComponent< bool, PrimitiveBoundTypeId > DrawBound
 
typedef TypedStateComponent< bool, PrimitiveWireframeTypeId > DrawWireframe
 
typedef TypedStateComponent< float, PrimitiveWireframeWidthTypeId > WireframeWidth
 
typedef TypedStateComponent< bool, PrimitiveSolidTypeId > DrawSolid
 
typedef TypedStateComponent< bool, PrimitiveOutlineTypeId > DrawOutline
 
typedef TypedStateComponent< float, PrimitiveOutlineWidthTypeId > OutlineWidth
 
typedef TypedStateComponent< bool, PrimitivePointsTypeId > DrawPoints
 
typedef TypedStateComponent< float, PrimitivePointWidthTypeId > PointWidth
 
typedef TypedStateComponent< bool, PrimitiveSelectableTypeId > Selectable
 
typedef TypedStateComponent< bool, PrimitiveTransparencySortStateComponentTypeId > TransparencySort
 Used to trigger sorting of the components of a primitive when the TransparentShadingStateComponent has a value of true.
 
 IE_CORE_DECLAREPTR (DrawBound)
 
 IE_CORE_DECLAREPTR (DrawWireframe)
 
 IE_CORE_DECLAREPTR (WireframeWidth)
 
 IE_CORE_DECLAREPTR (DrawSolid)
 
 IE_CORE_DECLAREPTR (DrawOutline)
 
 IE_CORE_DECLAREPTR (OutlineWidth)
 
 IE_CORE_DECLAREPTR (DrawPoints)
 
 IE_CORE_DECLAREPTR (PointWidth)
 
 IE_CORE_DECLAREPTR (Selectable)
 
 IE_CORE_DECLAREPTR (TransparencySort)
 

Additional Inherited Members

- Public Types inherited from IECore::RunTimeTyped
typedef RefCounted BaseClass
 A typedef for the class this class derives from. All RunTimeTyped classes define this typedef.
 
- Public Types inherited from IECore::RefCounted
typedef size_t RefCount
 
- Static Public Member Functions inherited from IECore::RunTimeTyped
static TypeId staticTypeId ()
 Returns the TypeId for this class, without needing an instance.
 
static const char * staticTypeName ()
 Returns the type name for this class, without needing an instance.
 
static TypeId baseTypeId ()
 
static const char * baseTypeName ()
 
static bool inheritsFrom (TypeId typeId)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (const char *typeName)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (TypeId type, TypeId baseType)
 Returns true if type inherits from baseType.
 
static bool inheritsFrom (const char *typeName, const char *baseTypeName)
 Returns true if typeName inherits from baseTypeName.
 
static TypeId baseTypeId (TypeId typeId)
 Returns the base type of the given type, or InvalidTypeId if no such base exists.
 
static const std::vector< TypeId > & baseTypeIds (TypeId typeId)
 
static const std::set< TypeId > & derivedTypeIds (TypeId typeId)
 
static TypeId typeIdFromTypeName (const char *typeName)
 
static const char * typeNameFromTypeId (TypeId typeId)
 
static void registerType (TypeId derivedTypeId, const char *derivedTypeName, TypeId baseTypeId)
 Allows external modules to register their own type ids.
 
- Protected Types inherited from IECore::RunTimeTyped
typedef std::map< TypeId, TypeIdBaseTypeRegistryMap
 
typedef std::map< TypeId, std::vector< TypeId > > BaseTypesRegistryMap
 
typedef std::map< TypeId, std::set< TypeId > > DerivedTypesRegistryMap
 
typedef tbb::spin_rw_mutex Mutex
 
typedef std::map< TypeId, std::string > TypeIdsToTypeNamesMap
 
typedef std::map< std::string, TypeIdTypeNamesToTypeIdsMap
 
- Static Protected Member Functions inherited from IECore::RunTimeTyped
static BaseTypeRegistryMap & baseTypeRegistry ()
 
static DerivedTypesRegistryMap & derivedTypesRegistry ()
 
static BaseTypesRegistryMap & completeBaseTypesRegistry ()
 
static DerivedTypesRegistryMap & completeDerivedTypesRegistry ()
 
static void derivedTypeIdsWalk (TypeId typeId, std::set< TypeId > &)
 
static TypeIdsToTypeNamesMap & typeIdsToTypeNames ()
 
static TypeNamesToTypeIdsMap & typeNamesToTypeIds ()
 
- Static Protected Attributes inherited from IECore::RunTimeTyped
static Mutex g_baseTypeIdsMutex
 
static Mutex g_derivedTypeIdsMutex
 

Detailed Description

The Primitive class represents geometric objects that can be rendered in OpenGL. Primitives may be rendered in a variety of styles defined by State objects, or just rendered as raw geometry in the current OpenGL state.

Member Function Documentation

virtual void IECoreGL::Primitive::addPrimitiveVariable ( const std::string &  name,
const IECore::PrimitiveVariable primVar 
)
pure virtual

Adds a primitive variable to this primitive. Derived classes should implement any filtering or conversions that are necessary and then call addVertexAttribute() or addUniformAttribute(). The default implementation calls addUniformAttribute() for uniform primitive variables and addVertexAttribute() for all others.

Implemented in IECoreGL::MeshPrimitive.

void IECoreGL::Primitive::addPrimitiveVariablesToShaderSetup ( Shader::Setup shaderSetup,
const std::string &  vertexPrefix = "vertex",
GLuint  vertexDivisor = 0 
) const

Adds the primitive variables held by this Primitive to the specified Shader::Setup. Vertex attributes will be prefixed as specified, and for each vertex attribute a boolean uniform parameter called "${prefix}${attributeName}Active" will also be added so the shader can determine whether or not the values for that input are useful.

bool IECoreGL::Primitive::depthSortRequested ( const State *  state) const
protected

Convenience function for use in render() implementations. Returns true if TransparentShadingStateComponent is true and PrimitiveTransparencySortStateComponent is true.

void IECoreGL::Primitive::render ( State *  currentState) const
overridevirtual

High level rendering function which renders in the styles represented by currentState, allowing representations such as wireframe over shaded etc to be achieved with a single call. The currentState must be complete and already have been bound. Finer grained control over rendering can be achieved by using the shaderSetup() and renderInstances() methods - in fact those methods are used to implement this one.

Implements IECoreGL::Renderable.

virtual void IECoreGL::Primitive::render ( const State *  currentState,
IECore::TypeId  style 
) const
virtual

Renders the primitive using the specified state and with a particular style. The style is specified using the TypeId of the StateComponent representing that style (e.g. PrimitiveWireframeTypeId is passed for wireframe rendering).

The default implementation calls renderInstances() but derived classes may override it to modify their drawing based on the state. A Shader::Setup created for this primitive must be bound before calling this method.

virtual void IECoreGL::Primitive::renderInstances ( size_t  numInstances = 1) const
pure virtual

Renders a number of instances of the primitive by issuing a single call to glDrawElementsInstanced() or glDrawArraysInstanced(). A Shader::Setup created for this primitive must be bound before calling this method.

Implemented in IECoreGL::MeshPrimitive.


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