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.
20 #include <GLES3/gl3.h>
21 #include <LinearMath/btIDebugDraw.h>
22 #include <dali/dali.h>
25 using Dali::CameraActor;
29 using Dali::TextureSet;
31 namespace Dali::Toolkit::Physics::Internal
35 class PhysicsDebugRenderer : public btIDebugDraw
38 // Creates and initializes a new renderer
39 static std::unique_ptr<PhysicsDebugRenderer> New(uint32_t width, uint32_t height, Dali::CameraActor camera, PhysicsAdaptor* adaptor);
42 * Get the callback (for actor creation)
44 std::unique_ptr<Dali::RenderCallback>& GetCallback()
46 return mRenderCallback;
49 void UpdateWindowSize(Dali::Vector2 size);
53 * @param[in] width Width of the renderer - viewport
54 * @param[in] height Height of the renderer - viewport
56 PhysicsDebugRenderer(uint32_t width, uint32_t height, Dali::CameraActor camera, PhysicsAdaptor* adaptor);
58 public: // Inherited from btIDebugDraw
59 // Assume this is called during FrameCallback (i.e. in update manager, rather than during render...)
60 // Generate stack of lines... render, then clear stack.
61 void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override;
62 void drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor) override;
63 void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override;
64 void reportErrorWarning(const char* warningString) override;
65 void draw3dText(const btVector3& location, const char* textString) override;
66 void setDebugMode(int debugMode) override;
67 int getDebugMode() const override;
70 bool OnRender(const Dali::RenderCallbackInput& input);
73 void RenderLines(const Dali::RenderCallbackInput& input);
77 Renderer mDebugRenderer;
78 std::unique_ptr<Dali::RenderCallback> mRenderCallback;
84 } mState{State::INIT};
88 Dali::Vector3 position;
91 std::vector<VertexLine> mLines;
93 Dali::Matrix mModelViewMatrix;
94 Dali::Matrix mViewMatrix;
95 Dali::Matrix mProjectionMatrix;
98 PhysicsAdaptor& mAdaptor;
99 GLint mVertexLocation;
100 GLint mVertexColourLocation;
101 GLint mProjectionLocation;
102 GLint mModelViewLocation;
107 } // namespace Dali::Toolkit::Physics::Internal