Skip to content

Add native OpenGL backends for macOS and Linux - #372

Draft
wysaid wants to merge 65 commits into
masterfrom
feature/opengl-backend
Draft

Add native OpenGL backends for macOS and Linux#372
wysaid wants to merge 65 commits into
masterfrom
feature/opengl-backend

Conversation

@wysaid

@wysaid wysaid commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • adds a native OpenGL/GLFW backend for macOS and Linux while preserving Windows GDI as the default
  • aligns drawing, image save/load, text, input, page, window shutdown, and camera behavior with the existing implementation
  • adds deterministic rendering, file-format, camera, event-loop, process-exit, default-configuration, and compatibility tests
  • expands CI across Windows GDI, Windows OpenGL opt-in compilation, macOS ARM64/Intel, Linux X11 runtime, system/bundled GLFW, sanitizers, and Wayland opt-in compilation
  • fixes fresh single-config builds to default to Release and makes Linux bundled GLFW default to X11 without overriding explicit Wayland choices

Why

The previous build and runtime paths were coupled to Win32/GDI. Earlier cross-platform work could compile but did not prove pixel parity, camera lifecycle safety, or reliable process exit. The latest default-configuration test also reproduced two hidden CI gaps: an empty build type on fresh single-config builds and a Linux bundled GLFW default that required undocumented Wayland dependencies.

Impact

  • Windows remains GDI by default; OpenGL remains an explicit build/runtime opt-in.
  • macOS and Linux native builds use OpenGL by default.
  • Linux bundled GLFW uses the tested X11 path by default; Wayland remains explicit and now has a compile gate.
  • Native macOS/Linux SDK packaging and real-device Linux V4L2 coverage remain follow-up work, documented in MERGE_READINESS_REPORT.md.

Validation

  • macOS Release functional tests: 11/11
  • macOS Debug functional tests: 11/11
  • macOS camera-on ASan+UBSan functional tests: 11/11
  • canonical performance test: 1/1
  • core demos: 37/37 built
  • fresh default configuration and explicit Debug preservation verified
  • git diff --check, C++ format check, and workflow YAML parse passed

The PR is intentionally draft until the latest GitHub Actions matrix is green and the remaining hardware-specific smoke tests are acknowledged.

wysaid and others added 30 commits May 6, 2026 20:50
- Accept Clang/AppleClang in CMake when EGE_BUILD_OPENGL=ON

- Avoid stdint conflicts on Clang by gating bundled stdint and fixing __clang__ detection

- Initialize graph state for GLFW backend and pump events to prevent startup segfault

- Update PRD progress for macOS verification
…mitives

- Define RenderTarget abstract interface (src/backend/interface/RenderTarget.h)
  covering 80+ drawing methods for full EGE API coverage
- Implement GlRenderTarget (OpenGL 3.3 Core) with VBO+Shader batch rendering,
  FBO offscreen support, CPU/GPU sync, and basic primitives (line, rect,
  circle, ellipse, sector, arc, polygon, pixel)
- Add GlShader utility for shader compilation/linking
- Integrate GLAD 2.0 loader (OpenGL 3.3 Core profile, header-only)
- Upgrade GLFWWindow to use GlRenderTarget instead of legacy immediate mode
- Extend IMAGE class with m_renderTarget and m_glDirty fields
- Wire screen RenderTarget to image pages in initgraph
- Update egegapi.cpp drawing functions to route through RenderTarget
- Suppress OpenGL deprecation warnings on macOS
- Phase 3/4/5 stubs for image transfer, text rendering, and input

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 实现 GlRenderTarget 图像传输方法:blit, blitStretch, alphaBlend,
  alphaTransparent, withAlpha, alphaFilter, rotateBlend, rotateZoomBlend,
  filterBlur
- 实现 CPU ↔ GPU 同步:getPixelBuffer (GPU→CPU), syncToGpu (CPU→GPU)
- 添加 ROP2 模式支持:XOR, AND, OR(shader 位运算 + destination texture 采样)
- 实现 rebuild() 方法用于 resize 时重建 GPU 纹理
- 将 IMAGE::putimage 全系列函数路由到 RenderTarget(OpenGL 模式)
- 新增 image blit shader(顶点变换 + 片段 ROP2 + color key + alpha override)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…/measureText

Implement GlRenderTarget text rendering capability using stb_truetype:
- Glyph atlas texture with on-demand rasterization (1024x1024)
- setFont() with face, height, weight, italic, underline, strikeout support
- setTextJustify() for horizontal/vertical alignment
- drawText() for both char* (UTF-8) and wchar_t* strings
- getTextWidth/Height and measureText for text measurement
- Escapement/rotation support for rotated text
- macOS system font path resolution (PingFang, Arial, etc.)
- Text rendering demo (graph_text_opengl.cpp)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Linux/macOS now default to EGE_BUILD_OPENGL=ON for true cross-platform support
- mingw-w64 + wine cross-compilation deprecated with warnings
- Updated BUILD.md to promote OpenGL as recommended approach
- Legacy mode still available via -DEGE_BUILD_OPENGL=OFF
…port

- Add captureScreenToTexture() to capture framebuffer before swapBuffers
- Refactor submitBatch to create fresh VAO/VBO per batch (Core OpenGL compat)
- Optimize getPixelBuffer for on-screen RT (skip GPU readback if not dirty)
- Route all drawing functions in egegapi.cpp to m_renderTarget
- Add OS event pumping in dealmessage for native GLFW backends
- Implement getimage with OpenGL pixel readback (RT-to-RT blit + glReadPixels)
- Fix macOS OpenGL context hints (retina framebuffer, doublebuffer)
- Update demos to run 10 frames and save screenshots

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
# Conflicts:
#	src/graphics.cpp
#	src/thread_queue.h
#	src/time.cpp
#	src/window.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants