3ds Max C++ API Reference
IPrimitiveRenderer Class Referenceabstract

This class is used to draw simple primitives, markers, text with given material and transformations. More...

#include <IPrimitiveRenderer.h>

+ Inheritance diagram for IPrimitiveRenderer:

Public Member Functions

virtual const Matrix44GetWorldMatrix () const =0
 This method gets current row-major world transform matrix. More...
 
virtual void SetWorldMatrix (const Matrix44 &worldMatrix)=0
 This method sets current row-major world transform matrix for example, world matrix with translation should be: | 1 0 0 0 | | 0 1 0 0 | | 0 0 1 0 | | x y z 1 |. More...
 
virtual const Matrix44GetViewMatrix () const =0
 This method gets current row-major view transform matrix. More...
 
virtual void SetViewMatrix (const Matrix44 &viewMatrix)=0
 This method sets current row-major view transform matrix pseudo view matrix should like this: zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) More...
 
virtual const Matrix44GetProjectionMatrix () const =0
 This method gets current row-major projection transform matrix. More...
 
virtual void SetProjectionMatrix (const Matrix44 &projMatrix)=0
 This method sets current row-major projection transform matrix typical perspective project matrix should like this: | 2*zNear/width 0 0 0 | | 0 2*zNear/height 0 0 | | 0 0 zFar/(zFar-zNear) 1 | | 0 0 zNear*zFar/(zNear-zFar) 0 |. More...
 
virtual Rect GetViewportRect ()=0
 This method gets current viewport rectangle. More...
 
virtual Point2 GetDepthRange ()=0
 This method gets current depth range. More...
 
virtual void SetScreenSpace (const Rect &r, const Point2 &depth)=0
 This method sets current viewport rectangle and depth range. More...
 
virtual void Clear (const BufferClearFlag flags, const AColor &color, const float z, const int stencil)=0
 This method clears screen. More...
 
virtual void Clear (const IPoint2 &upperleft, const IPoint2 &bottomright, const BufferClearFlag flags, const AColor &color, const float z, const int stencil)=0
 This method clears sub-region of screen. More...
 
virtual void DrawIndexedPrimitiveUP (PrimitiveType primitiveType, const SimpleVertexStream &vertices, int primitiveCount, const int *indices, int indexCount)=0
 This method draws indexed primitives to screen, warning : primitive restart is not supported, you will need several calls to handle this. More...
 
virtual void DrawPrimitiveUP (PrimitiveType primitiveType, const SimpleVertexStream &vertices, int primitiveCount)=0
 This method draws primitives to screen. More...
 
virtual void DrawPrimitive (MaxSDK::Graphics::PrimitiveType primitiveType, int vertexStart, int primitiveCount)=0
 This method draws primitives based on the current vertex and index buffers. More...
 
virtual void DrawPrimitiveInstanced (MaxSDK::Graphics::PrimitiveType primitiveType, int vertexStart, int primitiveCount, int instanceCount)=0
 This method draws multiple primitives instance from vertex buffer and index buffer. More...
 
virtual void DrawRenderItem (const DisplayCallbackContext &displayContext, const RenderItemHandle &hRenderItem)=0
 Draw a given render item. More...
 
virtual void DrawScreenQuad (float z=0.0f)=0
 This method draws a quad covering the entire current target set. More...
 
virtual void DrawText (const Point3 &xyz, const MCHAR *s)=0
 This method draws a string at given world position. More...
 
virtual void DrawText (const IPoint2 &xy, const MCHAR *s)=0
 This method draws a string at given screen position (upper left is the origin) More...
 
virtual bool BeginMarker ()=0
 This method should be called before AddMarkers. More...
 
virtual bool AddMarkers (MarkerType type, const Point3 *xyz, size_t count, const Color &color=DefaultMarkerColor)=0
 This allows drawing batches of markers at a time. More...
 
virtual bool AddScreenSpaceMarkers (MarkerType type, const Point3 *xyz, size_t count, const Color &color=DefaultMarkerColor)=0
 This allows drawing batches of screen-space markers at a time. More...
 
virtual void EndMarker ()=0
 Ends the marker drawing sequence. More...
 
