• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // PBufferSurfaceCGL.cpp: an implementation of egl::Surface for PBuffers for the CLG backend,
8 //                      currently implemented using renderbuffers
9 
10 #include "libANGLE/renderer/gl/cgl/PbufferSurfaceCGL.h"
11 
12 #if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
13 
14 #    include "common/debug.h"
15 #    include "libANGLE/renderer/gl/FramebufferGL.h"
16 #    include "libANGLE/renderer/gl/FunctionsGL.h"
17 #    include "libANGLE/renderer/gl/RendererGL.h"
18 #    include "libANGLE/renderer/gl/StateManagerGL.h"
19 
20 namespace rx
21 {
22 
PbufferSurfaceCGL(const egl::SurfaceState & state,RendererGL * renderer,EGLint width,EGLint height)23 PbufferSurfaceCGL::PbufferSurfaceCGL(const egl::SurfaceState &state,
24                                      RendererGL *renderer,
25                                      EGLint width,
26                                      EGLint height)
27     : SurfaceGL(state),
28       mWidth(width),
29       mHeight(height),
30       mFunctions(renderer->getFunctions()),
31       mStateManager(renderer->getStateManager()),
32       mColorRenderbuffer(0),
33       mDSRenderbuffer(0)
34 {}
35 
~PbufferSurfaceCGL()36 PbufferSurfaceCGL::~PbufferSurfaceCGL()
37 {
38     if (mColorRenderbuffer != 0)
39     {
40         mFunctions->deleteRenderbuffers(1, &mColorRenderbuffer);
41         mColorRenderbuffer = 0;
42     }
43     if (mDSRenderbuffer != 0)
44     {
45         mFunctions->deleteRenderbuffers(1, &mDSRenderbuffer);
46         mDSRenderbuffer = 0;
47     }
48 }
49 
initialize(const egl::Display * display)50 egl::Error PbufferSurfaceCGL::initialize(const egl::Display *display)
51 {
52     mFunctions->genRenderbuffers(1, &mColorRenderbuffer);
53     mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mColorRenderbuffer);
54     mFunctions->renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, mWidth, mHeight);
55 
56     mFunctions->genRenderbuffers(1, &mDSRenderbuffer);
57     mStateManager->bindRenderbuffer(GL_RENDERBUFFER, mDSRenderbuffer);
58     mFunctions->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mWidth, mHeight);
59 
60     return egl::NoError();
61 }
62 
makeCurrent(const gl::Context * context)63 egl::Error PbufferSurfaceCGL::makeCurrent(const gl::Context *context)
64 {
65     return egl::NoError();
66 }
67 
swap(const gl::Context * context)68 egl::Error PbufferSurfaceCGL::swap(const gl::Context *context)
69 {
70     return egl::NoError();
71 }
72 
postSubBuffer(const gl::Context * context,EGLint x,EGLint y,EGLint width,EGLint height)73 egl::Error PbufferSurfaceCGL::postSubBuffer(const gl::Context *context,
74                                             EGLint x,
75                                             EGLint y,
76                                             EGLint width,
77                                             EGLint height)
78 {
79     return egl::NoError();
80 }
81 
querySurfacePointerANGLE(EGLint attribute,void ** value)82 egl::Error PbufferSurfaceCGL::querySurfacePointerANGLE(EGLint attribute, void **value)
83 {
84     UNIMPLEMENTED();
85     return egl::NoError();
86 }
87 
bindTexImage(const gl::Context * context,gl::Texture * texture,EGLint buffer)88 egl::Error PbufferSurfaceCGL::bindTexImage(const gl::Context *context,
89                                            gl::Texture *texture,
90                                            EGLint buffer)
91 {
92     UNIMPLEMENTED();
93     return egl::NoError();
94 }
95 
releaseTexImage(const gl::Context * context,EGLint buffer)96 egl::Error PbufferSurfaceCGL::releaseTexImage(const gl::Context *context, EGLint buffer)
97 {
98     UNIMPLEMENTED();
99     return egl::NoError();
100 }
101 
setSwapInterval(EGLint interval)102 void PbufferSurfaceCGL::setSwapInterval(EGLint interval) {}
103 
getWidth() const104 EGLint PbufferSurfaceCGL::getWidth() const
105 {
106     return mWidth;
107 }
108 
getHeight() const109 EGLint PbufferSurfaceCGL::getHeight() const
110 {
111     return mHeight;
112 }
113 
isPostSubBufferSupported() const114 EGLint PbufferSurfaceCGL::isPostSubBufferSupported() const
115 {
116     UNIMPLEMENTED();
117     return EGL_FALSE;
118 }
119 
getSwapBehavior() const120 EGLint PbufferSurfaceCGL::getSwapBehavior() const
121 {
122     return EGL_BUFFER_PRESERVED;
123 }
124 
createDefaultFramebuffer(const gl::Context * context,const gl::FramebufferState & state)125 FramebufferImpl *PbufferSurfaceCGL::createDefaultFramebuffer(const gl::Context *context,
126                                                              const gl::FramebufferState &state)
127 {
128     const FunctionsGL *functions = GetFunctionsGL(context);
129     StateManagerGL *stateManager = GetStateManagerGL(context);
130 
131     GLuint framebuffer = 0;
132     functions->genFramebuffers(1, &framebuffer);
133     stateManager->bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
134     functions->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
135                                        mColorRenderbuffer);
136     functions->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
137                                        mDSRenderbuffer);
138 
139     return new FramebufferGL(state, framebuffer, true, false);
140 }
141 
142 }  // namespace rx
143 
144 #endif  // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
145