• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 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 // RenderbufferD3d.cpp: Implements the RenderbufferD3D class, a specialization of RenderbufferImpl
8 
9 #include "libANGLE/renderer/d3d/RenderbufferD3D.h"
10 
11 #include "libANGLE/Context.h"
12 #include "libANGLE/Image.h"
13 #include "libANGLE/renderer/d3d/ContextD3D.h"
14 #include "libANGLE/renderer/d3d/EGLImageD3D.h"
15 #include "libANGLE/renderer/d3d/RenderTargetD3D.h"
16 #include "libANGLE/renderer/d3d/RendererD3D.h"
17 
18 namespace rx
19 {
RenderbufferD3D(const gl::RenderbufferState & state,RendererD3D * renderer)20 RenderbufferD3D::RenderbufferD3D(const gl::RenderbufferState &state, RendererD3D *renderer)
21     : RenderbufferImpl(state), mRenderer(renderer), mRenderTarget(nullptr), mImage(nullptr)
22 {}
23 
~RenderbufferD3D()24 RenderbufferD3D::~RenderbufferD3D()
25 {
26     SafeDelete(mRenderTarget);
27     mImage = nullptr;
28 }
29 
onDestroy(const gl::Context * context)30 void RenderbufferD3D::onDestroy(const gl::Context *context)
31 {
32     SafeDelete(mRenderTarget);
33 }
34 
setStorage(const gl::Context * context,GLenum internalformat,GLsizei width,GLsizei height)35 angle::Result RenderbufferD3D::setStorage(const gl::Context *context,
36                                           GLenum internalformat,
37                                           GLsizei width,
38                                           GLsizei height)
39 {
40     return setStorageMultisample(context, 0, internalformat, width, height,
41                                  gl::MultisamplingMode::Regular);
42 }
43 
setStorageMultisample(const gl::Context * context,GLsizei samples,GLenum internalformat,GLsizei width,GLsizei height,gl::MultisamplingMode mode)44 angle::Result RenderbufferD3D::setStorageMultisample(const gl::Context *context,
45                                                      GLsizei samples,
46                                                      GLenum internalformat,
47                                                      GLsizei width,
48                                                      GLsizei height,
49                                                      gl::MultisamplingMode mode)
50 {
51     // TODO: Correctly differentiate between normal multisampling and render to texture.  In the
52     // latter case, the renderbuffer must be automatically resolved when rendering is broken and
53     // operations performed on it (such as blit, copy etc) should use the resolved image.
54     // http://anglebug.com/3107.
55 
56     // If the renderbuffer parameters are queried, the calling function
57     // will expect one of the valid renderbuffer formats for use in
58     // glRenderbufferStorage, but we should create depth and stencil buffers
59     // as DEPTH24_STENCIL8
60     GLenum creationFormat = internalformat;
61     if (internalformat == GL_DEPTH_COMPONENT16 || internalformat == GL_STENCIL_INDEX8)
62     {
63         creationFormat = GL_DEPTH24_STENCIL8_OES;
64     }
65 
66     // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
67     // the specified storage.
68     // Because ES 3.0 already knows the exact number of supported samples, it would already have
69     // been validated and generated GL_INVALID_VALUE.
70     const gl::TextureCaps &formatCaps = mRenderer->getNativeTextureCaps().get(creationFormat);
71     ANGLE_CHECK_GL_ALLOC(GetImplAs<ContextD3D>(context),
72                          static_cast<uint32_t>(samples) <= formatCaps.getMaxSamples());
73 
74     RenderTargetD3D *newRT = nullptr;
75     ANGLE_TRY(
76         mRenderer->createRenderTarget(context, width, height, creationFormat, samples, &newRT));
77 
78     SafeDelete(mRenderTarget);
79     mImage        = nullptr;
80     mRenderTarget = newRT;
81 
82     return angle::Result::Continue;
83 }
84 
setStorageEGLImageTarget(const gl::Context * context,egl::Image * image)85 angle::Result RenderbufferD3D::setStorageEGLImageTarget(const gl::Context *context,
86                                                         egl::Image *image)
87 {
88     mImage = GetImplAs<EGLImageD3D>(image);
89     SafeDelete(mRenderTarget);
90 
91     return angle::Result::Continue;
92 }
93 
getRenderTarget(const gl::Context * context,RenderTargetD3D ** outRenderTarget)94 angle::Result RenderbufferD3D::getRenderTarget(const gl::Context *context,
95                                                RenderTargetD3D **outRenderTarget)
96 {
97     if (mImage)
98     {
99         return mImage->getRenderTarget(context, outRenderTarget);
100     }
101     else
102     {
103         *outRenderTarget = mRenderTarget;
104         return angle::Result::Continue;
105     }
106 }
107 
getAttachmentRenderTarget(const gl::Context * context,GLenum binding,const gl::ImageIndex & imageIndex,GLsizei samples,FramebufferAttachmentRenderTarget ** rtOut)108 angle::Result RenderbufferD3D::getAttachmentRenderTarget(const gl::Context *context,
109                                                          GLenum binding,
110                                                          const gl::ImageIndex &imageIndex,
111                                                          GLsizei samples,
112                                                          FramebufferAttachmentRenderTarget **rtOut)
113 {
114     return getRenderTarget(context, reinterpret_cast<RenderTargetD3D **>(rtOut));
115 }
116 
initializeContents(const gl::Context * context,const gl::ImageIndex & imageIndex)117 angle::Result RenderbufferD3D::initializeContents(const gl::Context *context,
118                                                   const gl::ImageIndex &imageIndex)
119 {
120     RenderTargetD3D *renderTarget = nullptr;
121     ANGLE_TRY(getRenderTarget(context, &renderTarget));
122     return mRenderer->initRenderTarget(context, renderTarget);
123 }
124 
125 }  // namespace rx
126