virtual bool SetMaterial (const BaseMaterialHandle &material)=0
 This method sets current material used by DrawPrimitive and DrawIndexedPrimitive. More...
 
virtual BaseMaterialHandleGetMaterial ()=0
 This method gets current material. More...
 
virtual void SetVertexBuffer (size_t count, const VertexBufferHandle *pBuffers)=0
 This method sets vertex buffers used by DrawPrimitive. More...
 
virtual void SetIndexBuffer (const IndexBufferHandle &pIndexBuffer)=0
 This method sets index buffer used by DrawPrimitive. More...
 
virtual void SetStreamFormat (const StreamFormatHandle &format)=0
 This method sets vertex format of vertex buffer. More...
 
virtual IRenderStateManagerGetRenderStates ()=0
 This method retrieves current render states object. More...
 
virtual IVirtualDeviceGetVirtualDevice ()=0
 This method retrieves current virtual device object. More...
 

Static Public Attributes

static GraphicsDriverAPI Color DefaultMarkerColor
 

Protected Member Functions

virtual ~IPrimitiveRenderer ()
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

This class is used to draw simple primitives, markers, text with given material and transformations.

Description
The class provides various ways to draw objects. Many functions are self contained and handle much of the code for you by using SimpleVertexStream, whilst others give you complete control over how the primitive is drawn. For example DrawPrimitive() allows the developer to create vertex and index buffers and define the actual vertex format to be used by providing a StreamFormatHandle which provides formating information for vertex data like Position, UVs and Normals.
Remarks
This class is running in graphic driver's thread. So sharing data between max thread and driver thread should be designed carefully ensuring thread safety. Users can get an instance of IPrimitiveRenderer in IDisplayCallback::Display().
See also
IDisplayCallback IVertexBuffer IIndexBuffer

Constructor & Destructor Documentation

◆ ~IPrimitiveRenderer()

virtual ~IPrimitiveRenderer ( )
inlineprotectedvirtual
101 {}

Member Function Documentation

◆ GetWorldMatrix()

virtual const Matrix44& GetWorldMatrix ( ) const
pure virtual

This method gets current row-major world transform matrix.

Returns
current world transform matrix

◆ SetWorldMatrix()

virtual void SetWorldMatrix ( const Matrix44 worldMatrix)
pure virtual

This method sets current row-major world transform matrix for example, world matrix with translation should be: | 1 0 0 0 | | 0 1 0 0 | | 0 0 1 0 | | x y z 1 |.

Parameters
[in]worldMatrixthe new world transform matrix

◆ GetViewMatrix()

virtual const Matrix44& GetViewMatrix ( ) const
pure virtual

This method gets current row-major view transform matrix.

Returns
current view transform matrix

◆ SetViewMatrix()

virtual void SetViewMatrix ( const Matrix44 viewMatrix)
pure virtual

This method sets current row-major view transform matrix pseudo view matrix should like this: zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis)

| xaxis.x yaxis.x zaxis.x 0 | | xaxis.y yaxis.y zaxis.y 0 | | xaxis.z yaxis.z zaxis.z 0 | | -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1 |

Parameters
[in]viewMatrixthe new view transform matrix

◆ GetProjectionMatrix()

virtual const Matrix44& GetProjectionMatrix ( ) const
pure virtual

This method gets current row-major projection transform matrix.

Returns
current 4x4 projection matrix

◆ SetProjectionMatrix()

virtual void SetProjectionMatrix ( const Matrix44 projMatrix)
pure virtual

This method sets current row-major projection transform matrix typical perspective project matrix should like this: | 2*zNear/width 0 0 0 | | 0 2*zNear/height 0 0 | | 0 0 zFar/(zFar-zNear) 1 | | 0 0 zNear*zFar/(zNear-zFar) 0 |.

Parameters
[in]projMatrixprojection matrix.

◆ GetViewportRect()

virtual Rect GetViewportRect ( )
pure virtual

This method gets current viewport rectangle.

Returns
current viewport

◆ GetDepthRange()

virtual Point2 GetDepthRange ( )
pure virtual

This method gets current depth range.

Returns
current depth range

◆ SetScreenSpace()

virtual void SetScreenSpace ( const Rect r,
const Point2 depth 
)
pure virtual

This method sets current viewport rectangle and depth range.

