• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright 2019 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// RenderBufferMtl.mm:
7//    Implements the class methods for RenderBufferMtl.
8//
9
10#include "libANGLE/renderer/metal/RenderBufferMtl.h"
11
12#include "libANGLE/renderer/metal/ContextMtl.h"
13#include "libANGLE/renderer/metal/mtl_format_utils.h"
14#include "libANGLE/renderer/metal/mtl_utils.h"
15
16namespace rx
17{
18
19RenderbufferMtl::RenderbufferMtl(const gl::RenderbufferState &state) : RenderbufferImpl(state) {}
20
21RenderbufferMtl::~RenderbufferMtl() {}
22
23void RenderbufferMtl::onDestroy(const gl::Context *context)
24{
25    releaseTexture();
26}
27
28void RenderbufferMtl::releaseTexture()
29{
30    mTexture = nullptr;
31}
32
33angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context,
34                                              size_t samples,
35                                              GLenum internalformat,
36                                              size_t width,
37                                              size_t height)
38{
39    ContextMtl *contextMtl = mtl::GetImpl(context);
40
41    // NOTE(hqle): Support MSAA
42    ANGLE_CHECK(contextMtl, samples == 1, "Multisample is not supported atm.", GL_INVALID_VALUE);
43
44    if (mTexture != nullptr && mTexture->valid())
45    {
46        // Check against the state if we need to recreate the storage.
47        if (internalformat != mState.getFormat().info->internalFormat ||
48            static_cast<GLsizei>(width) != mState.getWidth() ||
49            static_cast<GLsizei>(height) != mState.getHeight())
50        {
51            releaseTexture();
52        }
53    }
54
55    const gl::InternalFormat &internalFormat = gl::GetSizedInternalFormatInfo(internalformat);
56    angle::FormatID angleFormatId =
57        angle::Format::InternalFormatToID(internalFormat.sizedInternalFormat);
58    mFormat = contextMtl->getPixelFormat(angleFormatId);
59
60    if ((mTexture == nullptr || !mTexture->valid()) && (width != 0 && height != 0))
61    {
62        ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, static_cast<uint32_t>(width),
63                                              static_cast<uint32_t>(height), 1, false, false,
64                                              &mTexture));
65
66        mRenderTarget.set(mTexture, 0, 0, mFormat);
67    }
68
69    return angle::Result::Continue;
70}
71
72angle::Result RenderbufferMtl::setStorage(const gl::Context *context,
73                                          GLenum internalformat,
74                                          size_t width,
75                                          size_t height)
76{
77    return setStorageImpl(context, 1, internalformat, width, height);
78}
79
80angle::Result RenderbufferMtl::setStorageMultisample(const gl::Context *context,
81                                                     size_t samples,
82                                                     GLenum internalformat,
83                                                     size_t width,
84                                                     size_t height)
85{
86    // NOTE(hqle): Support MSAA
87    UNIMPLEMENTED();
88    return angle::Result::Stop;
89}
90
91angle::Result RenderbufferMtl::setStorageEGLImageTarget(const gl::Context *context,
92                                                        egl::Image *image)
93{
94    // NOTE(hqle): Support EGLimage
95    UNIMPLEMENTED();
96    return angle::Result::Stop;
97}
98
99angle::Result RenderbufferMtl::getAttachmentRenderTarget(const gl::Context *context,
100                                                         GLenum binding,
101                                                         const gl::ImageIndex &imageIndex,
102                                                         GLsizei samples,
103                                                         FramebufferAttachmentRenderTarget **rtOut)
104{
105    // NOTE(hqle): Support MSAA.
106    ASSERT(mTexture && mTexture->valid());
107    *rtOut = &mRenderTarget;
108    return angle::Result::Continue;
109}
110
111angle::Result RenderbufferMtl::initializeContents(const gl::Context *context,
112                                                  const gl::ImageIndex &imageIndex)
113{
114    return mtl::InitializeTextureContents(context, mTexture, mFormat, imageIndex);
115}
116}