reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #ifndef GrGLTexture_DEFINED |
| 10 | #define GrGLTexture_DEFINED |
| 11 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 12 | #include "GrGpu.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 13 | #include "GrGLRenderTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 15 | /** |
| 16 | * A ref counted tex id that deletes the texture in its destructor. |
| 17 | */ |
| 18 | class GrGLTexID : public GrRefCnt { |
| 19 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame^] | 20 | SK_DECLARE_INST_COUNT(GrGLTexID) |
| 21 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 22 | GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool ownsID) |
| 23 | : fGL(gl) |
| 24 | , fTexID(texID) |
| 25 | , fOwnsID(ownsID) { |
| 26 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 27 | |
| 28 | virtual ~GrGLTexID() { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 29 | if (0 != fTexID && fOwnsID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 30 | GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | void abandon() { fTexID = 0; } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 35 | GrGLuint id() const { return fTexID; } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 36 | |
| 37 | private: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 38 | const GrGLInterface* fGL; |
| 39 | GrGLuint fTexID; |
| 40 | bool fOwnsID; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame^] | 41 | |
| 42 | typedef GrRefCnt INHERITED; |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 45 | //////////////////////////////////////////////////////////////////////////////// |
| 46 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 47 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | class GrGLTexture : public GrTexture { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 49 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | public: |
| 51 | enum Orientation { |
| 52 | kBottomUp_Orientation, |
| 53 | kTopDown_Orientation, |
| 54 | }; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 55 | |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 56 | struct TexParams { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 57 | GrGLenum fFilter; |
| 58 | GrGLenum fWrapS; |
| 59 | GrGLenum fWrapT; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 60 | GrGLenum fSwizzleRGBA[4]; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 61 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 62 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 64 | struct Desc : public GrTextureDesc { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 65 | GrGLuint fTextureID; |
| 66 | bool fOwnsID; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 67 | Orientation fOrientation; |
| 68 | }; |
| 69 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 70 | // creates a texture that is also an RT |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 71 | GrGLTexture(GrGpuGL* gpu, |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 72 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 73 | const GrGLRenderTarget::Desc& rtDesc); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 75 | // creates a non-RT texture |
| 76 | GrGLTexture(GrGpuGL* gpu, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 77 | const Desc& textureDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 78 | |
| 79 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 80 | virtual ~GrGLTexture() { this->release(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 82 | virtual intptr_t getTextureHandle() const SK_OVERRIDE; |
| 83 | |
| 84 | virtual void invalidateCachedState() SK_OVERRIDE { fTexParams.invalidate(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 86 | // these functions |
| 87 | const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { |
| 88 | *timestamp = fTexParamsTimestamp; |
| 89 | return fTexParams; |
| 90 | } |
| 91 | void setCachedTexParams(const TexParams& texParams, |
| 92 | GrGpu::ResetTimestamp timestamp) { |
| 93 | fTexParams = texParams; |
| 94 | fTexParamsTimestamp = timestamp; |
| 95 | } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 96 | GrGLuint textureID() const { return fTexIDObj->id(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | // Ganesh assumes texture coordinates have their origin |
| 99 | // in the top-left corner of the image. OpenGL, however, |
| 100 | // has the origin in the lower-left corner. For content that |
| 101 | // is loaded by Ganesh we just push the content "upside down" |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 102 | // (by GL's understanding of the world) in glTex*Image and the |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 103 | // addressing just works out. However, content generated by GL |
| 104 | // (FBO or externally imported texture) will be updside down |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | // and it is up to the GrGpuGL derivative to handle y-mirroing. |
| 106 | Orientation orientation() const { return fOrientation; } |
| 107 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 108 | static const GrGLenum* WrapMode2GLWrap(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 109 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 110 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 111 | |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 112 | // overrides of GrTexture |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 113 | virtual void onAbandon() SK_OVERRIDE; |
| 114 | virtual void onRelease() SK_OVERRIDE; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 115 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 116 | private: |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 117 | TexParams fTexParams; |
| 118 | GrGpu::ResetTimestamp fTexParamsTimestamp; |
| 119 | GrGLTexID* fTexIDObj; |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 120 | Orientation fOrientation; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 121 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 122 | void init(GrGpuGL* gpu, |
| 123 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 124 | const GrGLRenderTarget::Desc* rtDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 125 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | typedef GrTexture INHERITED; |
| 127 | }; |
| 128 | |
| 129 | #endif |