Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Texture.h: Defines the abstract Texture class and its concrete derived |
| 16 | // classes Texture2D and TextureCubeMap. Implements GL texture objects and |
| 17 | // related functionality. [OpenGL ES 2.0.24] section 3.7 page 63. |
| 18 | |
| 19 | #ifndef LIBGLES_CM_TEXTURE_H_ |
| 20 | #define LIBGLES_CM_TEXTURE_H_ |
| 21 | |
| 22 | #include "Renderbuffer.h" |
| 23 | #include "common/Object.hpp" |
| 24 | #include "utilities.h" |
| 25 | #include "libEGL/Texture.hpp" |
| 26 | #include "common/debug.h" |
| 27 | |
| 28 | #include <GLES/gl.h> |
| 29 | |
| 30 | #include <vector> |
| 31 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 32 | namespace gl { class Surface; } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 33 | |
| 34 | namespace es1 |
| 35 | { |
| 36 | class Framebuffer; |
| 37 | |
| 38 | enum |
| 39 | { |
| 40 | IMPLEMENTATION_MAX_TEXTURE_LEVELS = sw::MIPMAP_LEVELS, |
| 41 | IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (IMPLEMENTATION_MAX_TEXTURE_LEVELS - 1), |
| 42 | IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (IMPLEMENTATION_MAX_TEXTURE_LEVELS - 1), |
| 43 | IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = sw::OUTLINE_RESOLUTION, |
| 44 | }; |
| 45 | |
| 46 | class Texture : public egl::Texture |
| 47 | { |
| 48 | public: |
| 49 | explicit Texture(GLuint name); |
| 50 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 51 | sw::Resource *getResource() const override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 52 | |
| 53 | virtual void addProxyRef(const Renderbuffer *proxy) = 0; |
| 54 | virtual void releaseProxy(const Renderbuffer *proxy) = 0; |
| 55 | |
| 56 | virtual GLenum getTarget() const = 0; |
| 57 | |
| 58 | bool setMinFilter(GLenum filter); |
| 59 | bool setMagFilter(GLenum filter); |
| 60 | bool setWrapS(GLenum wrap); |
| 61 | bool setWrapT(GLenum wrap); |
| 62 | bool setMaxAnisotropy(GLfloat textureMaxAnisotropy); |
| 63 | void setGenerateMipmap(GLboolean enable); |
| 64 | void setCropRect(GLint u, GLint v, GLint w, GLint h); |
| 65 | |
| 66 | GLenum getMinFilter() const; |
| 67 | GLenum getMagFilter() const; |
| 68 | GLenum getWrapS() const; |
| 69 | GLenum getWrapT() const; |
| 70 | GLfloat getMaxAnisotropy() const; |
| 71 | GLboolean getGenerateMipmap() const; |
| 72 | GLint getCropRectU() const; |
| 73 | GLint getCropRectV() const; |
| 74 | GLint getCropRectW() const; |
| 75 | GLint getCropRectH() const; |
| 76 | |
| 77 | virtual GLsizei getWidth(GLenum target, GLint level) const = 0; |
| 78 | virtual GLsizei getHeight(GLenum target, GLint level) const = 0; |
Nicolas Capens | 3b4a25c | 2018-02-22 20:14:07 -0500 | [diff] [blame] | 79 | virtual GLint getFormat(GLenum target, GLint level) const = 0; |
Nicolas Capens | b3f54e8 | 2017-12-19 13:38:18 -0500 | [diff] [blame] | 80 | virtual int getTopLevel() const = 0; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 81 | |
| 82 | virtual bool isSamplerComplete() const = 0; |
| 83 | virtual bool isCompressed(GLenum target, GLint level) const = 0; |
| 84 | virtual bool isDepth(GLenum target, GLint level) const = 0; |
| 85 | |
Nicolas Capens | 0ccc71d | 2018-03-23 10:13:06 -0400 | [diff] [blame] | 86 | virtual Renderbuffer *getRenderbuffer(GLenum target, GLint level) = 0; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 87 | virtual egl::Image *getRenderTarget(GLenum target, unsigned int level) = 0; |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 88 | egl::Image *createSharedImage(GLenum target, unsigned int level); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 89 | virtual bool isShared(GLenum target, unsigned int level) const = 0; |
| 90 | |
| 91 | virtual void generateMipmaps() = 0; |
| 92 | virtual void autoGenerateMipmaps() = 0; |
| 93 | |
| 94 | virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0; |
| 95 | |
| 96 | protected: |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 97 | ~Texture() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 98 | |
Nicolas Capens | 3b4a25c | 2018-02-22 20:14:07 -0500 | [diff] [blame] | 99 | void setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image); |
| 100 | void subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 101 | void setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image); |
| 102 | void subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, egl::Image *image); |
| 103 | |
| 104 | bool copy(egl::Image *source, const sw::Rect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, egl::Image *dest); |
| 105 | |
| 106 | bool isMipmapFiltered() const; |
| 107 | |
| 108 | GLenum mMinFilter; |
| 109 | GLenum mMagFilter; |
| 110 | GLenum mWrapS; |
| 111 | GLenum mWrapT; |
| 112 | GLfloat mMaxAnisotropy; |
| 113 | GLboolean generateMipmap; |
| 114 | GLint cropRectU; |
| 115 | GLint cropRectV; |
| 116 | GLint cropRectW; |
| 117 | GLint cropRectH; |
| 118 | |
| 119 | sw::Resource *resource; |
| 120 | }; |
| 121 | |
| 122 | class Texture2D : public Texture |
| 123 | { |
| 124 | public: |
| 125 | explicit Texture2D(GLuint name); |
| 126 | |
| 127 | void addProxyRef(const Renderbuffer *proxy) override; |
| 128 | void releaseProxy(const Renderbuffer *proxy) override; |
| 129 | void sweep() override; |
| 130 | |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 131 | GLenum getTarget() const override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 132 | |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 133 | GLsizei getWidth(GLenum target, GLint level) const override; |
| 134 | GLsizei getHeight(GLenum target, GLint level) const override; |
Nicolas Capens | 3b4a25c | 2018-02-22 20:14:07 -0500 | [diff] [blame] | 135 | GLint getFormat(GLenum target, GLint level) const override; |
Nicolas Capens | b3f54e8 | 2017-12-19 13:38:18 -0500 | [diff] [blame] | 136 | int getTopLevel() const override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 137 | |
Nicolas Capens | 3b4a25c | 2018-02-22 20:14:07 -0500 | [diff] [blame] | 138 | void setImage(GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 139 | void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels); |
Nicolas Capens | 3b4a25c | 2018-02-22 20:14:07 -0500 | [diff] [blame] | 140 | void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 141 | void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels); |
| 142 | void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 143 | void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 144 | |
Nicolas Capens | 58df2f6 | 2016-06-07 14:48:56 -0400 | [diff] [blame] | 145 | void setSharedImage(egl::Image *image); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 146 | |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 147 | bool isSamplerComplete() const override; |
| 148 | bool isCompressed(GLenum target, GLint level) const override; |
| 149 | bool isDepth(GLenum target, GLint level) const override; |
| 150 | void bindTexImage(gl::Surface *surface); |
| 151 | void releaseTexImage() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 152 | |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 153 | void generateMipmaps() override; |
| 154 | void autoGenerateMipmaps() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 155 | |
Nicolas Capens | 0ccc71d | 2018-03-23 10:13:06 -0400 | [diff] [blame] | 156 | Renderbuffer *getRenderbuffer(GLenum target, GLint level) override; |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 157 | egl::Image *getRenderTarget(GLenum target, unsigned int level) override; |
| 158 | bool isShared(GLenum target, unsigned int level) const override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 159 | |
| 160 | egl::Image *getImage(unsigned int level); |
| 161 | |
| 162 | protected: |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 163 | ~Texture2D() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 164 | |
| 165 | bool isMipmapComplete() const; |
| 166 | |
| 167 | egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS]; |
| 168 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 169 | gl::Surface *mSurface; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 170 | |
| 171 | // A specific internal reference count is kept for colorbuffer proxy references, |
| 172 | // because, as the renderbuffer acting as proxy will maintain a binding pointer |
| 173 | // back to this texture, there would be a circular reference if we used a binding |
| 174 | // pointer here. This reference count will cause the pointer to be set to null if |
| 175 | // the count drops to zero, but will not cause deletion of the Renderbuffer. |
| 176 | Renderbuffer *mColorbufferProxy; |
| 177 | unsigned int mProxyRefs; |
| 178 | }; |
| 179 | |
| 180 | class TextureExternal : public Texture2D |
| 181 | { |
| 182 | public: |
| 183 | explicit TextureExternal(GLuint name); |
| 184 | |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 185 | GLenum getTarget() const override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 186 | |
| 187 | protected: |
Nicolas Capens | 74a4504 | 2017-06-27 17:03:24 -0400 | [diff] [blame] | 188 | ~TextureExternal() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 189 | }; |
| 190 | } |
| 191 | |
| 192 | #endif // LIBGLES_CM_TEXTURE_H_ |