23#ifndef VCL_BGFX_DRAWABLE_DRAWABLE_TRACKBALL_H
24#define VCL_BGFX_DRAWABLE_DRAWABLE_TRACKBALL_H
26#include "uniforms/drawable_trackball_uniforms.h"
28#include <vclib/algorithms/core/create.h>
29#include <vclib/bgfx/buffers.h>
30#include <vclib/math/transform.h>
31#include <vclib/render/drawable/drawable_object.h>
32#include <vclib/space/core/matrix.h>
34#include <vclib/bgfx/context.h>
40 inline static const uint N_POINTS = 128;
41 inline static const auto TRACKBALL_DATA =
51 bgfx::ProgramHandle mProgram =
54 .getProgram<VertFragProgram::DRAWABLE_TRACKBALL>();
63 mUniforms.setNumberOfVerticesPerAxis(N_POINTS);
69 mVisible(
other.mVisible), mProgram(
other.mProgram),
70 mUniforms(
other.mUniforms), mTransform(
other.mTransform)
93 swap(mVertexCoordsBuffer,
other.mVertexCoordsBuffer);
94 swap(mEdgeIndexBuffer,
other.mEdgeIndexBuffer);
112 DrawableTrackBall& operator=(DrawableTrackBall other)
120 void draw(uint viewId)
const override
123 if (bgfx::isValid(mProgram)) {
129 mVertexCoordsBuffer.
bind(0);
130 mEdgeIndexBuffer.
bind();
132 bgfx::setTransform(mTransform.data());
136 bgfx::submit(viewId, mProgram);
145 return std::make_shared<DrawableTrackBall>(*
this);
148 std::shared_ptr<DrawableObject>
clone() &&
override
150 return std::make_shared<DrawableTrackBall>(std::move(*
this));
161 mVertexCoordsBuffer.
create(
162 TRACKBALL_DATA.first.data(),
163 TRACKBALL_DATA.first.size(),
164 bgfx::Attrib::Position,
166 PrimitiveType::FLOAT);
170 TRACKBALL_DATA.second.data(), TRACKBALL_DATA.second.size(),
false);
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:365
The DrawableObject class is the base class for all the objects that can be drawn in a 3D viewer.
Definition drawable_object.h:55
Definition drawable_trackball.h:39
std::shared_ptr< DrawableObject > clone() const &override
This member function is used to create a new copy of the DrawableObject. Each derived class must impl...
Definition drawable_trackball.h:143
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_trackball.h:153
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_trackball.h:155
void updateDragging(bool isDragging)
Update the dragging status of the trackball.
Definition drawable_trackball.h:107
std::shared_ptr< DrawableObject > clone() &&override
This member function is used to create a new DrawableObject that is a moved from the current one....
Definition drawable_trackball.h:148
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_trackball.h:120
Box3d boundingBox() const override
This member function is used to find a good camera position to render object. It should return the th...
Definition drawable_trackball.h:141
void swap(DrawableTrackBall &other)
Swap the content of this object with another DrawableTrackBall object.
Definition drawable_trackball.h:89
The IndexBuffer manages the lifetime of a bgfx::IndexBufferHandle.
Definition index_buffer.h:43
void create(const void *bufferIndices, const uint bufferSize, bool is32Bit=true, bgfx::ReleaseFn releaseFn=nullptr)
Creates the index buffer and sets the data for rendering.
Definition index_buffer.h:103
void bind(uint stage=UINT_NULL, bgfx::Access::Enum access=bgfx::Access::Read) const
Bind the index buffer to the rendering pipeline.
Definition index_buffer.h:193
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The VertexBuffer manages the lifetime of a bgfx::VertexBufferHandle.
Definition vertex_buffer.h:43
void create(const void *bufferData, uint vertNum, bgfx::Attrib::Enum attrib, uint attribNumPerVertex, PrimitiveType attribType, bool normalize=false, bgfx::ReleaseFn releaseFn=nullptr)
Creates the vertex buffer and sets the data for rendering.
Definition vertex_buffer.h:106
void bind(uint stream, bgfx::Access::Enum access=bgfx::Access::Read) const
Bind the vertex buffer to the rendering pipeline.
Definition vertex_buffer.h:231