示例#1
0
文件: CCEGLView.cpp 项目: Gamex/GameX
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;
}
示例#2
0
  virtual void DidChangeView(const pp::View& view) {
    // Pepper specifies dimensions in DIPs (device-independent pixels). To
    // generate a context that is at device-pixel resolution on HiDPI devices,
    // scale the dimensions by view.GetDeviceScale().
    int32_t new_width = view.GetRect().width() * view.GetDeviceScale();
    int32_t new_height = view.GetRect().height() * view.GetDeviceScale();

    if (context_.is_null()) {
      if (!InitGL(new_width, new_height)) {
        // failed.
        return;
      }

      verify(gles_init() == true);
      RenderLoop(0);
    } else {
      // Resize the buffers to the new size of the module.
      int32_t result = context_.ResizeBuffers(new_width, new_height);
      if (result < 0) {
        printf("Unable to resize buffers to %d x %d!\n");
        return;
      }
    }

    width_ = new_width;
    height_ = new_height;
    glViewport(0, 0, width_, height_);
    printf("Resize: %d x %d\n", new_width, new_height);
  }
示例#3
0
文件: CCEGLView.cpp 项目: Gamex/GameX
void OpenGLContext::ResizeContext(int width, int height)
{
    CCLOG("OpenGLContext::ResizeContext %dx%d", width, height);
    _size.SetSize(width, height);
    if (!_graphics3d.is_null())
    {
        _graphics3d.ResizeBuffers(width, height);
    }
}
示例#4
0
  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;
  }
示例#5
0
  void RenderLoop(int32_t) {

    screen_width = width_;
    screen_height = height_;

    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if (rend_framePending()) {
      while (!rend_single_frame()) ;
      printf("Rendered frame\n");
    }

    printf("Swapping buffers\n");
    context_.SwapBuffers(
        callback_factory_.NewCallback(&HelloWorldInstance::RenderLoop));
  }
示例#6
0
文件: CCEGLView.cpp 项目: Gamex/GameX
void OpenGLContext::FlushContext()
{
    //CCLOG("OpenGLContext::FlushContext");
    _graphics3d.SwapBuffers(pp::BlockUntilComplete());
}