mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibAccelGfx+WebContent: Add GPU painter support on macOS
With these changes it is now possible to create OpenGL context on macOS and run GPU-painter. For now only QT client has a CLI param that turns it on though.
This commit is contained in:
parent
ffe304e88b
commit
61a2e59d87
5 changed files with 70 additions and 16 deletions
|
@ -12,3 +12,8 @@ if (OPENGL_FOUND)
|
||||||
else()
|
else()
|
||||||
set(HAS_ACCELERATED_GRAPHICS OFF CACHE BOOL "" FORCE)
|
set(HAS_ACCELERATED_GRAPHICS OFF CACHE BOOL "" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
set(HAS_ACCELERATED_GRAPHICS ON CACHE BOOL "" FORCE)
|
||||||
|
set(ACCEL_GFX_LIBS "-framework OpenGL" CACHE STRING "" FORCE)
|
||||||
|
endif()
|
||||||
|
|
|
@ -6,6 +6,14 @@
|
||||||
|
|
||||||
#include <LibAccelGfx/Context.h>
|
#include <LibAccelGfx/Context.h>
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
# define GL_SILENCE_DEPRECATION
|
||||||
|
# include <OpenGL/CGLRenderers.h>
|
||||||
|
# include <OpenGL/CGLTypes.h>
|
||||||
|
# include <OpenGL/OpenGL.h>
|
||||||
|
# include <OpenGL/gl3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace AccelGfx {
|
namespace AccelGfx {
|
||||||
|
|
||||||
Context& Context::the()
|
Context& Context::the()
|
||||||
|
@ -16,7 +24,38 @@ Context& Context::the()
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Context> Context::create()
|
#ifdef AK_OS_MACOS
|
||||||
|
static void make_context_cgl()
|
||||||
|
{
|
||||||
|
CGLContextObj context = NULL;
|
||||||
|
CGLPixelFormatAttribute attributes[4] = {
|
||||||
|
kCGLPFAOpenGLProfile,
|
||||||
|
(CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core,
|
||||||
|
kCGLPFAAccelerated,
|
||||||
|
(CGLPixelFormatAttribute)0
|
||||||
|
};
|
||||||
|
|
||||||
|
CGLPixelFormatObj pixelFormat = NULL;
|
||||||
|
GLint numPixelFormats = 0;
|
||||||
|
CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &numPixelFormats);
|
||||||
|
if (error) {
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
error = CGLCreateContext(pixelFormat, NULL, &context);
|
||||||
|
if (error) {
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
error = CGLSetCurrentContext(context);
|
||||||
|
if (error) {
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
VERIFY(glGetError() == GL_NO_ERROR);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void make_context_egl()
|
||||||
{
|
{
|
||||||
EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
|
|
||||||
|
@ -60,8 +99,18 @@ OwnPtr<Context> Context::create()
|
||||||
dbgln("eglMakeCurrent failed");
|
dbgln("eglMakeCurrent failed");
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return make<Context>(egl_display, egl_context, egl_config);
|
OwnPtr<Context> Context::create()
|
||||||
|
{
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
make_context_cgl();
|
||||||
|
#else
|
||||||
|
make_context_egl();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return make<Context>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,12 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
|
||||||
|
#ifndef AK_OS_MACOS
|
||||||
// Make sure egl.h doesn't give us definitions from X11 headers
|
// Make sure egl.h doesn't give us definitions from X11 headers
|
||||||
#define EGL_NO_X11
|
# define EGL_NO_X11
|
||||||
#include <EGL/egl.h>
|
# include <EGL/egl.h>
|
||||||
#undef EGL_NO_X11
|
# undef EGL_NO_X11
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace AccelGfx {
|
namespace AccelGfx {
|
||||||
|
|
||||||
|
@ -22,17 +24,9 @@ public:
|
||||||
|
|
||||||
static OwnPtr<Context> create();
|
static OwnPtr<Context> create();
|
||||||
|
|
||||||
Context(EGLDisplay egl_display, EGLContext egl_context, EGLConfig egl_config)
|
Context()
|
||||||
: m_egl_display(egl_display)
|
|
||||||
, m_egl_context(egl_context)
|
|
||||||
, m_egl_config(egl_config)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
EGLDisplay m_egl_display { nullptr };
|
|
||||||
EGLContext m_egl_context { nullptr };
|
|
||||||
EGLConfig m_egl_config { nullptr };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <GL/gl.h>
|
#ifdef AK_OS_MACOS
|
||||||
|
# define GL_SILENCE_DEPRECATION
|
||||||
|
# include <OpenGL/OpenGL.h>
|
||||||
|
# include <OpenGL/gl3.h>
|
||||||
|
#else
|
||||||
|
# include <GL/gl.h>
|
||||||
|
#endif
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
|
|
||||||
namespace AccelGfx::GL {
|
namespace AccelGfx::GL {
|
||||||
|
|
|
@ -75,7 +75,7 @@ in vec2 vTextureCoord;
|
||||||
uniform sampler2D uSampler;
|
uniform sampler2D uSampler;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = texture2D(uSampler, vTextureCoord) * uColor;
|
fragColor = texture(uSampler, vTextureCoord) * uColor;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue