epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #ifndef GrGLTexture_DEFINED |
| 11 | #define GrGLTexture_DEFINED |
| 12 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 13 | #include "GrGLRenderTarget.h" |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 14 | #include "GrScalar.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 17 | /** |
| 18 | * A ref counted tex id that deletes the texture in its destructor. |
| 19 | */ |
| 20 | class GrGLTexID : public GrRefCnt { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 22 | public: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 23 | GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool ownsID) |
| 24 | : fGL(gl) |
| 25 | , fTexID(texID) |
| 26 | , fOwnsID(ownsID) { |
| 27 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 28 | |
| 29 | virtual ~GrGLTexID() { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 30 | if (0 != fTexID && fOwnsID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 31 | GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | void abandon() { fTexID = 0; } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 36 | GrGLuint id() const { return fTexID; } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 39 | const GrGLInterface* fGL; |
| 40 | GrGLuint fTexID; |
| 41 | bool fOwnsID; |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 44 | //////////////////////////////////////////////////////////////////////////////// |
| 45 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 46 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | class GrGLTexture : public GrTexture { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 48 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | public: |
| 50 | enum Orientation { |
| 51 | kBottomUp_Orientation, |
| 52 | kTopDown_Orientation, |
| 53 | }; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 55 | struct TexParams { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 56 | GrGLenum fFilter; |
| 57 | GrGLenum fWrapS; |
| 58 | GrGLenum fWrapT; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 59 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 60 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 62 | struct Desc { |
bsalomon@google.com | 79d2dbe | 2011-06-13 19:28:02 +0000 | [diff] [blame] | 63 | int fContentWidth; |
| 64 | int fContentHeight; |
| 65 | int fAllocWidth; |
| 66 | int fAllocHeight; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 67 | GrPixelConfig fFormat; |
| 68 | GrGLuint fTextureID; |
| 69 | bool fOwnsID; |
| 70 | GrGLenum fUploadFormat; |
| 71 | GrGLenum fUploadByteCount; |
| 72 | GrGLenum fUploadType; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 73 | Orientation fOrientation; |
| 74 | }; |
| 75 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 76 | // creates a texture that is also an RT |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 77 | GrGLTexture(GrGpuGL* gpu, |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 78 | const Desc& textureDesc, |
| 79 | const GrGLRenderTarget::Desc& rtDesc, |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 80 | const TexParams& initialTexParams); |
| 81 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 82 | // creates a non-RT texture |
| 83 | GrGLTexture(GrGpuGL* gpu, |
| 84 | const Desc& textureDesc, |
| 85 | const TexParams& initialTexParams); |
| 86 | |
| 87 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 88 | virtual ~GrGLTexture() { this->release(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 89 | |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 90 | // overrides of GrTexture |
bsalomon@google.com | 79d2dbe | 2011-06-13 19:28:02 +0000 | [diff] [blame] | 91 | virtual void uploadTextureData(int x, |
| 92 | int y, |
| 93 | int width, |
| 94 | int height, |
junov@google.com | 4ee7ae5 | 2011-06-30 17:30:49 +0000 | [diff] [blame] | 95 | const void* srcData, |
| 96 | size_t rowBytes); |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 97 | virtual intptr_t getTextureHandle() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 99 | const TexParams& getTexParams() const { return fTexParams; } |
| 100 | void setTexParams(const TexParams& texParams) { fTexParams = texParams; } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 101 | GrGLuint textureID() const { return fTexIDObj->id(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 103 | GrGLenum uploadFormat() const { return fUploadFormat; } |
| 104 | GrGLenum uploadByteCount() const { return fUploadByteCount; } |
| 105 | GrGLenum uploadType() const { return fUploadType; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 107 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 108 | * @return width() / allocWidth() |
| 109 | */ |
| 110 | GrScalar contentScaleX() const { return fScaleX; } |
| 111 | |
| 112 | /** |
| 113 | * @return height() / allocHeight() |
| 114 | */ |
| 115 | GrScalar contentScaleY() const { return fScaleY; } |
| 116 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | // Ganesh assumes texture coordinates have their origin |
| 118 | // in the top-left corner of the image. OpenGL, however, |
| 119 | // has the origin in the lower-left corner. For content that |
| 120 | // is loaded by Ganesh we just push the content "upside down" |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 121 | // (by GL's understanding of the world ) in glTex*Image and the |
| 122 | // addressing just works out. However, content generated by GL |
| 123 | // (FBO or externally imported texture) will be updside down |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | // and it is up to the GrGpuGL derivative to handle y-mirroing. |
| 125 | Orientation orientation() const { return fOrientation; } |
| 126 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 127 | static const GrGLenum* WrapMode2GLWrap(GrGLBinding binding); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 128 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 129 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 130 | |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 131 | // overrides of GrTexture |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 132 | virtual void onAbandon(); |
| 133 | virtual void onRelease(); |
| 134 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 135 | private: |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 136 | TexParams fTexParams; |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 137 | GrGLTexID* fTexIDObj; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 138 | GrGLenum fUploadFormat; |
| 139 | GrGLenum fUploadByteCount; |
| 140 | GrGLenum fUploadType; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 141 | // precomputed content / alloc ratios |
| 142 | GrScalar fScaleX; |
| 143 | GrScalar fScaleY; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 144 | Orientation fOrientation; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 145 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 146 | void init(GrGpuGL* gpu, |
| 147 | const Desc& textureDesc, |
| 148 | const GrGLRenderTarget::Desc* rtDesc, |
| 149 | const TexParams& initialTexParams); |
| 150 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | typedef GrTexture INHERITED; |
| 152 | }; |
| 153 | |
| 154 | #endif |