29 # define STB_IMAGE_WRITE_IMPLEMENTATION
30 # include "stb_image_write.h"
44 _inputManager(inputManager),
45 _shadowMapTimesMS(60, 0.0f),
46 _cullTimesMS(60, 0.0f),
47 _draw3DTimesMS(60, 0.0f),
48 _draw2DTimesMS(60, 0.0f),
49 _screenCaptureIsRequested(false),
50 _screenCaptureWaitFrames(0)
70 void* onWndUpdateCallback,
71 void* onSelectNodeMeshCallback,
73 const string& configPath)
116 #if defined(SL_OS_ANDROID) || defined(SL_OS_MACIOS) || defined(SL_EMSCRIPTEN)
149 material->nodesVisible2D().clear();
153 material->nodesVisible3D().clear();
198 vsCorners[0] =
SLVec4f(minX, minY, minZ);
199 vsCorners[1] =
SLVec4f(maxX, minY, minZ);
200 vsCorners[2] =
SLVec4f(minX, maxY, minZ);
201 vsCorners[3] =
SLVec4f(maxX, maxY, minZ);
202 vsCorners[4] =
SLVec4f(minX, minY, maxZ);
203 vsCorners[5] =
SLVec4f(maxX, minY, maxZ);
204 vsCorners[6] =
SLVec4f(minX, maxY, maxZ);
205 vsCorners[7] =
SLVec4f(maxX, maxY, maxZ);
207 SLVec3f vsMin(FLT_MAX, FLT_MAX, FLT_MAX);
208 SLVec3f vsMax(FLT_MIN, FLT_MIN, FLT_MIN);
212 for (
auto& vsCorner : vsCorners)
214 vsCorner = vm * vsCorner;
216 vsMin.
x = std::min(vsMin.
x, vsCorner.x);
217 vsMin.
y = std::min(vsMin.
y, vsCorner.y);
218 vsMin.
z = std::min(vsMin.
z, vsCorner.z);
220 vsMax.
x = std::max(vsMax.
x, vsCorner.x);
221 vsMax.
y = std::max(vsMax.
y, vsCorner.y);
222 vsMax.
z = std::max(vsMax.
z, vsCorner.z);
239 distX = vsMax.
x / (ar * halfTan);
240 distY = vsMax.
y / halfTan;
245 distX = (vsMax.
x - vsMin.
x) * 0.5f / (ar * halfTan);
246 distY = (vsMax.
y - vsMin.
y) * 0.5f / halfTan;
252 SLfloat dist = std::max(distX, distY);
284 SLVec3f forward(-currentWM.
m(8), -currentWM.
m(9), -currentWM.
m(10));
300 if (nextCam ==
nullptr)
316 assert(
_scrW > 0 &&
_scrH > 0 &&
"SLSceneView::setViewportFromRatio: Invalid screen size");
333 SLfloat vpWdivH = (float)vpRatio.
x / (
float)vpRatio.
y;
348 default: vpRect.
x = (
_scrW - vpRect.
width) / 2;
break;
373 SL_EXIT_MSG(
"SLSceneView::viewport: Viewport is bigger than the screen!");
407 if (SLOptix::available)
411 _optixRaytracer.setupOptix();
412 _optixPathtracer.setupOptix();
414 catch (std::exception& e)
416 SLOptix::available =
false;
417 SL_LOG(
"**** OptiX renderers disabled ****");
419 SL_LOG(
"The GPU is most likely older than the SL_OPTIX_CUDA_ARCH the");
420 SL_LOG(
"kernels were compiled for. Everything else keeps working.");
435 _s->
root3D()->updateMeshAccelStructs();
445 SL_LOG_DEBUG(
"sv->onInitialize : No Lights found in scene!");
483 if (width == 0 || height == 0)
return;
532 SLbool sceneHasChanged =
false;
533 SLbool viewConsumedEvents =
false;
556 SLbool camUpdated =
false;
575 case RT_optix_rt: camUpdated = draw3DOptixRT();
break;
576 case RT_optix_pt: camUpdated = draw3DOptixPT();
break;
603 return !
_doWaitOnIdle || camUpdated || sceneHasChanged || viewConsumedEvents;
676 if (light->createsShadows())
677 light->renderShadowMap(
this,
_s->
root3D());
755 material->nodesVisible3D().clear();
775 _s->
skybox()->drawAroundCamera(
this);
801 _s->
skybox()->drawAroundCamera(
this);
836 if (!material->hasAlpha())
852 if (material->hasAlpha())
875 stateGL->
blend(
false);
890 if (nodes.empty())
return;
894 stateGL->
blend(alphaBlended);
901 std::sort(nodes.begin(), nodes.end(), [](
SLNode* a,
SLNode* b)
903 if (!a) return false;
905 return a->aabb()->sqrViewDist() > b->aabb()->sqrViewDist(); });
909 for (
auto* node : nodes)
915 node->drawMesh(
this);
934 if (nodes.empty())
return;
937 stateGL->
blend(
false);
944 for (
auto* node : nodes)
959 if (node->isSelected())
980 for (
auto* node : nodes)
990 stateGL->
blend(
false);
999 node->aabb()->drawAxisWS();
1010 for (
auto joint : skeleton->
joints())
1013 SLMat4f wm = node->updateAndGetWM();
1014 wm *= joint->updateAndGetWM();
1018 if (joint->parent())
1020 parentWM = node->parent()->updateAndGetWM();
1021 parentWM *= joint->parent()->updateAndGetWM();
1022 joint->aabb()->updateBoneWS(parentWM,
false, wm);
1025 joint->aabb()->updateBoneWS(parentWM,
true, wm);
1027 joint->aabb()->drawBoneWS();
1034 node->aabb()->calculateRectSS();
1057 if (node->mesh() && node->mesh()->mat())
1059 SLMesh* mesh = node->mesh();
1063 stateGL->
blend(hasAlpha);
1072 node->drawMesh(
this);
1107 material->nodesVisible2D().clear();
1170 stateGL->
blend(
true);
1178 for (
auto* node : material->nodesVisible2D())
1184 node->drawMesh(
this);
1196 node->drawMesh(
this);
1208 SLVVec3f centerRombusPoints = {{-cs, 0, 0},
1214 SLCol4f yelloAlpha(1.0f, 1.0f, 0.0f, 0.5f);
1232 SLint circlePoints = 60;
1234 for (
SLint i = 0; i < circlePoints; ++i)
1238 rombusAndCirclePoints.push_back(
SLVec3f(c.
x, c.
y, 0));
1242 SLCol4f yelloAlpha(1.0f, 1.0f, 0.0f, 0.5f);
1249 stateGL->
blend(
false);
1294 SLbool eventConsumed =
false;
1297 if (eh->onMouseDown(button, x, y,
mod))
1298 eventConsumed =
true;
1360 SLbool eventConsumed =
false;
1363 if (eh->onMouseUp(button, x, y,
mod))
1364 eventConsumed =
true;
1439 SLbool eventConsumed =
false;
1442 if (eh->onMouseMove(btn, x, y,
_mouseMod))
1443 eventConsumed =
true;
1460 static SLint lastMouseWheelPos = 0;
1461 SLint delta = wheelPos - lastMouseWheelPos;
1462 lastMouseWheelPos = wheelPos;
1498 if (eh->onMouseWheel(delta,
mod))
1528 SLRay pickRay(
this);
1541 if (pickRay.
length < FLT_MAX)
1566 if (eh->onDoubleClick(button, x, y,
mod))
1600 if (eh->onTouch2Down(x1, y1, x2, y2))
1633 if (eh->onTouch2Move(x1, y1, x2, y2))
1665 if (eh->onTouch2Up(x1, y1, x2, y2))
1703 if (key==
'R' &&
mod==
K_shift) {startOptixRaytracing(5);}
1704 if (key==
'P' &&
mod==
K_shift) {startOptixPathtracing(5, 100);}
1763 if (eh->onKeyPress(key,
mod))
1798 if (eh->onKeyRelease(key,
mod))
1831 profiling =
" *** PROFILING *** ";
1844 "Ray Tracing: %s (fps: %4.1f, Threads: %d)",
1853 "Ray Tracing: %s (Threads: %d)",
1862 "Path Tracing: %s (Threads: %d)",
1870 format =
"OpenGL Renderer: %s (fps: %4.0f, %u nodes of %u rendered)";
1872 format =
"OpenGL Renderer: %s (fps: %4.1f, %u nodes of %u rendered)";
1884 snprintf(title,
sizeof(title),
"Scene is loading ...");
1886 return profiling +
SLstring(title) + profiling;
1918 _s->
root3D()->updateMeshAccelStructs();
1971 _s->
root3D()->updateMeshAccelStructs();
1992 void SLSceneView::startOptixRaytracing(
SLint maxDepth)
1996 if (!SLOptix::available)
return;
1998 _stopOptixRT =
false;
1999 _optixRaytracer.maxDepth(maxDepth);
2007 _optixRaytracer.setupScene(
this,
s()->assetManager());
2009 catch (std::exception& e)
2011 SLOptix::available =
false;
2012 SL_LOG(
"**** OptiX ray tracing failed, renderer disabled ****");
2020 SLbool SLSceneView::draw3DOptixRT()
2025 if (_optixRaytracer.state() ==
rtReady)
2029 _optixRaytracer.updateScene(
this);
2031 if (_optixRaytracer.doDistributed())
2032 _optixRaytracer.renderDistrib();
2034 _optixRaytracer.renderClassic();
2038 _optixRaytracer.renderImage(
false);
2050 void SLSceneView::startOptixPathtracing(
SLint maxDepth,
SLint samples)
2053 if (!SLOptix::available)
return;
2055 _stopOptixPT =
false;
2056 _optixPathtracer.maxDepth(maxDepth);
2057 _optixPathtracer.samples(samples);
2061 _optixPathtracer.setupScene(
this,
s()->assetManager());
2063 catch (std::exception& e)
2065 SLOptix::available =
false;
2066 SL_LOG(
"**** OptiX path tracing failed, renderer disabled ****");
2074 SLbool SLSceneView::draw3DOptixPT()
2079 if (_optixPathtracer.state() ==
rtReady)
2084 _optixPathtracer.updateScene(
this);
2085 _optixPathtracer.render();
2089 _optixPathtracer.renderImage(
false);
2108 cv::Size targetSize)
2115 #ifndef SL_EMSCRIPTEN
2116 GLsizei nrChannels = 3;
2118 GLsizei nrChannels = 4;
2121 GLsizei stride = nrChannels * fbW;
2122 stride += (stride % 4) ? (4 - stride % 4) : 0;
2123 GLsizei bufferSize = stride * fbH;
2124 vector<uchar> buffer(bufferSize);
2128 #ifndef SL_EMSCRIPTEN
2129 CVMat rgbImg =
CVMat(fbH, fbW, CV_8UC3, (
void*)buffer.data(), stride);
2130 cv::cvtColor(rgbImg, rgbImg, cv::COLOR_BGR2RGB);
2135 (
void*)buffer.data(),
2137 cv::cvtColor(rgbImg, rgbImg, cv::COLOR_RGBA2RGB);
2139 stride = nrChannels * fbW;
2142 cv::flip(rgbImg, rgbImg, 0);
2143 if (targetSize.width > 0 && targetSize.height > 0)
2144 cv::resize(rgbImg, rgbImg, targetSize);
2146 #ifndef SL_EMSCRIPTEN
2147 vector<int> compression_params;
2148 compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
2149 compression_params.push_back(6);
2153 imwrite(pathFilename, rgbImg, compression_params);
2154 string msg =
"Screenshot saved to: " + pathFilename;
2157 catch (std::runtime_error& ex)
2159 string msg =
"SLSceneView::saveFrameBufferAsImage: Exception: ";
2164 auto writer = [](
void* context,
void* data,
int size)
2167 stream->
write(data, size);
2173 stbi_write_png_to_func(writer,
2183 #if !defined(SL_OS_ANDROID) && !defined(SL_OS_MACIOS) && !defined(SL_EMSCRIPTEN)
static SLint dpi
Dot per inch resolution of screen.
#define PROFILE_FUNCTION()
float SLfloat
analog to GLfloat
#define SL_LOG_DEBUG(...)
#define SL_LOG(...)
Some debugging and error handling macros.
unsigned int SLuint
analog to GLuint
char SLchar
analog to GLchar (char is signed [-128 ... 127]!)
bool SLbool
analog to GLbool
#define SL_EXIT_MSG(message)
string SLstring
Redefinition of standard types for platform independence.
#define SL_DB_ONLYEDGES
Draw only hard edges.
#define SL_DB_NORMALS
Draw the vertex normals.
#define SL_DB_SKELETON
Draw the skeletons joints.
#define SL_DB_WITHEDGES
Draw faces with hard edges.
#define SL_DB_AXIS
Draw the coordinate axis of a node.
#define SL_DB_BRECT
Draw the bounding rectangle of a node.
#define SL_DB_OVERDRAW
Draw node over all other nodes.
#define SL_DB_VOXELS
Draw the voxels of the uniform grid.
#define SL_DB_GPU_SKINNING
Perform skinning on the GPU.
#define SL_DB_CULLOFF
Turn off face culling.
#define SL_DB_MESHWIRED
Draw polygons as wired mesh.
#define SL_DB_BBOX
Draw the bounding boxes of a node.
@ CA_turntableYUp
Orbiting around central object w. turntable rotation around y & right axis.
@ CA_trackball
Orbiting around central object w. one rotation around one axis.
@ CA_turntableZUp
Orbiting around central object w. turntable rotation around z & right axis.
SLProjType
Enumeration for different camera projections.
@ P_monoPerspective
standard mono pinhole perspective projection
@ P_stereoSideBySideD
side-by-side distorted for Oculus Rift like glasses
@ P_stereoLineByLine
line-by-line
@ P_monoOrthographic
standard mono orthographic projection
@ RT_optix_pt
Path Tracing with OptiX.
@ RT_optix_rt
Ray Tracing with OptiX.
SLMouseButton
Mouse button codes.
SLViewportAlign
Mouse button codes.
SLKey
Keyboard key codes enumeration.
Wrapper Class around the external ImGui GUI-framework.
deque< SLNode * > SLVNode
SLVNode typedef for a vector of SLNodes.
SLRect< SLint, SLVec2i > SLRecti
void(SL_STDCALL * cbOnSelectNodeMesh)(SLNode *, SLMesh *)
Callback function typedef for select node.
SLbool(SL_STDCALL * cbOnWndUpdate)()
Callback function typedef for GUI window updateRec.
vector< SLVec3f > SLVVec3f
SLVec3< SLfloat > SLVec3f
SLVec4< SLfloat > SLVec4f
Defines an axis aligned bounding box.
void minWS(const SLVec3f &minC)
void maxWS(const SLVec3f &maxC)
void drawVisuals(SLSceneView *sv)
Draws the animation visualizations.
SLAnimSkeleton keeps track of a skeletons joints and animations.
const SLVJoint & joints() const
void render(SLint widthPX, SLint heightPX)
Draws the background as 2D rectangle with OpenGL buffers.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
SLbool onTouch2Down(SLint x1, SLint y1, SLint x2, SLint y2) override
SLbool onKeyRelease(SLKey key, SLKey mod) override
SLfloat trackballSize() const
void setViewport(SLSceneView *sv, SLEyeType eye)
Sets the viewport transform depending on the projection.
SLbool onMouseUp(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever the mouse button is released.
void stereoEyeSeparation(const SLfloat es)
SLfloat fovV() const
Vertical field of view.
void clipFar(const SLfloat cFar)
void clipNear(const SLfloat cNear)
void focalDist(const SLfloat f)
void maxSpeed(const SLfloat ms)
SLbool onMouseMove(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever the mouse is moved.
void setView(SLSceneView *sv, SLEyeType eye)
void projType(SLProjType p)
void eyeToPixelRay(SLfloat x, SLfloat y, SLRay *ray)
eyeToPixelRay returns the a ray from the eye to the center of a pixel.
virtual SLbool camUpdate(SLSceneView *sv, SLfloat timeMS)
void setFrustumPlanes()
SLCamera::setFrustumPlanes set the 6 plane from the view frustum.
SLBackground & background()
SLbool onTouch2Up(SLint x1, SLint y1, SLint x2, SLint y2) override
SLbool onMouseDown(SLMouseButton button, SLint x, SLint y, SLKey mod) override
Gets called whenever a mouse button gets pressed.
void setProjection(SLSceneView *sv, SLEyeType eye)
SLbool onTouch2Move(SLint x1, SLint y1, SLint x2, SLint y2) override
SLbool onKeyPress(SLKey key, SLKey mod) override
SLbool onMouseWheel(SLint delta, SLKey mod) override
void camAnim(SLCamAnim ca)
void toggle(SLuint bit)
Toggles the specified bit.
void allOff()
Turns all bits off.
virtual SLbool onDoubleClick(const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
void updateSize(SLint scrWidth, SLint scrHeight)
void bindFramebuffer(SLint scrWidth, SLint scrHeight)
SLfloat resolutionScale()
void renderDistortion(SLint width, SLint height, SLuint tex, const SLCol4f &background)
void renderResolution(SLint width, SLint height)
Singleton class holding all OpenGL states.
void clearColor(const SLCol4f &c)
SLMat4f modelMatrix
Init all states.
void depthMask(SLbool state)
void viewport(SLint x, SLint y, SLsizei width, SLsizei height)
void multiSample(SLbool state)
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLMat4f viewMatrix
matrix for the active cameras view transform
void unbindAnythingAndFlush()
finishes all GL commands
void colorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
void onInitialize(const SLCol4f &clearColor)
On init GL.
SLMat4f projectionMatrix
matrix for projection transform
void polygonLine(SLbool state)
void readPixels(void *buffer)
Reads the front framebuffer pixels into the passed buffer.
void clearColorDepthBuffer()
void depthTest(SLbool state)
void deleteData(SLbool deleteAlsoOnGPU)
Delete all data (CVImages and GPU textures)
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
void clearAttribs()
Clears the attribute definition.
static SLuint totalDrawCalls
static SLuint totalPrimitivesRendered
static total no. of draw calls
Interface for accessing external data using streams.
virtual size_t write(const void *buffer, size_t size)
Abstract Light class for OpenGL light sources.
SLVec3< T > translation() const
void ortho(T l, T r, T b, T t, T n, T f)
Defines a orthographic projection matrix with a field of view angle.
void identity()
Sets the identity matrix.
void translate(T tx, T ty, T tz=0)
SLbool hasAlpha()
Returns true if there is any transparency in diffuse alpha or textures.
An SLMesh object is a triangulated mesh, drawn with one draw call.
SLNode represents a node in a hierarchical scene graph.
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
virtual void needUpdate()
const SLMat4f & updateAndGetWM() const
const SLMat4f & updateAndGetWMI() const
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
virtual SLAABBox & updateAABBRec(SLbool updateAlsoAABBinOS)
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Base class for all other classes.
void name(const SLstring &Name)
SLstring _name
name of an object
const SLstring & name() const
SLbool render(SLSceneView *sv)
Ray class with ray and intersection properties.
SLMesh * hitMesh
Points to the intersected mesh.
SLfloat length
length from origin to an intersection
SLNode * hitNode
Points to the intersected node.
SLbool renderClassic(SLSceneView *sv)
void doContinuous(SLbool cont)
void state(SLRTState state)
static SLuint numThreads()
SLbool renderDistrib(SLSceneView *sv)
virtual void renderImage(bool updateTextureGL)
void maxDepth(SLint depth)
void aaSamples(SLint samples)
void doDistributed(SLbool distrib)
void set(const T X, const T Y, const T WIDTH, const T HEIGHT)
SLbool contains(T X, T Y)
void drawGL(const SLCol4f &color)
The SLScene class represents the top level instance holding the scene structure.
bool onUpdate(bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
Updates animations and AABBs.
void deselectAllNodesAndMeshes()
Deselects all nodes and its meshes.
SLCamera * nextCameraInScene(SLCamera *activeSVCam)
Returns the next camera in the scene if there is one.
SLVEventHandler & eventHandlers()
void root2D(SLNode *root2D)
SLAnimManager & animManager()
void selectNodeMesh(SLNode *nodeToSelect, SLMesh *meshToSelect)
Handles the full mesh selection from double-clicks.
SLfloat elapsedTimeMS() const
void skybox(SLSkybox *skybox)
void root3D(SLNode *root3D)
SLNode * singleNodeSelected()
Returns the node if only one is selected. See also SLMesh::selectNodeMesh.
SLVNode & selectedNodes()
void stopAnimations(SLbool stop)
SLKey _mouseMod
mouse modifier key on key down
SLfloat _draw2DTimeMS
time for 2D drawing in ms
SLbool _screenCaptureIsRequested
Flag if screen capture is requested.
SLPathtracer _pathtracer
Pathtracer.
std::unordered_set< SLMaterial * > _visibleMaterials2D
visible materials 2D per frame
SLint _scrW
Screen width in pixels.
void draw3DGLLinesOverlay(SLVNode &nodes)
void switchToNextCameraInScene()
Sets the active camera to the next in the scene.
std::unordered_set< SLMaterial * > _visibleMaterials3D
visible materials 3D per frame
SLbool doWaitOnIdle() const
SLbool _stopPT
Flag to stop the PT.
SLNodeStats _stats3D
Statistic numbers for 3D nodes.
SLfloat _scrWdivH
Screen side aspect ratio.
SLint _screenCaptureWaitFrames
Frames to delay the screen capture.
virtual SLbool onDoubleClick(SLMouseButton button, SLint x, SLint y, SLKey mod)
SLint _scrH
Screen height in pixels.
SLRaytracer _raytracer
Whitted style raytracer.
SLbool _gotPainted
flag if this sceneview got painted
virtual SLbool onMouseWheelPos(SLint wheelPos, SLKey mod)
SLbool _mouseDownM
Flag if middle mouse button is pressed.
SLVNode _nodesBlended3D
Vector of visible blended nodes not in _visibleMaterials3D rendered in 3D.
SLVNode _nodesOverdrawn
Vector of helper nodes drawn over all others.
void draw3DGLNodes(SLVNode &nodes, SLbool alphaBlended, SLbool depthSorted)
cbOnWndUpdate onWndUpdate
C-Callback for app for intermediate window repaint.
SLVNode _nodesOpaque2D
Vector of visible opaque nodes not in _visibleMaterials2D rendered in 2D.
virtual SLbool onCharInput(SLuint c)
SLVNode _nodesBlended2D
Vector of visible blended nodes not in _visibleMaterials2D rendered in 2D.
SLbool doDepthTest() const
SLbool _doMultiSampling
Flag if multisampling is on.
SLRenderType _renderType
rendering type (GL,RT,PT)
SLGLOculusFB _oculusFB
Oculus framebuffer.
void draw3DGLLines(SLVNode &nodes)
void startPathtracing(SLint maxDepth, SLint samples)
Starts the path tracer. maxDepth is only a safety net against an.
void onResize(SLint width, SLint height)
cbOnSelectNodeMesh onSelectedNodeMesh
C-Callback for app on node selection.
SLbool _mouseDownL
Flag if left mouse button is pressed.
void switchToSceneViewCamera()
SLRecti _viewportRect
rectangle of viewport
SLVNode _nodesOpaque3D
Vector of visible opaque nodes not in _visibleMaterials3D rendered in 3D.
SLGLVertexArrayExt _vaoTouch
Buffer for touch pos. rendering.
SLUiInterface * _gui
new tighter imgui wrapper
SLbool doFrustumCulling() const
SLViewportAlign _viewportAlign
alignment of viewport
SLbool _doFrustumCulling
Flag if view frustum culling is on.
SLfloat _draw3DTimeMS
time for 3D drawing in ms
SLint _scrWdiv2
Screen half width in pixels.
SLbool _doWaitOnIdle
Flag for Event waiting.
virtual SLbool onMouseMove(SLint x, SLint y)
SLbool _doAlphaSorting
Flag if alpha sorting in blending is on.
SLint _scrHdiv2
Screen half height in pixels.
AvgFloat _shadowMapTimesMS
Averaged time for drawing the shadow maps in ms.
SLNodeStats _stats2D
Statistic numbers for 2D nodes.
SLbool _mouseDownR
Flag if right mouse button is pressed.
void init(SLstring name, SLint screenWidth, SLint screenHeight, void *onWndUpdateCallback, void *onSelectNodeMeshCallback, SLUiInterface *gui, const string &configPath)
SLbool doMultiSampling() const
void startRaytracing(SLint maxDepth)
SLbool drawBit(SLuint bit)
void initSceneViewCamera(const SLVec3f &dir=-SLVec3f::AXISZ, SLProjType proj=P_monoPerspective)
virtual SLbool onKeyRelease(SLKey key, SLKey mod)
SLbool doAlphaSorting() const
SLbool _viewportSameAsVideo
Adapt viewport aspect to the input video.
SLbool _doDepthTest
Flag if depth test is turned on.
SLbool _isFirstFrame
Flag if it is the first frame rendering.
void saveFrameBufferAsImage(SLstring pathFilename, cv::Size targetSize=cv::Size(-1, -1))
Saves after n wait frames the front frame buffer as a PNG image.
SLSceneView(SLScene *s, int dpi, SLInputManager &inputManager)
SLSceneView default constructor.
AvgFloat _cullTimesMS
Averaged time for culling in ms.
virtual SLbool onMouseWheel(SLint delta, SLKey mod)
SLint _touchDowns
finger touch down count
SLVec2i _touch[3]
up to 3 finger touch coordinates
SLInputManager & _inputManager
SLCamera _sceneViewCamera
Default camera for this SceneView (default cam not in scenegraph)
AvgFloat _draw2DTimesMS
Averaged time for 2D drawing in ms.
SLfloat _cullTimeMS
time for culling in ms
SLRaytracer * raytracer()
SLVec2i _viewportRatio
ratio of viewport
virtual SLbool onTouch2Move(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
virtual SLbool onMouseUp(SLMouseButton button, SLint scrX, SLint scrY, SLKey mod)
SLScene * _s
Pointer to the scene observed by this scene view.
SLfloat _shadowMapTimeMS
time for drawing the shadow maps in ms
void setViewportFromRatio(const SLVec2i &vpRatio, SLViewportAlign vpAlignment, SLbool vpSameAsVideo)
Sets the viewport ratio and the viewport rectangle.
virtual SLbool onKeyPress(SLKey key, SLKey mod)
AvgFloat _draw3DTimesMS
Averaged time for 3D drawing in ms.
virtual SLbool onMouseDown(SLMouseButton button, SLint scrX, SLint scrY, SLKey mod)
virtual SLbool onTouch2Up(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
SLCamera * _camera
Pointer to the _active camera.
SLDrawBits _drawBits
Sceneview level drawing flags.
SLbool _stopRT
Flag to stop the RT.
SLbool draw3DGL(SLfloat elapsedTimeSec)
Draws the 3D scene with OpenGL.
virtual SLbool onTouch2Down(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
static SLuint drawCalls
NO. of draw calls for shadow mapping.
Interface for ui integration in SLSceneView.
virtual void onMouseDown(SLMouseButton button, SLint x, SLint y)
forward user input to ui
virtual void onPaint(const SLRecti &viewport)
ui render call (called by SLSceneView draw2DGL)
virtual void onMouseMove(SLint xPos, SLint yPos)
forward user input to ui
virtual void init(const string &configPath)
initialization (called by SLSceneView init)
virtual void onKeyPress(SLKey key, SLKey mod)
forward user input to ui
virtual void renderExtraFrame(SLScene *s, SLSceneView *sv, SLint mouseX, SLint mouseY)
virtual bool doNotDispatchKeyboard()
inform if user keyboard input was consumed by the ui
virtual void onResize(const SLRecti &viewportRect)
inform the ui about scene view size change
virtual void onMouseWheel(SLfloat yoffset)
forward user input to ui
virtual void onKeyRelease(SLKey key, SLKey mod)
forward user input to ui
virtual bool doNotDispatchMouse()
inform if user mouse input was consumed by the ui
virtual void onMouseUp(SLMouseButton button, SLint x, SLint y)
forward user input to ui
virtual void onInitNewFrame(SLScene *s, SLSceneView *sv)
prepare the ui for a new rendering, e.g. update visual ui representation (called by SLSceneView onPai...
virtual void onCharInput(SLuint c)
forward user input to ui
virtual void drawMouseCursor(bool doDraw)
Turns on or off the mouse cursor drawing.
void set(const T X, const T Y)
void fromPolar(T r, T phiRAD)
Calculates the vector from polar coords r & phi in radians (-pi < phi < pi)
void init(int numValues, T initValue)
Initializes the average value array to a given value.
void set(T value)
Sets the current value in the value array and builds the average.
void close(SLIOStream *stream)
Closes and deletes a stream.
SLIOStream * open(std::string path, SLIOStreamKind kind, SLIOStreamMode mode)
Opens a file stream for I/O operations.
static const float DEG2RAD
void exitMsg(const char *tag, const char *msg, const int line, const char *file)
Terminates the application with a message. No leak checking.
SLuint numNodesOpaque
NO. of visible opaque nodes.
SLuint numNodes
NO. of children nodes.
void clear()
Resets all counters to zero.
SLuint numNodesBlended
NO. of visible blended nodes.