增加一些日志输出.修改对EGLCore的初始化
This commit is contained in:
parent
5c2e32b0d9
commit
1aaf8cfa89
@ -37,8 +37,7 @@ add_library(opencax SHARED
|
|||||||
NativeEGLOCCT/NativeRender.cpp
|
NativeEGLOCCT/NativeRender.cpp
|
||||||
NativeEGLOCCT/NativeRenderThread.cpp
|
NativeEGLOCCT/NativeRenderThread.cpp
|
||||||
NativeEGLOCCT/NativeManager.cpp
|
NativeEGLOCCT/NativeManager.cpp
|
||||||
napi_init.cpp
|
napi_init.cpp)
|
||||||
)
|
|
||||||
|
|
||||||
# 查找系统库
|
# 查找系统库
|
||||||
find_library(EGL-lib EGL)
|
find_library(EGL-lib EGL)
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#include "EGLCore.h"
|
#include "EGLCore.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
|
||||||
#include "NativeEGLOCCT/common.h"
|
#include "NativeEGLOCCT/common.h"
|
||||||
|
|
||||||
namespace NativeOpenCAX {
|
namespace NativeOpenCAX {
|
||||||
@ -20,14 +19,13 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
printf("Native window is null\n");
|
printf("Native window is null\n");
|
||||||
return false;
|
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;
|
nativeWindow_ = window;
|
||||||
|
|
||||||
// 获取EGL display
|
// 获取EGL display
|
||||||
eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
if (eglDisplay_ == EGL_NO_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());
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglGetDisplay failed:%{public}d",std::this_thread::get_id());
|
||||||
|
|
||||||
return false;
|
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());
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglInitialize failed:%{public}d",std::this_thread::get_id());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","EGLDisplay version:%{public}d",majorVersion+"."+minorVersion);
|
||||||
|
|
||||||
// 配置EGL
|
// 配置EGL
|
||||||
EGLint attribs[] = {
|
EGLint attribs[] = {
|
||||||
@ -62,7 +61,6 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
// 创建EGL surface
|
// 创建EGL surface
|
||||||
eglSurface_ = eglCreateWindowSurface(eglDisplay_, eglConfig_, (NativeWindowType)nativeWindow_, nullptr);
|
eglSurface_ = eglCreateWindowSurface(eglDisplay_, eglConfig_, (NativeWindowType)nativeWindow_, nullptr);
|
||||||
if (eglSurface_ == EGL_NO_SURFACE) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +72,6 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
|
|
||||||
eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs);
|
eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs);
|
||||||
if (eglContext_ == EGL_NO_CONTEXT) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +81,11 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
// 检查GL错误
|
// 检查GL错误
|
||||||
GLenum glError = glGetError();
|
GLenum glError = glGetError();
|
||||||
if (glError != GL_NO_ERROR) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置GL视口
|
// 设置GL视口
|
||||||
glViewport(0, 0, 1280, 720); // 默认大小,实际会随窗口变化
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,8 @@ public:
|
|||||||
EGLSurface getSurface() const { return eglSurface_; }
|
EGLSurface getSurface() const { return eglSurface_; }
|
||||||
EGLContext getContext() const { return eglContext_; }
|
EGLContext getContext() const { return eglContext_; }
|
||||||
EGLDisplay getDisplay() const { return eglDisplay_; }
|
EGLDisplay getDisplay() const { return eglDisplay_; }
|
||||||
|
EGLConfig getConfig() const { return eglConfig_; }
|
||||||
|
OHNativeWindow* getOHNativeWindow()const{return nativeWindow_;}
|
||||||
private:
|
private:
|
||||||
EGLDisplay eglDisplay_;
|
EGLDisplay eglDisplay_;
|
||||||
EGLContext eglContext_;
|
EGLContext eglContext_;
|
||||||
|
|||||||
@ -10,10 +10,10 @@
|
|||||||
#include <Prs3d_ShadingAspect.hxx>
|
#include <Prs3d_ShadingAspect.hxx>
|
||||||
#include <Graphic3d_MaterialAspect.hxx>
|
#include <Graphic3d_MaterialAspect.hxx>
|
||||||
#include <Graphic3d_NameOfMaterial.hxx>
|
#include <Graphic3d_NameOfMaterial.hxx>
|
||||||
|
#include <Graphic3d_TextureEnv.hxx>
|
||||||
#include <BRepPrimAPI_MakeBox.hxx>
|
#include <BRepPrimAPI_MakeBox.hxx>
|
||||||
#include <BRepPrimAPI_MakeSphere.hxx>
|
#include <BRepPrimAPI_MakeSphere.hxx>
|
||||||
#include <BRepPrimAPI_MakeCylinder.hxx>
|
#include <BRepPrimAPI_MakeCylinder.hxx>
|
||||||
#include <Graphic3d_TextureEnv.hxx>
|
|
||||||
#include <V3d_TypeOfOrientation.hxx>
|
#include <V3d_TypeOfOrientation.hxx>
|
||||||
#include <Aspect_TypeOfTriedronPosition.hxx>
|
#include <Aspect_TypeOfTriedronPosition.hxx>
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ NativeRender::NativeRender()
|
|||||||
: rotationX_(0.0f),
|
: rotationX_(0.0f),
|
||||||
rotationY_(0.0f),
|
rotationY_(0.0f),
|
||||||
zoomLevel_(1.0f),
|
zoomLevel_(1.0f),
|
||||||
width_(0),
|
width_(1280),
|
||||||
height_(0),
|
height_(720),
|
||||||
clearColor_(Quantity_NOC_BLACK),
|
clearColor_(Quantity_NOC_BLACK),
|
||||||
translationX_(0.0f),
|
translationX_(0.0f),
|
||||||
translationY_(0.0f)
|
translationY_(0.0f)
|
||||||
@ -36,7 +36,8 @@ NativeRender::~NativeRender() {
|
|||||||
shapes_.clear();
|
shapes_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeRender::init(int width, int height) {
|
bool NativeRender::init(int width, int height,EGLCore* eglCore) {
|
||||||
|
eglCore_=eglCore;
|
||||||
setupViewer();
|
setupViewer();
|
||||||
setupContext();
|
setupContext();
|
||||||
setupView();
|
setupView();
|
||||||
@ -47,7 +48,8 @@ bool NativeRender::init(int width, int height) {
|
|||||||
}
|
}
|
||||||
view_->SetBackgroundColor(clearColor_);
|
view_->SetBackgroundColor(clearColor_);
|
||||||
view_->MustBeResized();
|
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","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","width: %{public}d",width_);
|
||||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","height: %{public}d",height_);
|
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() {
|
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()) {
|
if (graphicDriver_.IsNull()) {
|
||||||
graphicDriver_ = new OpenGl_GraphicDriver(displayConnection, Standard_False);
|
graphicDriver_ = new OpenGl_GraphicDriver(displayConnection,Standard_False);
|
||||||
graphicDriver_->ChangeOptions().buffersNoSwap = Standard_True;
|
graphicDriver_->ChangeOptions().buffersNoSwap = Standard_True;
|
||||||
|
graphicDriver_->InitEglContext(eglCore_->getDisplay(), eglCore_->getContext(), eglCore_->getConfig());
|
||||||
}
|
}
|
||||||
// 创建V3d_Viewer
|
// 创建V3d_Viewer
|
||||||
viewer_ = new V3d_Viewer(graphicDriver_);
|
viewer_ = new V3d_Viewer(graphicDriver_);
|
||||||
@ -80,7 +86,6 @@ void NativeRender::setupView() {
|
|||||||
view_->ChangeRenderingParams().IsReflectionEnabled = Standard_False;
|
view_->ChangeRenderingParams().IsReflectionEnabled = Standard_False;
|
||||||
view_->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
|
view_->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
|
||||||
view_->ChangeRenderingParams().Resolution = 2;
|
view_->ChangeRenderingParams().Resolution = 2;
|
||||||
|
|
||||||
// 设置背景渐变
|
// 设置背景渐变
|
||||||
view_->SetBgGradientColors(
|
view_->SetBgGradientColors(
|
||||||
Quantity_Color(Quantity_NOC_GRAY),
|
Quantity_Color(Quantity_NOC_GRAY),
|
||||||
@ -156,7 +161,6 @@ bool NativeRender::loadModel(const std::string& filePath) {
|
|||||||
shapes_.push_back(aisShape);
|
shapes_.push_back(aisShape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调整相机到合适位置
|
// 调整相机到合适位置
|
||||||
view_->FitAll(0.05, Standard_True);
|
view_->FitAll(0.05, Standard_True);
|
||||||
view_->ZFitAll();
|
view_->ZFitAll();
|
||||||
@ -221,8 +225,9 @@ void NativeRender::render() {
|
|||||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render","View Is Null");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render","View Is Null");
|
||||||
return;
|
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_);
|
glViewport(0, 0, width_, height_);
|
||||||
// 应用旋转
|
// 应用旋转
|
||||||
Handle(Graphic3d_Camera) camera = view_->Camera();
|
Handle(Graphic3d_Camera) camera = view_->Camera();
|
||||||
|
|||||||
@ -16,20 +16,25 @@
|
|||||||
#include <Message.hxx>
|
#include <Message.hxx>
|
||||||
#include <Quantity_Color.hxx>
|
#include <Quantity_Color.hxx>
|
||||||
#include <gp_Quaternion.hxx>
|
#include <gp_Quaternion.hxx>
|
||||||
|
#include <OpenGl_Window.hxx>
|
||||||
#include <gp_EulerSequence.hxx>
|
#include <gp_EulerSequence.hxx>
|
||||||
|
#include <Aspect_Handle.hxx>
|
||||||
#include <ace/xcomponent/native_interface_xcomponent.h>
|
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include "EGLCore.h"
|
||||||
class Aspect_Window;
|
class Aspect_Window;
|
||||||
class gp_Quaternion;
|
class gp_Quaternion;
|
||||||
class Graphic3d_Camera;
|
class Graphic3d_Camera;
|
||||||
|
|
||||||
|
|
||||||
namespace NativeOpenCAX {
|
namespace NativeOpenCAX {
|
||||||
class NativeRender {
|
class NativeRender {
|
||||||
public:
|
public:
|
||||||
NativeRender();
|
NativeRender();
|
||||||
~NativeRender();
|
~NativeRender();
|
||||||
|
|
||||||
bool init(int width, int height);
|
bool init(int width, int height,EGLCore* eglCore);
|
||||||
bool loadModel(const std::string& filePath);
|
bool loadModel(const std::string& filePath);
|
||||||
void loadDefaultModel();
|
void loadDefaultModel();
|
||||||
void render();
|
void render();
|
||||||
@ -39,13 +44,13 @@ public:
|
|||||||
void setClearColor(float r, float g, float b, float a);
|
void setClearColor(float r, float g, float b, float a);
|
||||||
void setZoomLevel(float zoom);
|
void setZoomLevel(float zoom);
|
||||||
void setTranslation(float x, float y);
|
void setTranslation(float x, float y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupViewer();
|
void setupViewer();
|
||||||
void setupContext();
|
void setupContext();
|
||||||
void setupView();
|
void setupView();
|
||||||
|
// Bind existing EGL display/context to OCCT OpenGl driver
|
||||||
//void loadDefaultModel();
|
//void loadDefaultModel();
|
||||||
|
EGLCore* eglCore_;
|
||||||
Handle(OpenGl_GraphicDriver) graphicDriver_;
|
Handle(OpenGl_GraphicDriver) graphicDriver_;
|
||||||
Handle(V3d_Viewer) viewer_;
|
Handle(V3d_Viewer) viewer_;
|
||||||
Handle(V3d_View) view_;
|
Handle(V3d_View) view_;
|
||||||
|
|||||||
@ -57,7 +57,7 @@ void NativeRenderThread::renderLoop() {
|
|||||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
|
||||||
}
|
}
|
||||||
// 初始化OCCT渲染器
|
// 初始化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");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer");
|
||||||
eglCore_->destroy();
|
eglCore_->destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user