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