some
This commit is contained in:
1 parent
290c0ea504
commit
dad1b868e5
19 files changed
+121
-154
No files matched your search
@@ -2,10 +2,14 @@
|
||||
#define GLBRI_H
|
||||
|
||||
#include "glbriConst.h"
|
||||
#include <libEGL/libEGL.h>
|
||||
#include <libGLESv2/GLES/gl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(PLATFORM_IOS)
|
||||
#include "glbriIOS.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "glbriWindows.h"
|
||||
#endif
|
||||
|
||||
typedef struct GLBriState {
|
||||
EGLConfig cfg;
|
||||
EGLContext ctx;
|
||||
@@ -24,7 +28,7 @@ void glbriShutdown(GLBriState *st);
|
||||
#if defined(GLBRI_IMPLEMENTATION)
|
||||
|
||||
bool glbriInit(GLBriState *st) {
|
||||
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
st->display = glbriGetDisplay();
|
||||
if (st->display == EGL_NO_DISPLAY) {
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +73,6 @@ bool glbriResetSurface(GLBriState *st) {
|
||||
}
|
||||
|
||||
// Create new surface
|
||||
// ANGLE on iOS takes a CALayer as the native window
|
||||
st->surface = eglCreateWindowSurface(
|
||||
st->display,
|
||||
st->cfg,
|
||||
@@ -1,7 +1,11 @@
|
||||
#ifndef GLBRI_CONST_H
|
||||
#define GLBRI_CONST_H
|
||||
|
||||
#include <libEGL/libEGL.h>
|
||||
#if defined(PLATFORM_IOS)
|
||||
#include "glbriConstIOS.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "glbriConstWindows.h"
|
||||
#endif
|
||||
|
||||
// Header
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef GLBRI_CONST_IOS_H
|
||||
#define GLBRI_CONST_IOS_H
|
||||
|
||||
#include <libEGL/libEGL.h>
|
||||
|
||||
#endif // GLBRI_CONST_IOS_H
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef GLBRI_IOS_H
|
||||
#define GLBRI_IOS_H
|
||||
|
||||
#include "glbriConst.h"
|
||||
#include <libGLESv2/GLES/gl.h>
|
||||
|
||||
// Header
|
||||
|
||||
EGLDisplay glbriGetDisplay(void);
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(GLBRI_IOS_IMPLEMENTATION)
|
||||
|
||||
EGLDisplay glbriGetDisplay(void) {
|
||||
return eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
|
||||
#endif // GLBRI_IOS_IMPLEMENTATION
|
||||
|
||||
#endif // GLBRI_IOS_H
|
||||
@@ -1,99 +0,0 @@
|
||||
#ifndef GLBRI_H
|
||||
#define GLBRI_H
|
||||
|
||||
#include "glbriConst.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct GLBriState {
|
||||
EGLConfig cfg;
|
||||
EGLContext ctx;
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
void *window;
|
||||
} GLBriState;
|
||||
|
||||
bool glbriInit(GLBriState *st);
|
||||
bool glbriMakeCurrentContext(GLBriState *st);
|
||||
bool glbriResetSurface(GLBriState *st);
|
||||
void glbriShutdown(GLBriState *st);
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(GLBRI_IMPLEMENTATION)
|
||||
|
||||
bool glbriInit(GLBriState *st) {
|
||||
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
|
||||
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
if (getPlatformDisplay == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
st->display = getPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, NULL, GLBRI_DISPLAY);
|
||||
if (st->display == EGL_NO_DISPLAY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (eglInitialize(st->display, NULL, NULL) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLint cfgCount = 0;
|
||||
if (
|
||||
eglChooseConfig(st->display, GLBRI_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
||||
cfgCount < 1
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, GLBRI_CTX);
|
||||
if (st->ctx == EGL_NO_CONTEXT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool glbriMakeCurrentContext(GLBriState *st) {
|
||||
if (eglMakeCurrent(st->display, st->surface, st->surface, st->ctx) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool glbriResetSurface(GLBriState *st) {
|
||||
// Destroy previous surface
|
||||
if (st->surface != EGL_NO_SURFACE) {
|
||||
eglDestroySurface(st->display, st->surface);
|
||||
st->surface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
// Create new surface
|
||||
// WinUI-enabled ANGLE takes the SwapChainPanel's IInspectable as the native window
|
||||
st->surface = eglCreateWindowSurface(
|
||||
st->display,
|
||||
st->cfg,
|
||||
(EGLNativeWindowType)st->window,
|
||||
NULL
|
||||
);
|
||||
if (st->surface == EGL_NO_SURFACE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void glbriShutdown(GLBriState *st) {
|
||||
eglMakeCurrent(st->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroySurface(st->display, st->surface);
|
||||
eglDestroyContext(st->display, st->ctx);
|
||||
eglTerminate(st->display);
|
||||
}
|
||||
|
||||
#endif // GLBRI_IMPLEMENTATION
|
||||
|
||||
#endif // GLBRI_H
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef GLBRI_CONST_H
|
||||
#define GLBRI_CONST_H
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
// Header
|
||||
|
||||
extern const EGLint GLBRI_CFG[];
|
||||
extern const EGLint GLBRI_CTX[];
|
||||
extern const EGLint GLBRI_DISPLAY[];
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(GLBRI_CONST_IMPLEMENTATION)
|
||||
|
||||
const EGLint GLBRI_CFG[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_ALPHA_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
const EGLint GLBRI_CTX[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
const EGLint GLBRI_DISPLAY[] = {
|
||||
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
#endif // GLBRI_CONST_IMPLEMENTATION
|
||||
|
||||
#endif // GLBRI_CONST_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef GLBRI_CONST_WINDOWS_H
|
||||
#define GLBRI_CONST_WINDOWS_H
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
// Header
|
||||
|
||||
extern const EGLint GLBRI_DISPLAY[];
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(GLBRI_CONST_WINDOWS_IMPLEMENTATION)
|
||||
|
||||
const EGLint GLBRI_DISPLAY[] = {
|
||||
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
#endif // GLBRI_CONST_WINDOWS_IMPLEMENTATION
|
||||
|
||||
#endif // GLBRI_CONST_WINDOWS_H
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef GLBRI_WINDOWS_H
|
||||
#define GLBRI_WINDOWS_H
|
||||
|
||||
#include "glbriConst.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// Header
|
||||
|
||||
EGLDisplay glbriGetDisplay(void);
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(GLBRI_WINDOWS_IMPLEMENTATION)
|
||||
|
||||
EGLDisplay glbriGetDisplay(void) {
|
||||
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
|
||||
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
if (getPlatformDisplay == NULL) {
|
||||
return EGL_NO_DISPLAY;
|
||||
}
|
||||
|
||||
return getPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, NULL, GLBRI_DISPLAY);
|
||||
}
|
||||
|
||||
#endif // GLBRI_WINDOWS_IMPLEMENTATION
|
||||
|
||||
#endif // GLBRI_WINDOWS_H
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "glbri/glbriConst.h"
|
||||
|
||||
#define GLBRI_IMPLEMENTATION
|
||||
#define GLBRI_IOS_IMPLEMENTATION
|
||||
#include "glbri/glbri.h"
|
||||
|
||||
#define RAYBRI_AUX_IMPLEMENTATION
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
#define TRACELOG(level, ...) do { fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while (0)
|
||||
|
||||
#define GLBRI_CONST_IMPLEMENTATION
|
||||
#define GLBRI_CONST_WINDOWS_IMPLEMENTATION
|
||||
#include "../glbri/glbriConst.h"
|
||||
|
||||
#define GLBRI_IMPLEMENTATION
|
||||
#define GLBRI_WINDOWS_IMPLEMENTATION
|
||||
#include "../glbri/glbri.h"
|
||||
|
||||
#define RAYBRI_AUX_IMPLEMENTATION
|
||||
|
||||
@@ -599,7 +599,7 @@ their component/controller may survive. queueEvent guarantees Android's renderin
|
||||
thread but does not create, restore or guarantee a current EGL context.
|
||||
|
||||
iOS cleanup stops its timer, makes the context current, calls raybriShutdown and
|
||||
then glbriShutdown. The latter lives in components/glbri/ios/glbri.h and owns unbinding,
|
||||
then glbriShutdown. The latter lives in components/glbri/glbri.h and owns unbinding,
|
||||
surface/context destruction and display termination. Preserve that order so
|
||||
graphics resources are released before their context disappears.
|
||||
|
||||
@@ -728,8 +728,9 @@ Reference APIs checked against the implementation:
|
||||
|
||||
The iOS EGL helper component is named glbri to avoid collisions with external
|
||||
EGL/egl.h headers on case-insensitive filesystems. Its source owners are
|
||||
components/glbri/ios/glbri.h and glbriConst.h; ver-ios/src/glbri links directly
|
||||
to those files. Helper functions use the glbri prefix, state is GLBriState and
|
||||
components/glbri/glbri.h and glbriConst.h for shared behavior, with
|
||||
platform-specific headers under ios/ and windows/. Each app's src/glbri entries
|
||||
link directly to the corresponding owners. Helper functions use the glbri prefix, state is GLBriState and
|
||||
bridge constants/macros use GLBRI_. Native EGL API names and framework includes
|
||||
remain unchanged.
|
||||
|
||||
@@ -843,9 +844,24 @@ search paths and libEGL/libGLESv2 linkage belong to this target; the executable
|
||||
keeps its icon resource linkage. src/glbri and src/raybri contain relative
|
||||
symlinks to their component owners, including the common raybri.h.
|
||||
|
||||
components/glbri/windows mirrors the iOS GLBriState and lifecycle functions.
|
||||
Windows adds GLBRI_DISPLAY to select ANGLE's D3D11 backend through
|
||||
eglGetPlatformDisplayEXT. GLBRI_CFG requests an ES3 window surface and
|
||||
components/glbri/glbri.h owns the common GLBriState and lifecycle functions;
|
||||
glbriConst.h owns GLBRI_CFG and GLBRI_CTX. Both apps link directly to these
|
||||
shared files. The common headers select the platform headers using PLATFORM_IOS
|
||||
or _WIN32. ios/glbriIOS.h and windows/glbriWindows.h each implement
|
||||
glbriGetDisplay: iOS calls eglGetDisplay, Windows uses eglGetPlatformDisplayEXT.
|
||||
ios/glbriConstIOS.h supplies the packaged EGL include; glbriIOS.h also keeps the
|
||||
packaged GLES base header before rlgl's includes. windows/glbriConstWindows.h
|
||||
supplies EGL/eglext includes and GLBRI_DISPLAY for ANGLE's D3D11 backend.
|
||||
Only common definitions live in the component root; the platform files retain
|
||||
their ios/ and windows/ owners.
|
||||
|
||||
Definitions are enabled once by each platform's raybri.c:
|
||||
GLBRI_CONST_IMPLEMENTATION and GLBRI_IMPLEMENTATION for the common headers,
|
||||
GLBRI_IOS_IMPLEMENTATION or GLBRI_WINDOWS_IMPLEMENTATION for display creation,
|
||||
and GLBRI_CONST_WINDOWS_IMPLEMENTATION for Windows display attributes.
|
||||
glbriConstIOS.h contains includes only and needs no implementation section.
|
||||
|
||||
GLBRI_CFG requests an ES3 window surface and
|
||||
GLBRI_CTX requests an ES3 context. GLBriState.window is a borrowed WinUI
|
||||
SwapChainPanel IInspectable pointer; the future native view must retain the
|
||||
panel while EGL uses it and call the bridge on its UI thread.
|
||||
|
||||
@@ -1 +1 @@
|
||||
../../../../../components/glbri/ios/glbri.h
|
||||
../../../../../components/glbri/glbri.h
|
||||
@@ -1 +1 @@
|
||||
../../../../../components/glbri/ios/glbriConst.h
|
||||
../../../../../components/glbri/glbriConst.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/ios/glbriConstIOS.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/ios/glbriIOS.h
|
||||
@@ -1 +1 @@
|
||||
../../../../../components/glbri/windows/glbri.h
|
||||
../../../../../components/glbri/glbri.h
|
||||
@@ -1 +1 @@
|
||||
../../../../../components/glbri/windows/glbriConst.h
|
||||
../../../../../components/glbri/glbriConst.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/windows/glbriConstWindows.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/windows/glbriWindows.h
|
||||
Reference in new issue
Block a user