RavEngine
Loading...
Searching...
No Matches
CmRenderBuffer.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 CM_RENDER_BUFFER_H
30#define CM_RENDER_BUFFER_H
31
32#include "common/PxRenderBuffer.h"
33#include "CmUtils.h"
34#include "foundation/PxArray.h"
35#include "foundation/PxUserAllocated.h"
36
37namespace physx
38{
39namespace Cm
40{
45 {
46
47 template <typename T>
48 void append(PxArray<T>& dst, const T* src, PxU32 count)
49 {
50 dst.reserve(dst.size() + count);
51 for(const T* end=src+count; src<end; ++src)
52 dst.pushBack(*src);
53 }
54
55 public:
56
57 RenderBuffer() :
58 mPoints("renderBufferPoints"),
59 mLines("renderBufferLines"),
60 mTriangles("renderBufferTriangles")
61 {}
62
63
64 virtual PxU32 getNbPoints() const { return mPoints.size(); }
65 virtual const PxDebugPoint* getPoints() const { return mPoints.begin(); }
66 virtual void addPoint(const PxDebugPoint& point) { mPoints.pushBack(point); }
67
68 virtual PxU32 getNbLines() const { return mLines.size(); }
69 virtual const PxDebugLine* getLines() const { return mLines.begin(); }
70 virtual void addLine(const PxDebugLine& line) { mLines.pushBack(line); }
71 virtual PxDebugLine* reserveLines(const PxU32 nbLines) {return reserveContainerMemory(mLines, nbLines);}
72
73 virtual PxDebugPoint* reservePoints(const PxU32 nbPoints) { return reserveContainerMemory(mPoints, nbPoints); }
74
75 virtual PxU32 getNbTriangles() const { return mTriangles.size(); }
76 virtual const PxDebugTriangle* getTriangles() const { return mTriangles.begin(); }
77 virtual void addTriangle(const PxDebugTriangle& triangle) { mTriangles.pushBack(triangle); }
78
79 virtual void append(const PxRenderBuffer& other)
80 {
81 append(mPoints, other.getPoints(), other.getNbPoints());
82 append(mLines, other.getLines(), other.getNbLines());
83 append(mTriangles, other.getTriangles(), other.getNbTriangles());
84 }
85
86 virtual void clear()
87 {
88 mPoints.clear();
89 mLines.clear();
90 mTriangles.clear();
91 }
92
93 virtual bool empty() const
94 {
95 return mPoints.empty() && mLines.empty() && mTriangles.empty();
96 }
97
98 virtual void shift(const PxVec3& delta)
99 {
100 for(PxU32 i=0; i < mPoints.size(); i++)
101 mPoints[i].pos += delta;
102
103 for(PxU32 i=0; i < mLines.size(); i++)
104 {
105 mLines[i].pos0 += delta;
106 mLines[i].pos1 += delta;
107 }
108
109 for(PxU32 i=0; i < mTriangles.size(); i++)
110 {
111 mTriangles[i].pos0 += delta;
112 mTriangles[i].pos1 += delta;
113 mTriangles[i].pos2 += delta;
114 }
115 }
116
117 PxArray<PxDebugPoint> mPoints;
119 PxArray<PxDebugTriangle> mTriangles;
120 };
121
122} // Cm
123
124}
125
126#endif
Definition CmRenderBuffer.h:45
Definition PxArray.h:53
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
PX_INLINE void reserve(const uint32_t capacity)
Definition PxArray.h:486
Interface for points, lines, triangles, and text buffer.
Definition PxRenderBuffer.h:136
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Used to store a single line and colour for debug rendering.
Definition PxRenderBuffer.h:85
Used to store a single point and colour for debug rendering.
Definition PxRenderBuffer.h:73
Used to store a single triangle and colour for debug rendering.
Definition PxRenderBuffer.h:99