RavEngine
Loading...
Searching...
No Matches
SnippetRender.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PHYSX_SNIPPET_RENDER_H
30#define PHYSX_SNIPPET_RENDER_H
31
32#include "PxPhysicsAPI.h"
33#include "foundation/PxPreprocessor.h"
34
35#if PX_WINDOWS
36 #include <windows.h>
37 #pragma warning(disable: 4505)
38 #include <GL/glew.h>
39 #include <GL/freeglut.h>
40#elif PX_LINUX_FAMILY
41 #if PX_CLANG
42 #pragma clang diagnostic push
43 #pragma clang diagnostic ignored "-Wreserved-identifier"
44 #endif
45 #include <GL/glew.h>
46 #include <GL/freeglut.h>
47 #if PX_CLANG
48 #pragma clang diagnostic pop
49 #endif
50#elif PX_OSX
51 #include <GL/glew.h>
52 #include <GLUT/glut.h>
53#else
54 #error platform not supported.
55#endif
56
57typedef void (*KeyboardCallback) (unsigned char key, const physx::PxTransform& camera);
58typedef void (*RenderCallback) ();
59typedef void (*ExitCallback) ();
60
61namespace Snippets
62{
63 class Camera;
64 void setupDefault(const char* name, Camera* camera, KeyboardCallback kbcb, RenderCallback rdcb, ExitCallback excb);
65 Camera* getCamera();
66 physx::PxVec3 computeWorldRayF(float xs, float ys, const physx::PxVec3& camDir);
67 PX_FORCE_INLINE physx::PxVec3 computeWorldRay(int xs, int ys, const physx::PxVec3& camDir)
68 {
69 return computeWorldRayF(float(xs), float(ys), camDir);
70 }
71
72 physx::PxU32 getScreenWidth();
73 physx::PxU32 getScreenHeight();
74
75 void enableVSync(bool vsync);
76
77 void startRender(const Camera* camera, float nearClip = 1.0f, float farClip = 10000.0f, float fov=60.0f, bool setupLighting=true);
78 void finishRender();
79 void print(const char* text);
80
82 {
83 public:
84 virtual bool isTrigger(physx::PxShape*) const = 0;
85 };
86
87#if PX_SUPPORT_GPU_PHYSX
88 class SharedGLBuffer
89 {
90 public:
91 SharedGLBuffer();
92 ~SharedGLBuffer();
93 void initialize(physx::PxCudaContextManager* contextManager);
94 void allocate(physx::PxU32 sizeInBytes);
95 void release();
96 void* map();
97 void unmap();
98
99 private:
100 physx::PxCudaContextManager* cudaContextManager;
101 void* vbo_res;
102 void* devicePointer;
103 public:
104 GLuint vbo; //Opengl vertex buffer object
105 physx::PxU32 size;
106 };
107#endif
108
109 void initFPS();
110 void showFPS(int updateIntervalMS = 30, const char* info = NULL);
111
112 void renderSoftBody(physx::PxSoftBody* softBody, const physx::PxArray<physx::PxVec4>& deformedPositionsInvMass, bool shadows, const physx::PxVec3& color = physx::PxVec3(0.0f, 0.75f, 0.0f));
113 void renderActors(physx::PxRigidActor** actors, const physx::PxU32 numActors, bool shadows = false, const physx::PxVec3& color = physx::PxVec3(0.0f, 0.75f, 0.0f), TriggerRender* cb = NULL, bool changeColorForSleepingActors = true, bool wireframePass=true);
114// void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometry* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color);
115 void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometryHolder* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color);
116 void renderMesh(physx::PxU32 nbVerts, const physx::PxVec3* verts, physx::PxU32 nbTris, const physx::PxU32* indices, const physx::PxVec3& color, const physx::PxVec3* normals = NULL, bool flipFaceOrientation = false);
117 void renderMesh(physx::PxU32 nbVerts, const physx::PxVec4* verts, physx::PxU32 nbTris, const physx::PxU32* indices, const physx::PxVec3& color, const physx::PxVec4* normals = NULL, bool flipFaceOrientation = false);
118 void renderHairSystem(physx::PxHairSystem* hairSystem, const physx::PxVec4* vertexPositionInvMass, physx::PxU32 numVertices);
119
120 void DrawLine(const physx::PxVec3& p0, const physx::PxVec3& p1, const physx::PxVec3& color);
121 void DrawPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxVec3& color, float scale);
122 void DrawPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxArray<physx::PxVec3>& colors, float scale);
123 void DrawPoints(const physx::PxArray<physx::PxVec4>& pts, const physx::PxVec3& color, float scale);
124 void DrawPoints(const physx::PxArray<physx::PxVec4>& pts, const physx::PxArray<physx::PxVec3>& colors, float scale);
125 void DrawPoints(GLuint vbo, physx::PxU32 numPoints, const physx::PxVec3& color, float scale, physx::PxU32 coordinatesPerPoint = 3, physx::PxU32 stride = 4 * sizeof(float), size_t offset = 0);
126
127 void DrawLines(GLuint vbo, physx::PxU32 numPoints, const physx::PxVec3& color, float scale, physx::PxU32 coordinatesPerPoint = 3, physx::PxU32 stride = 4 * sizeof(float), size_t offset = 0);
128
129 void DrawIcosahedraPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxVec3& color, float radius);
130 void DrawFrame(const physx::PxVec3& pt, float scale=1.0f);
131 void DrawBounds(const physx::PxBounds3& box);
132 void DrawBounds(const physx::PxBounds3& box, const physx::PxVec3& color);
133 void DrawMeshIndexedNoNormals(GLuint vbo, GLuint elementbuffer, GLuint numTriangles, const physx::PxVec3& color, physx::PxU32 stride = 4 * sizeof(float));
134 void DrawMeshIndexed(GLuint vbo, GLuint elementbuffer, GLuint numTriangles, const physx::PxVec3& color, physx::PxU32 stride = 6 * sizeof(float));
135
136 GLuint CreateTexture(physx::PxU32 width, physx::PxU32 height, const GLubyte* buffer, bool createMipmaps);
137 void UpdateTexture(GLuint texId, physx::PxU32 width, physx::PxU32 height, const GLubyte* buffer, bool createMipmaps);
138 void ReleaseTexture(GLuint texId);
139 void DrawRectangle(float x_start, float x_end, float y_start, float y_end, const physx::PxVec3& color_top, const physx::PxVec3& color_bottom, float alpha, physx::PxU32 screen_width, physx::PxU32 screen_height, bool draw_outline, bool texturing);
140 void DisplayTexture(GLuint texId, physx::PxU32 size, physx::PxU32 margin);
141}
142
143#endif //PHYSX_SNIPPET_RENDER_H
Definition camera.h:37
Definition SnippetRender.h:82
Definition PxArray.h:53
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Geometry holder class.
Definition PxGeometryHelpers.h:66
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Abstract class for collision shapes.
Definition PxShape.h:146
Represents a FEM softbody including everything to calculate its definition like geometry and material...
Definition PxSoftBody.h:104
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
Definition PxVec4.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335