增加一些日志输出.
This commit is contained in:
parent
acb34c3b4d
commit
5c2e32b0d9
@ -1,6 +1,7 @@
|
|||||||
#include "EGLCore.h"
|
#include "EGLCore.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include "NativeEGLOCCT/common.h"
|
||||||
|
|
||||||
namespace NativeOpenCAX {
|
namespace NativeOpenCAX {
|
||||||
|
|
||||||
@ -25,13 +26,16 @@ bool EGLCore::init(OHNativeWindow* 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) {
|
||||||
printf("eglGetDisplay failed\n");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglGetDisplay failed:%{public}d",std::this_thread::get_id());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化EGL
|
// 初始化EGL
|
||||||
if (!eglInitialize(eglDisplay_, nullptr, nullptr)) {
|
EGLint majorVersion;
|
||||||
printf("eglInitialize failed\n");
|
EGLint minorVersion;
|
||||||
|
if (!eglInitialize(eglDisplay_, &majorVersion, &minorVersion)) {
|
||||||
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglInitialize failed:%{public}d",std::this_thread::get_id());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,16 +52,17 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const EGLint maxConfigSize = 1;
|
||||||
EGLint numConfigs;
|
EGLint numConfigs;
|
||||||
if (!eglChooseConfig(eglDisplay_, attribs, &eglConfig_, 1, &numConfigs) || numConfigs == 0) {
|
if (!eglChooseConfig(eglDisplay_, attribs, &eglConfig_, maxConfigSize, &numConfigs)) {
|
||||||
printf("eglChooseConfig failed\n");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglChooseConfig: unable to choose configs");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建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) {
|
||||||
printf("eglCreateWindowSurface failed: 0x%x\n", eglGetError());
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglCreateWindowSurface failed:%{public}d",std::this_thread::get_id());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +74,7 @@ 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) {
|
||||||
printf("eglCreateContext failed\n");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","eglCreateContext failed:%{public}d",std::this_thread::get_id());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,19 +84,19 @@ bool EGLCore::init(OHNativeWindow* window) {
|
|||||||
// 检查GL错误
|
// 检查GL错误
|
||||||
GLenum glError = glGetError();
|
GLenum glError = glGetError();
|
||||||
if (glError != GL_NO_ERROR) {
|
if (glError != GL_NO_ERROR) {
|
||||||
printf("OpenGL error after initialization: 0x%x\n", glError);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLCore::makeCurrent() {
|
void EGLCore::makeCurrent() {
|
||||||
if (!eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_)) {
|
if (!eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_)) {
|
||||||
printf("eglMakeCurrent failed: 0x%x\n", eglGetError());
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInitDone","eglMakeCurrent failed: 0x%{public}x\n",eglGetError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,8 @@ public:
|
|||||||
bool swapBuffers();
|
bool swapBuffers();
|
||||||
void destroy();
|
void destroy();
|
||||||
EGLSurface getSurface() const { return eglSurface_; }
|
EGLSurface getSurface() const { return eglSurface_; }
|
||||||
|
EGLContext getContext() const { return eglContext_; }
|
||||||
|
EGLDisplay getDisplay() const { return eglDisplay_; }
|
||||||
private:
|
private:
|
||||||
EGLDisplay eglDisplay_;
|
EGLDisplay eglDisplay_;
|
||||||
EGLContext eglContext_;
|
EGLContext eglContext_;
|
||||||
|
|||||||
@ -215,7 +215,7 @@ ArkUI_NodeHandle CreateNodeHandle(const std::string &tag) {
|
|||||||
// 创建Node也名创建ROW Column等容器
|
// 创建Node也名创建ROW Column等容器
|
||||||
ArkUI_NodeHandle nodeHandel = nodeAPI->createNode(ARKUI_NODE_RELATIVE_CONTAINER);
|
ArkUI_NodeHandle nodeHandel = nodeAPI->createNode(ARKUI_NODE_RELATIVE_CONTAINER);
|
||||||
// 节点默认宽度or高度
|
// 节点默认宽度or高度
|
||||||
ArkUI_NumberValue nodeSizeData[] = {800, 600};
|
ArkUI_NumberValue nodeSizeData[] = {1280, 720};
|
||||||
ArkUI_NumberValue nodeMarginData[] = {{.u32 = 15}, {.f32 = 15}};
|
ArkUI_NumberValue nodeMarginData[] = {{.u32 = 15}, {.f32 = 15}};
|
||||||
// ArkUI_AttributeItem
|
// ArkUI_AttributeItem
|
||||||
// 参数1:指向数值数组
|
// 参数1:指向数值数组
|
||||||
@ -233,7 +233,7 @@ ArkUI_NodeHandle CreateNodeHandle(const std::string &tag) {
|
|||||||
// 组件ID Item
|
// 组件ID Item
|
||||||
ArkUI_AttributeItem comIdItem = {.string = tag.c_str(), .size = 1};
|
ArkUI_AttributeItem comIdItem = {.string = tag.c_str(), .size = 1};
|
||||||
// 组件Surface Size
|
// 组件Surface Size
|
||||||
ArkUI_NumberValue surfaceSizeData[] = {800, 600};
|
ArkUI_NumberValue surfaceSizeData[] = {1280, 720};
|
||||||
ArkUI_AttributeItem surfaceSizeItem = {surfaceSizeData, 2};
|
ArkUI_AttributeItem surfaceSizeItem = {surfaceSizeData, 2};
|
||||||
// 创建组件
|
// 创建组件
|
||||||
xc = nodeAPI->createNode(ARKUI_NODE_XCOMPONENT);
|
xc = nodeAPI->createNode(ARKUI_NODE_XCOMPONENT);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "NativeRender.h"
|
#include "NativeRender.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <OSD_Environment.hxx>
|
#include <OSD_Environment.hxx>
|
||||||
@ -28,9 +29,7 @@ NativeRender::NativeRender()
|
|||||||
translationX_(0.0f),
|
translationX_(0.0f),
|
||||||
translationY_(0.0f)
|
translationY_(0.0f)
|
||||||
{
|
{
|
||||||
setupViewer();
|
|
||||||
setupContext();
|
|
||||||
setupView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeRender::~NativeRender() {
|
NativeRender::~NativeRender() {
|
||||||
@ -38,6 +37,9 @@ NativeRender::~NativeRender() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NativeRender::init(int width, int height) {
|
bool NativeRender::init(int width, int height) {
|
||||||
|
setupViewer();
|
||||||
|
setupContext();
|
||||||
|
setupView();
|
||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
if (view_.IsNull()) {
|
if (view_.IsNull()) {
|
||||||
@ -46,18 +48,19 @@ bool NativeRender::init(int width, int height) {
|
|||||||
view_->SetBackgroundColor(clearColor_);
|
view_->SetBackgroundColor(clearColor_);
|
||||||
view_->MustBeResized();
|
view_->MustBeResized();
|
||||||
view_->Redraw();
|
view_->Redraw();
|
||||||
|
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_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeRender::setupViewer() {
|
void NativeRender::setupViewer() {
|
||||||
Handle(Aspect_DisplayConnection) displayConnection;
|
Handle(Aspect_DisplayConnection) displayConnection;
|
||||||
// 创建图形驱动
|
// 创建图形驱动
|
||||||
static Handle(OpenGl_GraphicDriver) graphicDriver;
|
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_ = graphicDriver;
|
|
||||||
// 创建V3d_Viewer
|
// 创建V3d_Viewer
|
||||||
viewer_ = new V3d_Viewer(graphicDriver_);
|
viewer_ = new V3d_Viewer(graphicDriver_);
|
||||||
viewer_->SetDefaultLights();
|
viewer_->SetDefaultLights();
|
||||||
@ -88,7 +91,8 @@ void NativeRender::setupView() {
|
|||||||
|
|
||||||
// 设置默认相机位置
|
// 设置默认相机位置
|
||||||
view_->SetProj(V3d_XposYnegZpos);
|
view_->SetProj(V3d_XposYnegZpos);
|
||||||
|
//可选:显示坐标轴
|
||||||
|
view_->ZBufferTriedronSetup();
|
||||||
// 设置相机参数
|
// 设置相机参数
|
||||||
Handle(Graphic3d_Camera) camera = view_->Camera();
|
Handle(Graphic3d_Camera) camera = view_->Camera();
|
||||||
camera->SetFOVy(45.0); // 使用正确的FOV设置API
|
camera->SetFOVy(45.0); // 使用正确的FOV设置API
|
||||||
@ -156,7 +160,7 @@ bool NativeRender::loadModel(const std::string& filePath) {
|
|||||||
// 调整相机到合适位置
|
// 调整相机到合适位置
|
||||||
view_->FitAll(0.05, Standard_True);
|
view_->FitAll(0.05, Standard_True);
|
||||||
view_->ZFitAll();
|
view_->ZFitAll();
|
||||||
printf("Successfully loaded STEP file with %d shapes\n", numShapes);
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadModel","Successfully loaded STEP file with %{public}d shapes",numShapes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +207,7 @@ void NativeRender::loadDefaultModel() {
|
|||||||
// 调整相机
|
// 调整相机
|
||||||
view_->FitAll(0.05, Standard_True);
|
view_->FitAll(0.05, Standard_True);
|
||||||
view_->ZFitAll();
|
view_->ZFitAll();
|
||||||
printf("Loaded default model (cube, sphere, cylinder)\n");
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadDefaultModel","Loaded default model (cube, sphere, cylinder)");
|
||||||
}
|
}
|
||||||
|
|
||||||
//setTranslation
|
//setTranslation
|
||||||
@ -214,9 +218,12 @@ void NativeRender::setTranslation(float x, float y) {
|
|||||||
|
|
||||||
void NativeRender::render() {
|
void NativeRender::render() {
|
||||||
if (view_.IsNull()) {
|
if (view_.IsNull()) {
|
||||||
|
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);
|
||||||
|
glViewport(0, 0, width_, height_);
|
||||||
// 应用旋转
|
// 应用旋转
|
||||||
Handle(Graphic3d_Camera) camera = view_->Camera();
|
Handle(Graphic3d_Camera) camera = view_->Camera();
|
||||||
// 计算旋转
|
// 计算旋转
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
#include <gp_Quaternion.hxx>
|
#include <gp_Quaternion.hxx>
|
||||||
#include <gp_EulerSequence.hxx>
|
#include <gp_EulerSequence.hxx>
|
||||||
#include <ace/xcomponent/native_interface_xcomponent.h>
|
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||||
|
#include "common.h"
|
||||||
class Aspect_Window;
|
class Aspect_Window;
|
||||||
class gp_Quaternion;
|
class gp_Quaternion;
|
||||||
class Graphic3d_Camera;
|
class Graphic3d_Camera;
|
||||||
@ -31,6 +31,7 @@ public:
|
|||||||
|
|
||||||
bool init(int width, int height);
|
bool init(int width, int height);
|
||||||
bool loadModel(const std::string& filePath);
|
bool loadModel(const std::string& filePath);
|
||||||
|
void loadDefaultModel();
|
||||||
void render();
|
void render();
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
void setRotation(float xAngle, float yAngle);
|
void setRotation(float xAngle, float yAngle);
|
||||||
@ -43,7 +44,7 @@ private:
|
|||||||
void setupViewer();
|
void setupViewer();
|
||||||
void setupContext();
|
void setupContext();
|
||||||
void setupView();
|
void setupView();
|
||||||
void loadDefaultModel();
|
//void loadDefaultModel();
|
||||||
|
|
||||||
Handle(OpenGl_GraphicDriver) graphicDriver_;
|
Handle(OpenGl_GraphicDriver) graphicDriver_;
|
||||||
Handle(V3d_Viewer) viewer_;
|
Handle(V3d_Viewer) viewer_;
|
||||||
|
|||||||
@ -9,7 +9,10 @@ NativeRenderThread::NativeRenderThread()
|
|||||||
: isRunning_(false),
|
: isRunning_(false),
|
||||||
nativeWindow_(nullptr),
|
nativeWindow_(nullptr),
|
||||||
windowWidth_(1280),
|
windowWidth_(1280),
|
||||||
windowHeight_(720) {}
|
windowHeight_(720)
|
||||||
|
{
|
||||||
|
eglCore_ = new EGLCore();
|
||||||
|
}
|
||||||
|
|
||||||
NativeRenderThread::~NativeRenderThread() {
|
NativeRenderThread::~NativeRenderThread() {
|
||||||
stop();
|
stop();
|
||||||
@ -22,19 +25,6 @@ bool NativeRenderThread::start(OHNativeWindow* window) {
|
|||||||
|
|
||||||
nativeWindow_ = window;
|
nativeWindow_ = window;
|
||||||
|
|
||||||
// 初始化EGL
|
|
||||||
if (!eglCore_.init(nativeWindow_)) {
|
|
||||||
printf("Failed to initialize EGL\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化OCCT渲染器
|
|
||||||
if (!renderer_.init(windowWidth_, windowHeight_)) {
|
|
||||||
printf("Failed to initialize OCCT renderer\n");
|
|
||||||
eglCore_.destroy();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isRunning_ = true;
|
isRunning_ = true;
|
||||||
renderThread_ = std::thread(&NativeRenderThread::renderLoop, this);
|
renderThread_ = std::thread(&NativeRenderThread::renderLoop, this);
|
||||||
|
|
||||||
@ -57,11 +47,20 @@ void NativeRenderThread::stop() {
|
|||||||
if (renderThread_.joinable()) {
|
if (renderThread_.joinable()) {
|
||||||
renderThread_.join();
|
renderThread_.join();
|
||||||
}
|
}
|
||||||
|
eglCore_->destroy();
|
||||||
eglCore_.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeRenderThread::renderLoop() {
|
void NativeRenderThread::renderLoop() {
|
||||||
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "renderLoop","Thread ID: %{public}d",std::this_thread::get_id());
|
||||||
|
// 初始化EGL
|
||||||
|
if (!eglCore_->init(nativeWindow_)) {
|
||||||
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
|
||||||
|
}
|
||||||
|
// 初始化OCCT渲染器
|
||||||
|
if (!renderer_.init(windowWidth_, windowHeight_)) {
|
||||||
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer");
|
||||||
|
eglCore_->destroy();
|
||||||
|
}
|
||||||
while (isRunning_) {
|
while (isRunning_) {
|
||||||
RenderCommand command;
|
RenderCommand command;
|
||||||
bool hasCommand = false;
|
bool hasCommand = false;
|
||||||
@ -109,12 +108,10 @@ void NativeRenderThread::renderLoop() {
|
|||||||
if (!isRunning_) {
|
if (!isRunning_) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染
|
// 渲染
|
||||||
eglCore_.makeCurrent();
|
eglCore_->makeCurrent();
|
||||||
renderer_.render();
|
renderer_.render();
|
||||||
eglCore_.swapBuffers();
|
eglCore_->swapBuffers();
|
||||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderThead", "NativeRenderThead Done");
|
|
||||||
// 调用渲染完成回调
|
// 调用渲染完成回调
|
||||||
Callback callback;
|
Callback callback;
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,7 +37,7 @@ private:
|
|||||||
std::atomic<bool> isRunning_;
|
std::atomic<bool> isRunning_;
|
||||||
|
|
||||||
OHNativeWindow* nativeWindow_;
|
OHNativeWindow* nativeWindow_;
|
||||||
EGLCore eglCore_;
|
EGLCore* eglCore_;
|
||||||
NativeRender renderer_;
|
NativeRender renderer_;
|
||||||
|
|
||||||
std::mutex commandMutex_;
|
std::mutex commandMutex_;
|
||||||
|
|||||||
@ -21,7 +21,8 @@
|
|||||||
#include <EGL/eglplatform.h>
|
#include <EGL/eglplatform.h>
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#include <napi/native_api.h>
|
#include <napi/native_api.h>
|
||||||
|
#include "hilog/log.h"
|
||||||
|
#include <thread>
|
||||||
namespace NativeOpenCAX {
|
namespace NativeOpenCAX {
|
||||||
/**
|
/**
|
||||||
* Log print domain.
|
* Log print domain.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user