From 8b9dbff0ee76087c764215d87f2e4fdbf1d743f7 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Wed, 4 Mar 2026 19:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=83=8F=E7=B4=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/CMakeLists.txt | 2 +- .../src/main/cpp/NativeEGLOCCT/NativeRender.cpp | 16 +++++++++++++++- entry/src/main/cpp/NativeEGLOCCT/NativeRender.h | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/entry/src/main/cpp/CMakeLists.txt b/entry/src/main/cpp/CMakeLists.txt index 61ea1258..311461e8 100644 --- a/entry/src/main/cpp/CMakeLists.txt +++ b/entry/src/main/cpp/CMakeLists.txt @@ -45,7 +45,7 @@ find_library(GLES-lib GLESv3) #System so set(SYSTEM_LIBS - libace_napi.z.so libnative_window.so + libace_napi.z.so libnative_window.so libnative_display_manager.so hilog_ndk.z ace_ndk.z uv z ) diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp index f961ed41..86ac1e9c 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp @@ -55,7 +55,9 @@ bool NativeRender::init(int width, int height,EGLCore* eglCore) { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render", "GL Error before render: 0x%{public}x", glGetError()); return true; } + void NativeRender::initViewer(){ + displayPixelRatio(); Handle(Aspect_DisplayConnection) displayConnection=new Aspect_DisplayConnection(); // 创建图形驱动 if (graphicDriver_.IsNull()) { @@ -69,10 +71,21 @@ void NativeRender::initViewer(){ viewer_->SetDefaultLights(); viewer_->SetLightOn(); } +float NativeRender::displayPixelRatio(){ + float densityPixels; + NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(&densityPixels); + if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "DMSTest", "rotation=%{public}d", densityPixels); + return densityPixels; + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "DMSTest", + "GetDefaultDisplayRotation errCode=%{public}d", errCode); + } +} void NativeRender::initContext(){ context_ = new AIS_InteractiveContext(viewer_); context_->SetDisplayMode(AIS_Shaded, Standard_False); // 默认使用着色模式 - //context_->SetPixelTolerance (int(myDevicePixelRatio * 6.0)); // increase tolerance and adjust to hi-dpi screens + context_->SetPixelTolerance (int(displayPixelRatio() * 6.0)); // increase tolerance and adjust to hi-dpi screens } void NativeRender::initView() { Handle(Aspect_NeutralWindow) m_Window = new Aspect_NeutralWindow(); @@ -81,6 +94,7 @@ void NativeRender::initView() { // 设置渲染参数 view_->SetImmediateUpdate (false); //view_->ChangeRenderingParams().ToShowStats = true; + view_->ChangeRenderingParams().Resolution = (unsigned int )(96.0 * displayPixelRatio() + 0.5); view_->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION; view_->ChangeRenderingParams().IsShadowEnabled = Standard_False; view_->ChangeRenderingParams().IsReflectionEnabled = Standard_False; diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h index b1eac616..8638ac9d 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h @@ -23,6 +23,9 @@ #include "common.h" #include #include "EGLCore.h" +#include +#include + class Aspect_Window; class gp_Quaternion; class Graphic3d_Camera; @@ -44,6 +47,7 @@ public: void setClearColor(float r, float g, float b, float a); void setZoomLevel(float zoom); void setTranslation(float x, float y); + float displayPixelRatio(); private: void initViewer(); void initContext(); @@ -61,11 +65,14 @@ private: float rotationX_; float rotationY_; + float rotationZ_; + float zoomLevel_; int width_; int height_; float translationX_; float translationY_; + float translationZ_; Quantity_Color clearColor_; }; } // namespace NativeRender