4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <GLES3/gl3.h>
20 #include <chipmunk/chipmunk.h>
21 #include <dali/dali.h>
24 using Dali::CameraActor;
28 using Dali::TextureSet;
30 namespace Dali::Toolkit::Physics::Internal
34 class PhysicsDebugRenderer
37 // Creates and initializes a new renderer
38 static std::unique_ptr<PhysicsDebugRenderer> New(uint32_t width, uint32_t height, Dali::CameraActor camera, PhysicsAdaptor* adaptor);
40 * Get the callback (for actor creation)
43 std::unique_ptr<Dali::RenderCallback>& GetCallback()
45 return mRenderCallback;
48 void UpdateWindowSize(Dali::Vector2 size);
52 * @param[in] width Width of the renderer - viewport
53 * @param[in] height Height of the renderer - viewport
55 PhysicsDebugRenderer(uint32_t width, uint32_t height, Dali::CameraActor camera, PhysicsAdaptor* adaptor);
58 * Get the drawing options struct ( construct only )
60 const cpSpaceDebugDrawOptions& GetDebugDrawOptions()
62 return mDebugDrawOptions;
67 Dali::Vector2 position;
70 Dali::Vector4 fillColor;
71 Dali::Vector4 outlineColor;
74 public: // Debug functions (Creates indices & verts)
75 void DrawCircle(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
76 void DrawSegment(cpVect a, cpVect b, cpSpaceDebugColor color);
77 void DrawFatSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
78 void DrawPolygon(int count, const cpVect* verts, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
79 void DrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor color);
80 cpSpaceDebugColor DrawColorForShape(cpShape* shape);
83 bool OnRender(const Dali::RenderCallbackInput& input);
86 void RenderLines(const Dali::RenderCallbackInput& input);
88 Vertex* PushVertices(uint32_t vertexCount, uint32_t indexCount, const uint16_t* indices);
89 Vertex MakeVertex(cpVect pos, float u, float v, float r, Vector4 fill, Vector4 outline);
93 cpSpaceDebugDrawOptions mDebugDrawOptions;
94 Renderer mDebugRenderer;
95 std::unique_ptr<Dali::RenderCallback> mRenderCallback;
101 } mState{State::INIT};
103 std::vector<Vertex> mVertices;
104 std::vector<uint16_t> mIndices;
106 Dali::Matrix mModelViewMatrix;
107 Dali::Matrix mViewMatrix;
108 Dali::Matrix mProjectionMatrix;
111 PhysicsAdaptor& mAdaptor;
113 float mPointLineScale{2.0f};
114 GLint mPositionLocation;
116 GLint mRadiusLocation;
117 GLint mFillColourLocation;
118 GLint mOutlineColourLocation;
119 GLint mProjectionLocation;
120 GLint mModelViewLocation;
121 GLuint mIndexBufferId;
122 GLuint mVertexBufferId;
126 } // namespace Dali::Toolkit::Physics::Internal