bool OpenGLContext::MakeContextCurrent() { CCLOG("OpenGLContext::MakeContextCurrent %dx%d", _size.width(), _size.height()); // Lazily create the Pepper context. if (_graphics3d.is_null()) { int32_t attribs[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, PP_GRAPHICS3DATTRIB_SAMPLES, 0, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, PP_GRAPHICS3DATTRIB_WIDTH, _size.width(), PP_GRAPHICS3DATTRIB_HEIGHT, _size.height(), PP_GRAPHICS3DATTRIB_NONE }; _graphics3d = pp::Graphics3D(_instance, pp::Graphics3D(), attribs); if (_graphics3d.is_null()) { glSetCurrentContextPPAPI(0); return false; } bool rtn = _instance->BindGraphics(_graphics3d); assert(rtn && "BindGraphics failed"); if (!rtn) return false; } CCLOG("glSetCurrentContextPPAPI: %p", (void*)_graphics3d.pp_resource()); glSetCurrentContextPPAPI(_graphics3d.pp_resource()); return true; }
bool InitGL(int32_t new_width, int32_t new_height) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { fprintf(stderr, "Unable to initialize GL PPAPI!\n"); return false; } const int32_t attrib_list[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_WIDTH, new_width, PP_GRAPHICS3DATTRIB_HEIGHT, new_height, PP_GRAPHICS3DATTRIB_NONE }; context_ = pp::Graphics3D(this, attrib_list); if (!BindGraphics(context_)) { fprintf(stderr, "Unable to bind 3d context!\n"); context_ = pp::Graphics3D(); glSetCurrentContextPPAPI(0); return false; } glSetCurrentContextPPAPI(context_.pp_resource()); return true; }