1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_RENDER_3D_WIDGET_ADAPTER_H 17 #define OHOS_RENDER_3D_WIDGET_ADAPTER_H 18 19 #include <memory> 20 #include <EGL/egl.h> 21 #include <GLES/gl.h> 22 23 #include "i_engine.h" 24 #include "data_type/constants.h" 25 #include "data_type/geometry/geometry.h" 26 #include "data_type/geometry/cube.h" 27 #include "data_type/geometry/sphere.h" 28 #include "data_type/geometry/cone.h" 29 #include "data_type/gltf_animation.h" 30 #include "data_type/pointer_event.h" 31 32 namespace OHOS::Render3D { 33 34 class __attribute__((visibility("default"))) WidgetAdapter { 35 public: 36 explicit WidgetAdapter(uint32_t key); 37 virtual ~WidgetAdapter(); 38 void DeInitEngine(); 39 WidgetAdapter(const WidgetAdapter&) = delete; 40 WidgetAdapter& operator=(const WidgetAdapter&) = delete; 41 42 bool Initialize(std::unique_ptr<IEngine> engine); 43 bool OnWindowChange(const TextureInfo& textureInfo); 44 45 bool SetupCameraTransform(const OHOS::Render3D::Position& position, const OHOS::Render3D::Vec3& lookAt, 46 const OHOS::Render3D::Vec3& up, const OHOS::Render3D::Quaternion& rotation); 47 bool SetupCameraViewProjection(float zNear, float zFar, float fovDegrees); 48 bool SetupCameraViewport(uint32_t width, uint32_t height); 49 50 bool OnTouchEvent(const PointerEvent& event); 51 bool NeedsRepaint(); 52 53 bool DrawFrame(); 54 bool UpdateGeometries(const std::vector<std::shared_ptr<Geometry>>& shapes); 55 bool UpdateGLTFAnimations(const std::vector<std::shared_ptr<GLTFAnimation>>& animations); 56 57 bool UpdateLights(const std::vector<std::shared_ptr<OHOS::Render3D::Light>>& lights); 58 bool UpdateCustomRender(const std::shared_ptr<CustomRenderDescriptor>& customRender); 59 bool UpdateShaderPath(const std::string& shaderPath); 60 bool UpdateImageTexturePaths(const std::vector<std::string>& imageTextures); 61 bool UpdateShaderInputBuffer(const std::shared_ptr<OHOS::Render3D::ShaderInputBuffer>& shaderInputBuffer); 62 63 bool LoadSceneModel(const std::string& scene); 64 bool LoadEnvModel(const std::string& enviroment, BackgroundType type); 65 bool UnloadSceneModel(); 66 bool UnloadEnvModel(); 67 68 private: 69 std::unique_ptr<IEngine> engine_ = nullptr; 70 uint32_t key_; 71 }; 72 } // namespace OHOS::Render3D 73 #endif // OHOS_RENDER_3D_WIDGET_ADAPTER_H 74