Signed Distance Fields 1.0
PrimitiveManager Class Reference

Primitive management in the construction tree. More...

#include <sdf.h>

Public Member Functions

 PrimitiveManager ()
 Handle the writing of glsl primitives in an order respecting the dependency.
bool insertPrimitive (const QString &, const QString &, std::list< QString >=std::list< QString >())
 add a primitive in the shader, return true if the primitive is inserted, false otherwise (if the primitive was already in the list)
void setDependence (const QString &, std::list< QString > &)
 set the dependency of a given primitive
int getId ()
 get a primitive name that is not in the primitives set yet
QString getPRIMITIVE ()
 return a glsl code of all primitives in an order respecting the dependency
QString getPRIMITIVE (std::list< QString >)
 return a glsl code of all primitives in an order respecting the dependency
QString printGLSL ()
 Write PRIMITIVE code with identation and newline to help the reading.
qsizetype Alloc (qsizetype)
 reserve some memory space in the global OpenGl buffer 'FloatBuffer' that is loaded on the GPU when executing the shader
qsizetype Alloc (const QString &, qsizetype size)
 reserve some memory space in the global OpenGl buffer 'FloatBuffer' that is loaded on the GPU when executing the shader
qsizetype allocsize (const QString &name) const
 Give the size of a memory block. Return 0 if the block is not allocated, allowing check if(!allocisze("name"))malloc("name", ...);.
void setFloatData (float *floatData, qsizetype ptr, qsizetype size)
 Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.
void setFloatData (const QVector< float > &floatData, qsizetype ptr)
 Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.
void setFloatData (const QVector< Vector > &floatData, qsizetype ptr)
 Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.
void setFloatData (const QVector< Matrix > &floatData, qsizetype ptr)
 Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.
int GetFloatBufferSize () const
 return the size of the 'FloatBuffer'
const float * GetFloatBufferData () const
 return the data of the 'FloatBuffer'
QVector< float > GetFloatBufferDataQVector () const
 return the data of the 'FloatBuffer'

Protected Member Functions

QString getPRIMITIVE (const QString &, std::map< QString, bool > &) const
 Return the glsl code of a primitive and it's dependency.

Protected Attributes

std::map< QString, std::pair< QString, std::list< QString > > > primitives
 A map with primitive names as key, and a pair of (primitive code, list of primitive dependency) as data.
std::map< QString, QPair< qsizetype, qsizetype > > memoryNames
 A map memory name as key and memory <pointer, block size> as value.

Detailed Description

Primitive management in the construction tree.

Constructor & Destructor Documentation

◆ PrimitiveManager()

PrimitiveManager::PrimitiveManager ( )
explicit

Handle the writing of glsl primitives in an order respecting the dependency.

Author
Hubert-Brierre Pierre

Member Function Documentation

◆ Alloc() [1/2]

qsizetype PrimitiveManager::Alloc ( const QString & name,
qsizetype size )

reserve some memory space in the global OpenGl buffer 'FloatBuffer' that is loaded on the GPU when executing the shader

Parameters
namename of the allocated memory. If it was already used return the pointer to that previously allocated memory
sizenumber of float to reserve See SDFFrames::GetShader for use example
Author
Hubert-Brierre Pierre

◆ Alloc() [2/2]

qsizetype PrimitiveManager::Alloc ( qsizetype size)

reserve some memory space in the global OpenGl buffer 'FloatBuffer' that is loaded on the GPU when executing the shader

Parameters
qsizetypesize : number of float to reserve See SDFFrames::GetShader for use example
Author
Hubert-Brierre Pierre

◆ allocsize()

qsizetype PrimitiveManager::allocsize ( const QString & name) const

Give the size of a memory block. Return 0 if the block is not allocated, allowing check if(!allocisze("name"))malloc("name", ...);.

Parameters
namename of the allocated memory.
Returns
size number of float to reserved See SDFFrames::GetShader for use example
Author
Hubert-Brierre Pierre

◆ GetFloatBufferData()

const float * PrimitiveManager::GetFloatBufferData ( ) const

return the data of the 'FloatBuffer'

Author
Hubert-Brierre Pierre

◆ GetFloatBufferDataQVector()

QVector< float > PrimitiveManager::GetFloatBufferDataQVector ( ) const

return the data of the 'FloatBuffer'

Author
Hubert-Brierre Pierre

◆ GetFloatBufferSize()

int PrimitiveManager::GetFloatBufferSize ( ) const

return the size of the 'FloatBuffer'

Author
Hubert-Brierre Pierre

◆ getId()

int PrimitiveManager::getId ( )

get a primitive name that is not in the primitives set yet

Author
Hubert-Brierre Pierre

Create a uniqueId

Author
Hubert-Brierre Pierre

◆ getPRIMITIVE() [1/3]

QString PrimitiveManager::getPRIMITIVE ( )

return a glsl code of all primitives in an order respecting the dependency

Author
Hubert-Brierre Pierre

◆ getPRIMITIVE() [2/3]

QString PrimitiveManager::getPRIMITIVE ( const QString & name,
std::map< QString, bool > & primitivesWritten ) const
protected

Return the glsl code of a primitive and it's dependency.

Author
Hubert-Brierre Pierre
Parameters
nameThe primitive to write.
primitivesWrittenA map to manage the primitives (true if the primitive is already written, false if the primitive is encouter but not written, not in the map if the primitive is not encouter yet).

◆ getPRIMITIVE() [3/3]

QString PrimitiveManager::getPRIMITIVE ( std::list< QString > names)

return a glsl code of all primitives in an order respecting the dependency

Author
Hubert-Brierre Pierre

◆ insertPrimitive()

bool PrimitiveManager::insertPrimitive ( const QString & name,
const QString & glslCode,
std::list< QString > dependency = std::list<QString>() )

add a primitive in the shader, return true if the primitive is inserted, false otherwise (if the primitive was already in the list)

Author
Hubert-Brierre Pierre
Parameters
nameName of the primitive.
glslCodeCode of the primitive.
dependencyList of name of primitive that need to be written before this one.

◆ printGLSL()

QString PrimitiveManager::printGLSL ( )

Write PRIMITIVE code with identation and newline to help the reading.

Author
Hubert-Brierre Pierre

◆ setDependence()

void PrimitiveManager::setDependence ( const QString & name,
std::list< QString > & dependency )

set the dependency of a given primitive

Author
Hubert-Brierre Pierre
Parameters
nameName of the primitive.
dependencyList of name of primitive that need to be written before this one.

◆ setFloatData() [1/4]

void PrimitiveManager::setFloatData ( const QVector< float > & floatData,
qsizetype ptr )

Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.

Parameters
floatDatapointer to the float array
pointerto the start of the memory block in the 'FloatBuffer' (return value of the function PrimitiveManager::malloc)
Author
Hubert-Brierre Pierre

◆ setFloatData() [2/4]

void PrimitiveManager::setFloatData ( const QVector< Matrix > & floatData,
qsizetype ptr )

Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.

Parameters
floatDatapointer to the Matrix array. The array will be flatten out : [floatData[0][0], ..., floatData[0][9], floatData[1][0], ...]
ptrpointer to the start of the memory block in the 'FloatBuffer' (return value of the function PrimitiveManager::malloc)
Author
Hubert-Brierre Pierre

◆ setFloatData() [3/4]

void PrimitiveManager::setFloatData ( const QVector< Vector > & floatData,
qsizetype ptr )

Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.

Parameters
QVector<Vector>floatData : pointer to the Vector array. The array will be flatten out : [floatData[0].x, floatData[0].y, floatData[0].z, floatData[1].x, ...]
qsizetypeptr : pointer to the start of the memory block in the 'FloatBuffer' (return value of the function PrimitiveManager::malloc)
Author
Hubert-Brierre Pierre

◆ setFloatData() [4/4]

void PrimitiveManager::setFloatData ( float * floatData,
qsizetype ptr,
qsizetype size )

Write in the 'FloatBuffer'. This is a read only buffer loaded on GPU when executing the shader.

Parameters
floatDatapointer to the float array
ptrpointer to the start of the memory block in the 'FloatBuffer' (return value of the function PrimitiveManager::malloc)
sizenumber of float to write
Author
Hubert-Brierre Pierre