aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/mac/SkEGLContext_mac.cpp
blob: 13bb5922ac9bd17e0a2239331087434fc8b71412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "SkEGLContext.h"
#include <AGL/agl.h>

SkEGLContext::SkEGLContext() : fContext(NULL) {
}

SkEGLContext::~SkEGLContext() {
	if (fContext) {
		aglDestroyContext((AGLContext)fContext);
	}
}

bool SkEGLContext::init(int width, int height) {
	GLint major, minor;
	AGLContext ctx;

	aglGetVersion(&major, &minor);
	SkDebugf("---- agl version %d %d\n", major, minor);

	const GLint pixelAttrs[] = {
		AGL_RGBA,
		AGL_STENCIL_SIZE, 8,
/*
		AGL_SAMPLE_BUFFERS_ARB, 1,
		AGL_MULTISAMPLE,
		AGL_SAMPLES_ARB, 2,
*/
		AGL_ACCELERATED,
		AGL_NONE
	};
	AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs);
	//AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs);
	SkDebugf("----- agl format %p\n", format);
	ctx = aglCreateContext(format, NULL);
	SkDebugf("----- agl context %p\n", ctx);
	aglDestroyPixelFormat(format);

	SkDebugf("---- sizeof aglcontext %d\n", sizeof(AGLContext));
/*
	static const GLint interval = 1;
	aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval);
*/

	aglSetCurrentContext(ctx);
	fContext = (void*)ctx;

	// Now create our FBO render target

	GLuint fboID;
	GLuint cbID;
    GLuint dsID;
	glGenFramebuffersEXT(1, &fboID);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
	glGenRenderbuffers(1, &cbID);
	glBindRenderbuffer(GL_RENDERBUFFER, cbID);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, width, height);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cbID);
    glGenRenderbuffers(1, &dsID);
    glBindRenderbuffer(GL_RENDERBUFFER, dsID);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, dsID);
    
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    return GL_FRAMEBUFFER_COMPLETE == status;
}