Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

89 řádky
2.4 KiB

  1. // Copyright (c) 2011 The Native Client Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <lol/engine-internal.h>
  5. #include <pthread.h>
  6. #include <ppapi/cpp/completion_callback.h>
  7. #include <ppapi/gles2/gl2ext_ppapi.h>
  8. #include "platform/nacl/opengl_context.h"
  9. namespace {
  10. // This is called by the brower when the 3D context has been flushed to the
  11. // browser window.
  12. void FlushCallback(void* data, int32_t result) {
  13. static_cast<lol::OpenGLContext*>(data)->set_flush_pending(false);
  14. }
  15. } // namespace
  16. namespace lol {
  17. OpenGLContext::OpenGLContext(pp::Instance* instance)
  18. : pp::Graphics3DClient(instance),
  19. flush_pending_(false) {
  20. pp::Module* module = pp::Module::Get();
  21. assert(module);
  22. gles2_interface_ = static_cast<const struct PPB_OpenGLES2*>(
  23. module->GetBrowserInterface(PPB_OPENGLES2_INTERFACE));
  24. assert(gles2_interface_);
  25. }
  26. OpenGLContext::~OpenGLContext() {
  27. glSetCurrentContextPPAPI(0);
  28. }
  29. bool OpenGLContext::MakeContextCurrent(pp::Instance* instance)
  30. {
  31. if (instance == nullptr)
  32. {
  33. glSetCurrentContextPPAPI(0);
  34. return false;
  35. }
  36. // Lazily create the Pepper context.
  37. if (context_.is_null()) {
  38. int32_t attribs[] = {
  39. PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
  40. PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
  41. PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
  42. PP_GRAPHICS3DATTRIB_SAMPLES, 0,
  43. PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
  44. PP_GRAPHICS3DATTRIB_WIDTH, size_.width(),
  45. PP_GRAPHICS3DATTRIB_HEIGHT, size_.height(),
  46. PP_GRAPHICS3DATTRIB_NONE
  47. };
  48. context_ = pp::Graphics3D(instance, pp::Graphics3D(), attribs);
  49. if (context_.is_null()) {
  50. glSetCurrentContextPPAPI(0);
  51. return false;
  52. }
  53. instance->BindGraphics(context_);
  54. }
  55. glSetCurrentContextPPAPI(context_.pp_resource());
  56. return true;
  57. }
  58. void OpenGLContext::InvalidateContext(pp::Instance* instance) {
  59. glSetCurrentContextPPAPI(0);
  60. }
  61. void OpenGLContext::ResizeContext(const pp::Size& size) {
  62. size_ = size;
  63. if (!context_.is_null()) {
  64. context_.ResizeBuffers(size.width(), size.height());
  65. }
  66. }
  67. void OpenGLContext::FlushContext() {
  68. if (flush_pending()) {
  69. // A flush is pending so do nothing; just drop this flush on the floor.
  70. return;
  71. }
  72. set_flush_pending(true);
  73. context_.SwapBuffers(pp::CompletionCallback(&FlushCallback, this));
  74. }
  75. } // namespace lol