增加一些日志输出.修改对EGLCore的初始化

This commit is contained in:
JackLee 2026-03-02 14:17:43 +08:00
parent 5c2e32b0d9
commit 1aaf8cfa89
6 changed files with 38 additions and 32 deletions

View File

@ -37,8 +37,7 @@ add_library(opencax SHARED
NativeEGLOCCT/NativeRender.cpp
NativeEGLOCCT/NativeRenderThread.cpp
NativeEGLOCCT/NativeManager.cpp
napi_init.cpp
)
napi_init.cpp)
#
find_library(EGL-lib EGL)

View File

@ -1,6 +1,5 @@
#include "EGLCore.h"
#include <cstdio>
#include <cstring>
#include "NativeEGLOCCT/common.h"
namespace NativeOpenCAX {
@ -20,14 +19,13 @@ bool EGLCore::init(OHNativeWindow* window) {
printf("Native window is null\n");
return false;
}
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore","Current Thread ID: %{public}d",std::this_thread::get_id());
nativeWindow_ = window;
// 获取EGL display
eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (eglDisplay_ == EGL_NO_DISPLAY) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglGetDisplay failed:%{public}d",std::this_thread::get_id());
return false;
}
@ -38,6 +36,7 @@ bool EGLCore::init(OHNativeWindow* window) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglInitialize failed:%{public}d",std::this_thread::get_id());
return false;
}
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","EGLDisplay version:%{public}d",majorVersion+"."+minorVersion);
// 配置EGL
EGLint attribs[] = {
@ -62,7 +61,6 @@ bool EGLCore::init(OHNativeWindow* window) {
// 创建EGL surface
eglSurface_ = eglCreateWindowSurface(eglDisplay_, eglConfig_, (NativeWindowType)nativeWindow_, nullptr);
if (eglSurface_ == EGL_NO_SURFACE) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglCreateWindowSurface failed:%{public}d",std::this_thread::get_id());
return false;
}
@ -74,7 +72,6 @@ bool EGLCore::init(OHNativeWindow* window) {
eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs);
if (eglContext_ == EGL_NO_CONTEXT) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglCreateContext failed:%{public}d",std::this_thread::get_id());
return false;
}
@ -84,13 +81,11 @@ bool EGLCore::init(OHNativeWindow* window) {
// 检查GL错误
GLenum glError = glGetError();
if (glError != GL_NO_ERROR) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","OpenGL error after initialization:%{public}d",glError);
return false;
}
// 设置GL视口
glViewport(0, 0, 1280, 720); // 默认大小,实际会随窗口变化
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInitDone","Thread ID: %{public}d",std::this_thread::get_id());
return true;
}

View File

@ -31,6 +31,8 @@ public:
EGLSurface getSurface() const { return eglSurface_; }
EGLContext getContext() const { return eglContext_; }
EGLDisplay getDisplay() const { return eglDisplay_; }
EGLConfig getConfig() const { return eglConfig_; }
OHNativeWindow* getOHNativeWindow()const{return nativeWindow_;}
private:
EGLDisplay eglDisplay_;
EGLContext eglContext_;

View File

@ -10,10 +10,10 @@
#include <Prs3d_ShadingAspect.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <Graphic3d_NameOfMaterial.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <V3d_TypeOfOrientation.hxx>
#include <Aspect_TypeOfTriedronPosition.hxx>
@ -23,8 +23,8 @@ NativeRender::NativeRender()
: rotationX_(0.0f),
rotationY_(0.0f),
zoomLevel_(1.0f),
width_(0),
height_(0),
width_(1280),
height_(720),
clearColor_(Quantity_NOC_BLACK),
translationX_(0.0f),
translationY_(0.0f)
@ -36,7 +36,8 @@ NativeRender::~NativeRender() {
shapes_.clear();
}
bool NativeRender::init(int width, int height) {
bool NativeRender::init(int width, int height,EGLCore* eglCore) {
eglCore_=eglCore;
setupViewer();
setupContext();
setupView();
@ -47,7 +48,8 @@ bool NativeRender::init(int width, int height) {
}
view_->SetBackgroundColor(clearColor_);
view_->MustBeResized();
view_->Redraw();
//view_->Redraw();
view_->RedrawImmediate();
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","NativeRender Init Done");
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","width: %{public}d",width_);
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","height: %{public}d",height_);
@ -55,11 +57,15 @@ bool NativeRender::init(int width, int height) {
}
void NativeRender::setupViewer() {
Handle(Aspect_DisplayConnection) displayConnection;
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRender setupViewer","Current Thread ID: %{public}d",std::this_thread::get_id());
Handle(Aspect_DisplayConnection) displayConnection=new Aspect_DisplayConnection();
displayConnection->Init((Aspect_XDisplay*)eglGetCurrentDisplay());
// 创建图形驱动
if (graphicDriver_.IsNull()) {
graphicDriver_ = new OpenGl_GraphicDriver(displayConnection,Standard_False);
graphicDriver_->ChangeOptions().buffersNoSwap = Standard_True;
graphicDriver_->InitEglContext(eglCore_->getDisplay(), eglCore_->getContext(), eglCore_->getConfig());
}
// 创建V3d_Viewer
viewer_ = new V3d_Viewer(graphicDriver_);
@ -80,7 +86,6 @@ void NativeRender::setupView() {
view_->ChangeRenderingParams().IsReflectionEnabled = Standard_False;
view_->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
view_->ChangeRenderingParams().Resolution = 2;
// 设置背景渐变
view_->SetBgGradientColors(
Quantity_Color(Quantity_NOC_GRAY),
@ -156,7 +161,6 @@ bool NativeRender::loadModel(const std::string& filePath) {
shapes_.push_back(aisShape);
}
}
// 调整相机到合适位置
view_->FitAll(0.05, Standard_True);
view_->ZFitAll();
@ -221,8 +225,9 @@ void NativeRender::render() {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render","View Is Null");
return;
}
//glClearColor(1, 0, 0, 1);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width_, height_);
// 应用旋转
Handle(Graphic3d_Camera) camera = view_->Camera();

View File

@ -16,20 +16,25 @@
#include <Message.hxx>
#include <Quantity_Color.hxx>
#include <gp_Quaternion.hxx>
#include <OpenGl_Window.hxx>
#include <gp_EulerSequence.hxx>
#include <Aspect_Handle.hxx>
#include <ace/xcomponent/native_interface_xcomponent.h>
#include "common.h"
#include <EGL/egl.h>
#include "EGLCore.h"
class Aspect_Window;
class gp_Quaternion;
class Graphic3d_Camera;
namespace NativeOpenCAX {
class NativeRender {
public:
NativeRender();
~NativeRender();
bool init(int width, int height);
bool init(int width, int height,EGLCore* eglCore);
bool loadModel(const std::string& filePath);
void loadDefaultModel();
void render();
@ -39,13 +44,13 @@ public:
void setClearColor(float r, float g, float b, float a);
void setZoomLevel(float zoom);
void setTranslation(float x, float y);
private:
void setupViewer();
void setupContext();
void setupView();
// Bind existing EGL display/context to OCCT OpenGl driver
//void loadDefaultModel();
EGLCore* eglCore_;
Handle(OpenGl_GraphicDriver) graphicDriver_;
Handle(V3d_Viewer) viewer_;
Handle(V3d_View) view_;

View File

@ -57,7 +57,7 @@ void NativeRenderThread::renderLoop() {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
}
// 初始化OCCT渲染器
if (!renderer_.init(windowWidth_, windowHeight_)) {
if (!renderer_.init(windowWidth_, windowHeight_,eglCore_)) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer");
eglCore_->destroy();
}