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; }
bool NaCl::init(int32_t new_width, int32_t new_height) { lout << "init opengl" << endl; if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { 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)) { context = pp::Graphics3D(); glSetCurrentContextPPAPI(0); return false; } glSetCurrentContextPPAPI(context.pp_resource()); game.init(new_width, new_height); return true; }
virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { if (position.size().width() == fWidth && position.size().height() == fHeight) { return; // We don't care about the position, only the size. } fWidth = position.size().width(); fHeight = position.size().height(); fDeviceContext = pp::Graphics2D(this, pp::Size(fWidth, fHeight), false); if (!BindGraphics(fDeviceContext)) { SkDebugf("Couldn't bind the device context\n"); return; } fImage = pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(fWidth, fHeight), false); fBitmap.setConfig(SkBitmap::kARGB_8888_Config, fWidth, fHeight); fBitmap.setPixels(fImage.data()); if (fCanvas) { delete fCanvas; } fCanvas = new SkCanvas(fBitmap); fCanvas->clear(SK_ColorWHITE); if (!fFlushLoopRunning) { Paint(); } }
bool DiagrammarInterface::InitGL(int32_t width, int32_t height) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { std::cerr << "Unable to initialize GL PPAPI!\n"; return false; } if (context_.is_null()) { int32_t attrib_list[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_WIDTH, width, PP_GRAPHICS3DATTRIB_HEIGHT, height, PP_GRAPHICS3DATTRIB_NONE, }; context_ = pp::Graphics3D(this, attrib_list); assert(!context_.is_null()); if (!BindGraphics(context_)) { std::cerr << "Unable to bind 3d context!\n"; context_ = pp::Graphics3D(); glSetCurrentContextPPAPI(0); return false; } } return true; }
LuaBinding::LuaBinding() : // Core clockClass("Clock"), directoryClass("Directory"), fileClass("File"), streamClass("Stream"), // Math eulerAnglesClass("EulerAngles"), quaternionClass("Quaternion"), vector2dClass("Vector2"), vector3dClass("Vector3"), // Network abstractSocketClass("AbstractSocket"), ipAddressClass("IpAddress"), // Utility abstractImage("AbstractImage"), nodeClass("Node"), // SDK application("Application"), nodeComponent("NodeComponent"), entityClass("Entity"), velocityComponent("VelocityComponent"), worldClass("World") #ifndef NDK_SERVER , // Audio musicClass("Music"), soundBuffer("SoundBuffer"), soundEmitter("SoundEmitter"), soundClass("Sound"), // Graphics instancedRenderable("InstancedRenderable"), modelClass("Model"), // SDK consoleClass("Console"), graphicsComponent("GraphicsComponent") #endif { BindCore(); BindMath(); BindNetwork(); BindSDK(); BindUtility(); #ifndef NDK_SERVER BindAudio(); BindGraphics(); BindRenderer(); #endif }
//---------------------------------------------------------- void Bind::All(mrb_state* mrb) { BindApplication(mrb); BindColor::Bind(mrb); BindGraphics(mrb); BindImage::Bind(mrb); BindInput::Bind(mrb); BindMath(mrb); }
void GboxInstance::CreateContext(const pp::Size& size) { ScopedMutexLock scoped_mutex(&pixel_buffer_mutex_); if (!scoped_mutex.is_valid()) { return; } if (IsContextValid()) return; graphics_2d_context_ = new pp::Graphics2D(this, size, false); if (!BindGraphics(*graphics_2d_context_)) { printf("Couldn't bind the device context\n"); } }
bool NaClApplication::tryCreateContext(const Configuration& configuration) { CORRADE_ASSERT(!c, "Platform::NaClApplication::tryCreateContext(): context already created", false); viewportSize = configuration.size(); const std::int32_t attributes[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, PP_GRAPHICS3DATTRIB_SAMPLES, configuration.sampleCount(), PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration.sampleCount() > 1 ? 1 : 0, PP_GRAPHICS3DATTRIB_WIDTH, configuration.size().x(), PP_GRAPHICS3DATTRIB_HEIGHT, configuration.size().y(), PP_GRAPHICS3DATTRIB_NONE }; graphics = new pp::Graphics3D(this, attributes); if(graphics->is_null()) { Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context"; delete graphics; graphics = nullptr; return false; } if(!BindGraphics(*graphics)) { Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics"; delete graphics; graphics = nullptr; return false; } fullscreen = new pp::Fullscreen(this); glSetCurrentContextPPAPI(graphics->pp_resource()); /* Enable input handling for mouse and keyboard */ RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL); RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); c = new Context; return true; }
void MoonlightInstance::InitializeRenderingSurface(int width, int height) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { return; } int32_t contextAttributes[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, PP_GRAPHICS3DATTRIB_RED_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, PP_GRAPHICS3DATTRIB_SAMPLES, 0, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, PP_GRAPHICS3DATTRIB_WIDTH, width, PP_GRAPHICS3DATTRIB_HEIGHT, height, PP_GRAPHICS3DATTRIB_NONE }; g_Instance->m_Graphics3D = pp::Graphics3D(this, contextAttributes); int32_t swapBehaviorAttribute[] = { PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, PP_GRAPHICS3DATTRIB_BUFFER_DESTROYED, PP_GRAPHICS3DATTRIB_NONE }; g_Instance->m_Graphics3D.SetAttribs(swapBehaviorAttribute); if (!BindGraphics(m_Graphics3D)) { fprintf(stderr, "Unable to bind 3d context!\n"); m_Graphics3D = pp::Graphics3D(); glSetCurrentContextPPAPI(0); return; } glSetCurrentContextPPAPI(m_Graphics3D.pp_resource()); glDisable(GL_DITHER); glViewport(0, 0, width, height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); assertNoGLError(); static const float k_Vertices[] = { -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. }; GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(k_Vertices), k_Vertices, GL_STATIC_DRAW); assertNoGLError(); g_Instance->m_Graphics3D.SwapBuffers(pp::BlockUntilComplete()); }