1 #include "SkEGLContext.h" 2 //#include "SkTypes.h" 3 #include <AGL/agl.h> 4 5 SkEGLContext::SkEGLContext() : context(NULL) { 6 } 7 8 SkEGLContext::~SkEGLContext() { 9 if (this->context) { 10 aglDestroyContext(this->context); 11 } 12 } 13 14 bool SkEGLContext::init(int width, int height) { 15 GLint major, minor; 16 AGLContext ctx; 17 18 aglGetVersion(&major, &minor); 19 //SkDebugf("---- agl version %d %d\n", major, minor); 20 21 const GLint pixelAttrs[] = { 22 AGL_RGBA, 23 AGL_STENCIL_SIZE, 8, 24 /* 25 AGL_SAMPLE_BUFFERS_ARB, 1, 26 AGL_MULTISAMPLE, 27 AGL_SAMPLES_ARB, 2, 28 */ 29 AGL_ACCELERATED, 30 AGL_NONE 31 }; 32 AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs); 33 //AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); 34 //SkDebugf("----- agl format %p\n", format); 35 ctx = aglCreateContext(format, NULL); 36 //SkDebugf("----- agl context %p\n", ctx); 37 aglDestroyPixelFormat(format); 38 39 /* 40 static const GLint interval = 1; 41 aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval); 42 */ 43 44 aglSetCurrentContext(ctx); 45 this->context = ctx; 46 47 // Now create our FBO render target 48 49 GLuint fboID; 50 GLuint cbID; 51 GLuint dsID; 52 glGenFramebuffersEXT(1, &fboID); 53 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID); 54 glGenRenderbuffers(1, &cbID); 55 glBindRenderbuffer(GL_RENDERBUFFER, cbID); 56 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, width, height); 57 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cbID); 58 glGenRenderbuffers(1, &dsID); 59 glBindRenderbuffer(GL_RENDERBUFFER, dsID); 60 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height); 61 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, dsID); 62 glViewport(0, 0, width, height); 63 glClearStencil(0); 64 glClear(GL_STENCIL_BUFFER_BIT); 65 66 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 67 return GL_FRAMEBUFFER_COMPLETE == status; 68 } 69