Parameters
[in]rviewport area
[in]depthviewport depth range, x is near plane(default 0), y is far plane(default 1)

◆ Clear() [1/2]

virtual void Clear ( const BufferClearFlag  flags,
const AColor color,
const float  z,
const int  stencil 
)
pure virtual

This method clears screen.

Parameters
[in]flagsthe element to clear (Target | Stencil | ZBuffer)
[in]colorthe Target's clear color
[in]zthe value of depth buffer after clear
[in]stencilthe stencil value after clear

◆ Clear() [2/2]

virtual void Clear ( const IPoint2 upperleft,
const IPoint2 bottomright,
const BufferClearFlag  flags,
const AColor color,
const float  z,
const int  stencil 
)
pure virtual

This method clears sub-region of screen.

Parameters
[in]upperleftupper left of clear rect
[in]bottomrightbottom right of clear rect
[in]flagsthe element to clear (Target | Stencil | ZBuffer)
[in]colorthe Target's clear color
[in]zthe value of depth buffer after clear
[in]stencilthe stencil value after clear

◆ DrawIndexedPrimitiveUP()

virtual void DrawIndexedPrimitiveUP ( PrimitiveType  primitiveType,
const SimpleVertexStream vertices,
int  primitiveCount,
const int indices,
int  indexCount 
)
pure virtual

This method draws indexed primitives to screen, warning : primitive restart is not supported, you will need several calls to handle this.

Parameters
[in]primitiveTypetype of primitive (line, triangle)
[in]verticesthe primitive data pointer. In system memory.
[in]primitiveCountthe number of primitives.
[in]indicesthe vertices index array A index array stores a lot of integers. Which indicates how the primitive been constructed. For example, a triangle list index "0, 2, 5" means vertex v0, v2 and v5 consist one triangle. A line strip index "0, 3, 1" means vertex v0, v3, v1 consist two lines: one is v0-v3, the other is v3-v1.
[in]indexCountsize of the index buffer

◆ DrawPrimitiveUP()

virtual void DrawPrimitiveUP ( PrimitiveType  primitiveType,
const SimpleVertexStream vertices,
int  primitiveCount 
)
pure virtual

This method draws primitives to screen.

Parameters
[in]primitiveTypetype of primitive (point, line, triangle)
[in]verticesthe primitive data pointer. In system memory.
[in]primitiveCountthe number of primitives.

◆ DrawPrimitive()

virtual void DrawPrimitive ( MaxSDK::Graphics::PrimitiveType  primitiveType,
int  vertexStart,
int  primitiveCount 
)
pure virtual

This method draws primitives based on the current vertex and index buffers.

See also
SetVertexBuffer SetIndexBuffer SetStreamFormat
Parameters
[in]primitiveTypetype of primitive (point, line, triangle)
[in]vertexStartthe 1st primitives vertex position in vertex buffer
[in]primitiveCountthe number of primitives.

◆ DrawPrimitiveInstanced()

virtual void DrawPrimitiveInstanced ( MaxSDK::Graphics::PrimitiveType  primitiveType,
int  vertexStart,
int  primitiveCount,
int  instanceCount 
)
pure virtual

This method draws multiple primitives instance from vertex buffer and index buffer.

The instance data should be saved in one of the vertex streams. For example, the layout of transform instance stream should be:

first instance: float4, float4, float4, float4 //Four rows of transform matrix
second instance: float4, float4, float4, float4 //Four rows of transform matrix
etc.

When drawing the primitives, each instance's matrix will apply to the primitive. So you can draw multiple instances in one call.

See also
SetVertexBuffer SetIndexBuffer SetStreamFormat
Parameters
[in]primitiveTypetype of primitive (point, line, triangle)
[in]vertexStartthe 1st primitives vertex position in vertex buffer
[in]primitiveCountthe number of primitives.
[in]instanceCountthe number of instances in the stream

◆ DrawRenderItem()

virtual void DrawRenderItem ( const DisplayCallbackContext displayContext,
const RenderItemHandle hRenderItem 
)
pure virtual

Draw a given render item.

Parameters
[in]displayContextthe current display context.
[in]hRenderItemthe render item to be draw.

◆ DrawScreenQuad()

virtual void DrawScreenQuad ( float  z = 0.0f)
pure virtual

