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; }
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; }
void NaClGLContext::setCurrent() { if (mInstance == NULL) { glSetCurrentContextPPAPI(0); return; } // Lazily create the Pepper context. if (mContext.is_null()) { LogManager::getSingleton().logMessage("\tcreate context started"); 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, mWindow->getWidth(), PP_GRAPHICS3DATTRIB_HEIGHT, mWindow->getHeight(), PP_GRAPHICS3DATTRIB_NONE }; mContext = pp::Graphics3D(*mInstance, pp::Graphics3D(), attribs); if (mContext.is_null()) { glSetCurrentContextPPAPI(0); return; } mInstance->BindGraphics(mContext); } glSetCurrentContextPPAPI(mContext.pp_resource()); return; }
bool eGLContext::MakeCurrent(pp::Instance* instance) { if(!instance) { glSetCurrentContextPPAPI(0); return false; } if(context.is_null()) { int32_t attribs[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 0, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, PP_GRAPHICS3DATTRIB_SAMPLES, 0, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, PP_GRAPHICS3DATTRIB_WIDTH, size.width(), PP_GRAPHICS3DATTRIB_HEIGHT, size.height(), PP_GRAPHICS3DATTRIB_NONE }; context = pp::Graphics3D(instance, pp::Graphics3D(), attribs); if(context.is_null()) { glSetCurrentContextPPAPI(0); return false; } instance->BindGraphics(context); } glSetCurrentContextPPAPI(context.pp_resource()); return true; }
bool OpenGLContext::MakeContextCurrent(pp::Instance* instance) { if (instance == NULL) { glSetCurrentContextPPAPI(0); return false; } // Lazily create the Pepper context. if (context_.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, width, PP_GRAPHICS3DATTRIB_HEIGHT, height, PP_GRAPHICS3DATTRIB_NONE }; context_ = pp::Graphics3D(instance, pp::Graphics3D(), attribs); if (context_.is_null()) { glSetCurrentContextPPAPI(0); return false; } instance->BindGraphics(context_); } glSetCurrentContextPPAPI(context_.pp_resource()); return true; }
void DrawFrame(void* user_data, int32_t result) { glSetCurrentContextPPAPI(psNaCLContext->hRenderContext); DemoRender(psNaCLContext); glSetCurrentContextPPAPI(0); PP_CompletionCallback cc = PP_MakeCompletionCallback(DrawFrame, 0); psNaCLContext->psG3D->SwapBuffers(psNaCLContext->hRenderContext, cc); }
void NaClGLContext::resize() { if(mWidth != mWindow->getWidth() || mHeight != mWindow->getHeight() ) { LogManager::getSingleton().logMessage("\tresizing"); mWidth = mWindow->getWidth(); mHeight = mWindow->getHeight(); glSetCurrentContextPPAPI(0); mContext.ResizeBuffers( mWidth, mHeight ); glSetCurrentContextPPAPI(mContext.pp_resource()); LogManager::getSingleton().logMessage("\tdone resizing"); } }
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; }
void MoonlightInstance::VidDecCleanup(void) { free(s_DecodeBuffer); // Delete the decoder delete g_Instance->m_VideoDecoder; // Delete shader programs if (g_Instance->m_Texture2DShader.program) { glDeleteProgram(g_Instance->m_Texture2DShader.program); g_Instance->m_Texture2DShader.program = 0; } if (g_Instance->m_RectangleArbShader.program) { glDeleteProgram(g_Instance->m_RectangleArbShader.program); g_Instance->m_RectangleArbShader.program = 0; } if (g_Instance->m_ExternalOesShader.program) { glDeleteProgram(g_Instance->m_ExternalOesShader.program); g_Instance->m_ExternalOesShader.program = 0; } // Unbind graphics device by binding a default constructed object glSetCurrentContextPPAPI(0); g_Instance->m_Graphics3D = pp::Graphics3D(); g_Instance->BindGraphics(g_Instance->m_Graphics3D); }
void DiagrammarInterface::LaunchWorld() { glSetCurrentContextPPAPI(context_.pp_resource()); world_.Read(CreateJsonObject("/http/path_simple.json")); world_.Start(); drawer_ = new NaClDrawer(world_); SimulationLoop(); }
int NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context) { SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata; /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */ driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context); glSetCurrentContextPPAPI((PP_Resource) sdl_context); return 0; }
bool Ppapi::setInterfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers) { BX_TRACE("PPAPI Interfaces"); m_instance = _instance; m_instInterface = _instInterface; m_graphicsInterface = _graphicsInterface; m_instancedArrays = glGetInstancedArraysInterfacePPAPI(); m_query = glGetQueryInterfacePPAPI(); m_postSwapBuffers = _postSwapBuffers; 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, BGFX_DEFAULT_WIDTH, PP_GRAPHICS3DATTRIB_HEIGHT, BGFX_DEFAULT_HEIGHT, PP_GRAPHICS3DATTRIB_NONE }; m_context = m_graphicsInterface->Create(m_instance, 0, attribs); if (0 == m_context) { BX_TRACE("Failed to create context!"); return false; } m_instInterface->BindGraphics(m_instance, m_context); glSetCurrentContextPPAPI(m_context); m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete); if (NULL != m_instancedArrays) { glVertexAttribDivisor = naclVertexAttribDivisor; glDrawArraysInstanced = naclDrawArraysInstanced; glDrawElementsInstanced = naclDrawElementsInstanced; } if (NULL != m_query) { glGenQueries = naclGenQueries; glDeleteQueries = naclDeleteQueries; glBeginQuery = naclBeginQuery; glEndQuery = naclEndQuery; glGetQueryObjectiv = naclGetQueryObjectiv; glGetQueryObjectui64v = naclGetQueryObjectui64v; } // Prevent render thread creation. RenderFrame::Enum result = renderFrame(); return RenderFrame::NoContext == result; }
static void init_ui(void *data, int flags) { nacl_glw_root_t *ngr = data; initialized |= flags; if(!(initialized & CORE_INITIALIZED)) return; if(ngr->gr.gr_width == 0 || ngr->gr.gr_height == 0) return; if(nacl_3d_context) { ppb_graphics3d->ResizeBuffers(nacl_3d_context, ngr->gr.gr_width, ngr->gr.gr_height); return; } const int32_t attrib_list[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_WIDTH, ngr->gr.gr_width, PP_GRAPHICS3DATTRIB_HEIGHT, ngr->gr.gr_height, PP_GRAPHICS3DATTRIB_NONE }; nacl_3d_context = ppb_graphics3d->Create(g_Instance, 0, attrib_list); if(nacl_3d_context == 0) { panic("Unable to create 3D-graphics context"); return; } if(!ppb_instance->BindGraphics(g_Instance, nacl_3d_context)) { panic("Unable to bind 3D-graphics context"); return; } glSetCurrentContextPPAPI(nacl_3d_context); TRACE(TRACE_DEBUG, "NACL", "Current 3d context set"); glw_opengl_init_context(&ngr->gr); glClearColor(0,0,0,1); send_msg("running", NULL); mainloop(ngr); }
bool Window::createContext(int w, int h) { if (!graphics3d) { int32_t attribs[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, PP_GRAPHICS3DATTRIB_SAMPLES, 0, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, PP_GRAPHICS3DATTRIB_WIDTH, w, PP_GRAPHICS3DATTRIB_HEIGHT, h, PP_GRAPHICS3DATTRIB_NONE }; graphics3d = new pp::Graphics3D(g_Instance, attribs); if (!g_Instance->BindGraphics(*graphics3d)) goto failed; glSetCurrentContextPPAPI(graphics3d->pp_resource()); } else { // no need to resize. if (w == width && h == height) { return true; } int32_t result = graphics3d->ResizeBuffers(w, h); if (result != PP_OK) goto failed; } width = w; height = h; char buffer[32]; snprintf(buffer, 32, "setWindow:%d,%d", w, h); g_Instance->PostMessage(&buffer[0]); created = true; return true; failed: fprintf(stderr, "Failed to create Graphics3D context!\n"); delete graphics3d; graphics3d = NULL; return false; }
// WINDOW bool ZL_CreateWindow(const char*, int width, int height, int displayflags) { ZL_LOG("NACL", "ZL_CreateWindow - Code Window Size: %d / %d - Requested Size: %d / %d - Current View Size: %d / %d", width, height, NACL_Width, NACL_Height, recView.size.width, recView.size.height); //Window size if (NACL_Width > 0 && NACL_Height > 0) { } //use as is else if (NACL_Width > 0) NACL_Height = NACL_Width*height/width; else if (NACL_Height > 0) NACL_Width = NACL_Height*width/height; else if (recView.size.width < 2 && recView.size.height < 2) NACL_Width = width, NACL_Height = height; else NACL_Height = recView.size.width, NACL_Height = recView.size.height; recView.size.width = NACL_Width, recView.size.height = NACL_Height; if (!context3d) { //Create context int32_t attribs[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 0, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, (displayflags & ZL_DISPLAY_DEPTHBUFFER ? 16 : 0), PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, PP_GRAPHICS3DATTRIB_SAMPLES, 4, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 1, PP_GRAPHICS3DATTRIB_WIDTH, NACL_Width, PP_GRAPHICS3DATTRIB_HEIGHT, NACL_Height, PP_GRAPHICS3DATTRIB_NONE }; if (!(context3d = ppb_graphics3d_interface->Create(instance_, NULL, attribs)) || !ppb_instance_interface->BindGraphics(instance_, context3d)) { ZL_LOG0("NACL", "Failed to start graphics - No OpenGL available"); if (ppb_messaging_interface) ppb_messaging_interface->PostMessage(instance_, ppb_var_interface->VarFromUtf8("NOG", 3)); return false; } glSetCurrentContextPPAPI(context3d); } //WIN = Window created char msgmsg[1024]; uint32_t msgmsglen = sprintf(msgmsg, "WIN%d,%d", NACL_Width, NACL_Height); if (ppb_messaging_interface) ppb_messaging_interface->PostMessage(instance_, ppb_var_interface->VarFromUtf8(msgmsg, msgmsglen)); //PrepareOpenGL ZLGLSL::CreateShaders(); glClearColor(1, 0, 0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //WindowFlags pZL_WindowFlags = &NACL_WindowFlags; return true; }
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; }
OpenGLContext::~OpenGLContext() { glSetCurrentContextPPAPI(0); }
void OpenGLContext::InvalidateContext(pp::Instance* instance) { glSetCurrentContextPPAPI(0); }
void NaClGLContext::endCurrent() { glSetCurrentContextPPAPI(0); }
OpenGLContext::~OpenGLContext() { CCLOG("OpenGLContext::~OpenGLContext"); glSetCurrentContextPPAPI(0); }
void OpenGLContext::InvalidateContext() { CCLOG("InvalidateContext"); glSetCurrentContextPPAPI(0); }
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()); }
void eGLContext::Invalidate() { glSetCurrentContextPPAPI(0); }
/// Make the underlying 3D device invalid, so that any subsequent rendering /// commands will have no effect. The next call to MakeContextCurrent() will /// cause the underlying 3D device to get rebound and start receiving /// receiving rendering commands again. Use InvalidateContext(), for /// example, when resizing the context's viewing area. void OpenGLContext::InvalidateContext() { glSetCurrentContextPPAPI(0); }
int32_t graphics_3d_subinit(uint32_t *Rmask, uint32_t *Gmask, uint32_t *Bmask, uint32_t *Amask) { /* Pepper Graphics3D setup. */ PPB_Instance *ppb_instance_interface = (PPB_Instance *) NaCl_GetInterface(PPB_INSTANCE_INTERFACE); if (!ppb_instance_interface) { write_log("Could not acquire PPB_Instance interface.\n"); return 0; } ppb_g3d_interface = (PPB_Graphics3D *) NaCl_GetInterface(PPB_GRAPHICS_3D_INTERFACE); if (!ppb_g3d_interface) { write_log("Could not acquire PPB_Graphics3D interface.\n"); return 0; } pp_instance = NaCl_GetInstance(); if (!pp_instance) { write_log("Could not find current Pepper instance.\n"); return 0; } 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, gfxvidinfo.width, PP_GRAPHICS3DATTRIB_HEIGHT, gfxvidinfo.height, PP_GRAPHICS3DATTRIB_GPU_PREFERENCE, PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_PERFORMANCE, PP_GRAPHICS3DATTRIB_NONE }; graphics_context = ppb_g3d_interface->Create( pp_instance, 0 /* share_context */, attribs); if (!graphics_context) { write_log("Could not obtain a PPB_Graphics3D context.\n"); return 0; } if (!ppb_instance_interface->BindGraphics(pp_instance, graphics_context)) { write_log("Failed to bind context to instance.\n"); return 0; } glSetCurrentContextPPAPI(graphics_context); /* UAE gfxvidinfo setup. */ /* TODO(cstefansen): Implement gfx double-buffering if perf. mandates it. */ gfxvidinfo.pixbytes = 2; /* 16-bit graphics */ gfxvidinfo.rowbytes = gfxvidinfo.width * gfxvidinfo.pixbytes; gfxvidinfo.bufmem = (uint8_t *) calloc(round_up_to_power_of_2(gfxvidinfo.rowbytes), round_up_to_power_of_2(gfxvidinfo.height)); gfxvidinfo.flush_screen = pepper_graphics3d_flush_screen; *Rmask = 0x0000F800, *Gmask = 0x000007E0, *Bmask = 0x0000001F, *Amask = 0; /* OpenGL ES setup. */ glViewport(0, 0, gfxvidinfo.width, gfxvidinfo.height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glDisable(GL_DEPTH_TEST); /* Uniform index. */ enum { UNIFORM_VIDEOFRAME, UNIFORM_INPUTCOLOR, UNIFORM_THRESHOLD, NUM_UNIFORMS }; GLint uniforms[NUM_UNIFORMS]; /* Attribute index. */ enum { ATTRIB_VERTEX, ATTRIB_TEXTUREPOSITON, NUM_ATTRIBUTES }; static GLuint g_programObj; static GLuint g_textureID; char *g_VShaderData = "attribute vec4 position;" "attribute vec4 inputTextureCoordinate;" "varying vec2 textureCoordinate;" "void main()" "{" "gl_Position = position;" "textureCoordinate = inputTextureCoordinate.xy;" "}"; char *g_FShaderData = "varying highp vec2 textureCoordinate;" "uniform sampler2D videoFrame;" "void main()" "{" "gl_FragColor = texture2D(videoFrame, textureCoordinate);" "}"; GLuint g_vertexShader; GLuint g_fragmentShader; g_vertexShader = compileShader(GL_VERTEX_SHADER, g_VShaderData); g_fragmentShader = compileShader(GL_FRAGMENT_SHADER, g_FShaderData); g_programObj = glCreateProgram(); glAttachShader(g_programObj, g_vertexShader); glAttachShader(g_programObj, g_fragmentShader); glBindAttribLocation(g_programObj, ATTRIB_VERTEX, "position"); glBindAttribLocation(g_programObj, ATTRIB_TEXTUREPOSITON, "inputTextureCoordinate"); glLinkProgram(g_programObj); uniforms[UNIFORM_VIDEOFRAME] = glGetUniformLocation(g_programObj, "videoFrame"); uniforms[UNIFORM_INPUTCOLOR] = glGetUniformLocation(g_programObj, "inputColor"); uniforms[UNIFORM_THRESHOLD] = glGetUniformLocation(g_programObj, "threshold"); glGenTextures(1, &g_textureID); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, g_textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLint textureWidth = round_up_to_power_of_2(gfxvidinfo.width); GLint textureHeight = round_up_to_power_of_2(gfxvidinfo.height); glTexImage2D(GL_TEXTURE_2D, 0 /* level */, GL_RGB, textureWidth, textureHeight, 0, GL_RGB, pixel_data_type, gfxvidinfo.bufmem); static const GLfloat squareVertices[] = { -1.0f, -1.0, 1.0f, -1.0, -1.0f, 1.0, 1.0f, 1.0, }; GLfloat xFraction = ((GLfloat) gfxvidinfo.width) / (GLfloat) textureWidth; GLfloat yFraction = ((GLfloat) gfxvidinfo.height) / (GLfloat) textureHeight; static GLfloat textureVertices[] = { 0.0f, 0.0f /* yFraction */, 0.0f /* xFraction */, 0.0f /* yFraction */, 0.0f, 0.0f, 0.0f /* xFraction */, 0.0f, }; textureVertices[1] = yFraction; textureVertices[2] = xFraction; textureVertices[3] = yFraction; textureVertices[6] = xFraction; glUseProgram(g_programObj); glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0); glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices); glEnableVertexAttribArray(ATTRIB_VERTEX); glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices); glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON); DEBUG_LOG("Shaders compiled and program linked.\n"); GLenum glErrorStatus = glGetError(); if (glErrorStatus) { write_log("GL error %d while initializing.\n", glErrorStatus); return 0; } glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); ppb_g3d_interface->SwapBuffers(graphics_context, PP_BlockUntilComplete()); gettimeofday(&tv_prev, NULL); return 1; /* Success! */ }
void swap() { glSetCurrentContextPPAPI(m_context); m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete); }
NaClGLContext::~NaClGLContext() { glSetCurrentContextPPAPI(0); }