Use CGL queries to fetch pixelformat details and backbuffer dimensions

This commit is contained in:
baldurk
2019-01-30 19:56:08 +00:00
parent 9ff90117f8
commit 9a50a151d0
3 changed files with 103 additions and 21 deletions
+14 -1
View File
@@ -33,13 +33,26 @@ typedef CGLError (*PFN_CGLCreateContext)(CGLPixelFormatObj pix, CGLContextObj sh
typedef CGLError (*PFN_CGLSetCurrentContext)(CGLContextObj ctx);
typedef CGLError (*PFN_CGLFlushDrawable)(CGLContextObj ctx);
typedef CGLError (*PFN_CGLDestroyContext)(CGLContextObj ctx);
typedef CGLError (*PFN_CGLDescribePixelFormat)(CGLPixelFormatObj pix, GLint pix_num,
CGLPixelFormatAttribute attrib, GLint *value);
typedef CGLError (*PFN_CGLSetSurface)(CGLContextObj gl, CGSConnectionID cid, CGSWindowID wid,
CGSSurfaceID sid);
typedef CGLError (*PFN_CGLGetSurface)(CGLContextObj gl, CGSConnectionID *cid, CGSWindowID *wid,
CGSSurfaceID *sid);
typedef CGLError (*PFN_CGSGetSurfaceBounds)(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid,
CGRect *rect);
#define CGL_HOOKED_SYMBOLS(FUNC) \
FUNC(CGLCreateContext); \
FUNC(CGLSetCurrentContext); \
FUNC(CGLFlushDrawable);
#define CGL_NONHOOKED_SYMBOLS(FUNC) FUNC(CGLDestroyContext);
#define CGL_NONHOOKED_SYMBOLS(FUNC) \
FUNC(CGLDestroyContext); \
FUNC(CGLDescribePixelFormat); \
FUNC(CGLSetSurface); \
FUNC(CGLGetSurface); \
FUNC(CGSGetSurfaceBounds);
struct CGLDispatchTable
{
+43 -20
View File
@@ -55,30 +55,30 @@ CGLError GL_EXPORT_NAME(CGLCreateContext)(CGLPixelFormatObj pix, CGLContextObj s
if(ret != kCGLNoError)
return ret;
GLInitParams init;
GLInitParams init = {};
init.width = 0;
init.height = 0;
int value = 0;
GLint value = 0;
// GLX.glXGetConfig(dpy, vis, GLX_BUFFER_SIZE, &value);
init.colorBits = 32;
// GLX.glXGetConfig(dpy, vis, GLX_DEPTH_SIZE, &value);
init.depthBits = 24;
// GLX.glXGetConfig(dpy, vis, GLX_STENCIL_SIZE, &value);
init.stencilBits = 8;
value = 1; // default to srgb
// GLX.glXGetConfig(dpy, vis, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &value);
init.isSRGB = value;
value = 1;
// GLX.glXGetConfig(dpy, vis, GLX_SAMPLES_ARB, &value);
CGLError err = kCGLNoError;
CGL.CGLDescribePixelFormat(pix, 0, kCGLPFAColorSize, &value);
init.colorBits = (uint32_t)value;
CGL.CGLDescribePixelFormat(pix, 0, kCGLPFADepthSize, &value);
init.depthBits = (uint32_t)value;
CGL.CGLDescribePixelFormat(pix, 0, kCGLPFAStencilSize, &value);
init.stencilBits = (uint32_t)value;
// TODO: is macOS sRGB?
init.isSRGB = 1;
CGL.CGLDescribePixelFormat(pix, 0, kCGLPFASamples, &value);
init.multiSamples = RDCMAX(1, value);
GLWindowingData data;
data.wnd = NULL;
data.ctx = *ctx;
// data.cfg = pix;
data.cfg = pix;
{
SCOPED_LOCK(glLock);
@@ -118,18 +118,33 @@ CGLError GL_EXPORT_NAME(CGLSetCurrentContext)(CGLContextObj ctx)
GL.DriverForEmulation(&cglhook.driver);
}
CGRect rect = {};
GLWindowingData data;
data.wnd = (void *)0x4; // drawable;
data.wnd = NULL;
data.ctx = ctx;
// data.cfg = NULL;
data.cfg = NULL;
if(data.ctx)
{
CGSConnectionID conn = 0;
CGSWindowID window = 0;
CGSSurfaceID surface = 0;
CGL.CGLGetSurface(ctx, &conn, &window, &surface);
data.wnd = (void *)(uintptr_t)window;
CGL.CGSGetSurfaceBounds(conn, window, surface, &rect);
}
cglhook.driver.ActivateContext(data);
if(data.ctx)
{
GLInitParams &params = cglhook.driver.GetInitParams(data);
params.width = 400;
params.height = 200;
params.width = (uint32_t)rect.size.width;
params.height = (uint32_t)rect.size.height;
}
}
@@ -146,9 +161,17 @@ CGLError GL_EXPORT_NAME(CGLFlushDrawable)(CGLContextObj ctx)
return CGL.CGLFlushDrawable(ctx);
}
SCOPED_LOCK(glLock);
{
SCOPED_LOCK(glLock);
cglhook.driver.SwapBuffers((void *)0x4);
CGSConnectionID conn = 0;
CGSWindowID window = 0;
CGSSurfaceID surface = 0;
CGL.CGLGetSurface(ctx, &conn, &window, &surface);
cglhook.driver.SwapBuffers((void *)(uintptr_t)window);
}
return CGL.CGLFlushDrawable(ctx);
}
+46
View File
@@ -511,6 +511,52 @@ extern CGLContextObj OPENGL_NULLABLE CGLGetCurrentContext(void);
OPENGL_ASSUME_NONNULL_END
/************************************************************************/
/* CoreGraphics.framework/Headers/CGGeometry.h */
/************************************************************************/
#if defined(__LP64__) && __LP64__
#define CGFLOAT_TYPE double
#else
#define CGFLOAT_TYPE float
#endif
typedef CGFLOAT_TYPE CGFloat;
struct
CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;
struct
CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CGSize CGSize;
struct
CGRect {
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;
/************************************************************************/
/* Undocumented/internal functions */
/************************************************************************/
typedef int CGSConnectionID;
typedef int CGSWindowID;
typedef int CGSSurfaceID;
extern CGLError CGLSetSurface(CGLContextObj OPENGL_NULLABLE gl, CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid);
extern CGLError CGLGetSurface(CGLContextObj OPENGL_NULLABLE ctx, CGSConnectionID * OPENGL_NULLABLE cid, CGSWindowID * OPENGL_NULLABLE wid, CGSSurfaceID * OPENGL_NULLABLE sid);
extern CGLError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGRect rect);
extern CGLError CGSGetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGRect * OPENGL_NULLABLE rect);
#ifdef __cplusplus
}
#endif