This method draws a quad covering the entire current target set.

Parameters
[in]zz value of this quad

◆ DrawText() [1/2]

virtual void DrawText ( const Point3 xyz,
const MCHAR s 
)
pure virtual

This method draws a string at given world position.

Parameters
[in]xyzworld position of the string
[in]sthe text

◆ DrawText() [2/2]

virtual void DrawText ( const IPoint2 xy,
const MCHAR s 
)
pure virtual

This method draws a string at given screen position (upper left is the origin)

Parameters
[in]xyscreen position of the string
[in]sthe text

◆ BeginMarker()

virtual bool BeginMarker ( )
pure virtual

This method should be called before AddMarkers.

It can be used to draw markers. The system will create the appropriate buffer which will be filled up with calls to AddMarker

Returns
True if successful.

◆ AddMarkers()

virtual bool AddMarkers ( MarkerType  type,
const Point3 xyz,
size_t  count,
const Color color = DefaultMarkerColor 
)
pure virtual

This allows drawing batches of markers at a time.


Remarks
Only call this function between BeginMarker and EndMarker pair
Parameters
[in]typeMarker type
[in]xyzPointer to a Point3 buffer which contains marker's position in world space
[in]countNumber of markers
[in]colorMarker's color
Returns
True if successful. If false, then the buffer has potentially overflowed. Try using EndMarker and start another sequence

◆ AddScreenSpaceMarkers()

virtual bool AddScreenSpaceMarkers ( MarkerType  type,
const Point3 xyz,
size_t  count,
const Color color = DefaultMarkerColor 
)
pure virtual

This allows drawing batches of screen-space markers at a time.


needed to be drawn.

Remarks
Only call this function between BeginMarker and EndMarker pair
Parameters
[in]typeMarker type
[in]xyzPointer to a Point3 buffer which contains marker's position in screen space. z value's range is [0, 1]. "0" is front most and "1" is back most. It is used for comparing depth with other geometries.
[in]countNumber of markers
[in]colorMarker's color
Returns
True if successful. If false, then the buffer has potentially overflowed. Try using EndMarker and start another sequence

◆ EndMarker()

virtual void EndMarker ( )
pure virtual

Ends the marker drawing sequence.

This will draw and flush the internal buffers.

◆ SetMaterial()

virtual bool SetMaterial ( const BaseMaterialHandle material)
pure virtual

This method sets current material used by DrawPrimitive and DrawIndexedPrimitive.

Parameters
materialthe new materials' pointer

◆ GetMaterial()

virtual BaseMaterialHandle& GetMaterial ( )
pure virtual

This method gets current material.

Returns
current material handle

◆ SetVertexBuffer()

virtual void SetVertexBuffer ( size_t  count,
const VertexBufferHandle pBuffers 
)
pure virtual

This method sets vertex buffers used by DrawPrimitive.

Remarks
The number of steams is set by the StreamFormatHandle
Parameters
countnumber of vertex buffers, range is 0 to max number of streams - 1
pBuffersvertex buffer array

◆ SetIndexBuffer()

virtual void SetIndexBuffer ( const IndexBufferHandle pIndexBuffer)
pure virtual

This method sets index buffer used by DrawPrimitive.

Parameters
pIndexBufferA pointer to the index buffer object

◆ SetStreamFormat()

virtual void SetStreamFormat ( const StreamFormatHandle &  format)
pure virtual

This method sets vertex format of vertex buffer.

You can set multiple streams with different usage. Instance data must be a separate stream.

Parameters
formatformat of vertex buffer

◆ GetRenderStates()

virtual IRenderStateManager& GetRenderStates ( )
pure virtual

This method retrieves current render states object.

IRenderStateManager allows the developer to set various graphics states, whilst performing state management.

Returns
A reference of IRenderStateManager object

◆ GetVirtualDevice()

virtual IVirtualDevice& GetVirtualDevice ( )
pure virtual

This method retrieves current virtual device object.

IVirtualDevice allows the developer to set depth-stencil state,rasterizer state and blend state.

Returns
A reference of IVirtualDevice object

Member Data Documentation

◆ DefaultMarkerColor

GraphicsDriverAPI Color DefaultMarkerColor
static