14#import <OpenGLES/ES3/gl.h>
15#import <UIKit/UIKit.h>
26 return [CAEAGLLayer class];
36 ~GLWindowContext_ios()
override;
39 void onDestroyContext()
override;
41 void resize(
int w,
int h)
override;
44 void onSwapBuffers()
override;
47 UIViewController* fViewController;
49 EAGLContext* fGLContext;
56 , fWindow(
info.fWindow)
57 , fViewController(
info.fViewController)
62 this->initializeContext();
65GLWindowContext_ios::~GLWindowContext_ios() {
66 this->destroyContext();
67 [fGLView removeFromSuperview];
75 CGRect frameRect = [fViewController.view frame];
76 fGLView = [[[
GLView alloc] initWithFrame:frameRect] initWithWindow:fWindow];
77 [fViewController.view addSubview:fGLView];
79 fGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
83 SkDebugf(
"Could Not Create OpenGL ES Context\n");
87 if (![EAGLContext setCurrentContext:fGLContext]) {
88 SkDebugf(
"Could Not Set OpenGL ES Context As Current\n");
89 this->onDestroyContext();
94 CAEAGLLayer* eaglLayer = (CAEAGLLayer*)fGLView.layer;
95 eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO,
96 kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8 };
97 eaglLayer.opaque = YES;
98 eaglLayer.frame = frameRect;
99 eaglLayer.contentsGravity = kCAGravityTopLeft;
102 glGenFramebuffers(1, &fFramebuffer);
103 glBindFramebuffer(GL_FRAMEBUFFER, fFramebuffer);
105 glGenRenderbuffers(1, &fRenderbuffer);
106 glBindRenderbuffer(GL_RENDERBUFFER, fRenderbuffer);
107 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fRenderbuffer);
109 [fGLContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];
111 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
112 if (status != GL_FRAMEBUFFER_COMPLETE) {
114 this->onDestroyContext();
119 glClearColor(0, 0, 0, 255);
120 glStencilMask(0xffffffff);
121 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
126 fWidth = fViewController.view.frame.size.width;
127 fHeight = fViewController.view.frame.size.height;
129 glViewport(0, 0, fWidth, fHeight);
134void GLWindowContext_ios::onDestroyContext() {
135 glDeleteFramebuffers(1, &fFramebuffer);
136 glDeleteRenderbuffers(1, &fRenderbuffer);
137 [EAGLContext setCurrentContext:nil];
138 [fGLContext release];
142void GLWindowContext_ios::onSwapBuffers() {
143 glBindRenderbuffer(GL_RENDERBUFFER, fRenderbuffer);
144 [fGLContext presentRenderbuffer:GL_RENDERBUFFER];
147void GLWindowContext_ios::resize(
int w,
int h) {
148 GLWindowContext::resize(
w,
h);
157 std::unique_ptr<WindowContext> ctx(
new GLWindowContext_ios(
info,
params));
158 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const EmbeddedViewParams * params
SK_API sk_sp< const GrGLInterface > MakeIOS()
std::unique_ptr< WindowContext > MakeGLForIOS(const IOSWindowInfo &info, const DisplayParams ¶ms)