ComputerGraphik TU WIEN
Public Member Functions | Private Types | Private Attributes | List of all members
SelectorGPU Class Reference

Implements the GPU based object selection. More...

#include <selectorGPU.hpp>

Inheritance diagram for SelectorGPU:
SelectorBase SceneObject

Public Member Functions

 SelectorGPU (const std::string &name, Scene *scene)
 Defined in compute shader. More...
 
 ~SelectorGPU ()
 
void changeMode ()
 debug, change kernel count More...
 
void pickObject (const glm::ivec2 &mouse)
 select closest object to mouse More...
 
void getPixelCount (int &width, int &height) const
 
- Public Member Functions inherited from SelectorBase
 SelectorBase (const std::string &name, Scene *scene)
 
 ~SelectorBase ()
 
void reset ()
 set up EffectObject More...
 
void draw () const
 draw selectable object ids into a texture More...
 
void update (double deltaT)
 empty function More...
 
int getBufferWidth () const
 
int getBufferHeight () const
 
size_t getLastSelected () const
 
size_t getLastDistance () const
 
- Public Member Functions inherited from SceneObject
 SceneObject (std::shared_ptr< SceneObject > &effectParent, const glm::mat4 &modelMatrix=glm::mat4(1))
 
 SceneObject (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1))
 
virtual ~SceneObject ()
 
ModelgetModel () const
 
ShadergetShader () const
 
glm::mat4 getModelMatrix () const
 
glm::mat4 getGlobalModelMatrix () const
 
std::string getName () const
 
std::shared_ptr< SceneObjectgetParent () const
 
void setAnimationTime (double time)
 
bool setAnimation (const Animation &anim)
 
bool delChild (size_t idx)
 
bool getChild (size_t idx, std::shared_ptr< SceneObject > &child) const
 
bool addChild (std::shared_ptr< SceneObject > &child)
 
bool remEffect (const std::string &name)
 
SceneObjectgetEffect (const std::string &name) const
 
bool addEffect (const std::string &name, std::unique_ptr< SceneObject > &effect)
 
bool doNotRender ()
 
bool getIsVolSun ()
 
virtual bool animate (double time)
 
virtual void setShader (Shader *val)
 

Private Types

enum  { KernelSize = 8 }
 

Private Attributes

int mode
 debug, help to set window More...
 
int windowX
 number of kernels used in compute shader More...
 
int windowY
 number of kernels used in compute shader More...
 
GLuint objectBuffer
 buffer to store compute shader result on GPU More...
 
ShadercomputeShader
 the compute shader to use More...
 
std::vector< GLuint > buffer
 buffer to store compute shader result on CPU More...
 

Additional Inherited Members

- Public Types inherited from SceneObject
typedef std::vector< std::pair< double, glm::mat4 > > Animation
 
- Protected Attributes inherited from SelectorBase
int width
 width of screen More...
 
int height
 height of screen More...
 
GLuint idBuffer
 frame buffer More...
 
GLuint idTexture
 texture of rendered object indices More...
 
size_t lastDistance
 distance after pickObject() call More...
 
size_t lastSelected
 selected object id after pickObject() call More...
 
- Protected Attributes inherited from SceneObject
GLuint vao
 
Scenescene
 
Modelmodel
 
Shadershader
 
glm::mat4 modelMatrix
 
std::string name
 
std::weak_ptr< SceneObjectparent
 
std::vector< std::shared_ptr< SceneObject > > childs
 
std::map< std::string, std::unique_ptr< SceneObject > > effectChilds
 
size_t animIDX
 
Animation animation
 
bool norender
 
bool isVolSun
 

Detailed Description

Implements the GPU based object selection.

The SelectorGPU class implements an alternative selection method. The selectable objects are rendered into a texture the same way as in the quadtree based method. After rendering a compute shader is executed on the texture, returning the id and the distance of the closest object to the mouse. This way memory transfer and cpu time can be saved. By selecting different count of kernels, the size of the screen ROI can be modified. The following pseudocode demonstrates the object selection by the compute shader:

//the compute shader, executed for each pixel
ivec2 pixel = compute pixel position from thread id
if pixel out of pick buffer bounds
return;
//load object id at pixel position
uint id = imageLoad(pickBuffer, pixel)
//no object at pixel
if id == 0
return;
//compute distance, pack id and store if less
uint dist = (distance(mouse, pixel) << 16) | id;
atomicMin(buffer, dist);
Author
Adam

Member Enumeration Documentation

anonymous enum
private
Enumerator
KernelSize 

Constructor & Destructor Documentation

SelectorGPU::SelectorGPU ( const std::string &  name,
Scene scene 
)

Defined in compute shader.

SelectorGPU::~SelectorGPU ( )

Member Function Documentation

void SelectorGPU::changeMode ( )
virtual

debug, change kernel count

Implements SelectorBase.

void SelectorGPU::getPixelCount ( int &  width,
int &  height 
) const
inline
void SelectorGPU::pickObject ( const glm::ivec2 &  mouse)
virtual

select closest object to mouse

Implements SelectorBase.

Member Data Documentation

std::vector<GLuint> SelectorGPU::buffer
private

buffer to store compute shader result on CPU

Shader* SelectorGPU::computeShader
private

the compute shader to use

int SelectorGPU::mode
private

debug, help to set window

GLuint SelectorGPU::objectBuffer
private

buffer to store compute shader result on GPU

int SelectorGPU::windowX
private

number of kernels used in compute shader

int SelectorGPU::windowY
private

number of kernels used in compute shader


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