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 { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 20 | public: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 21 | GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool ownsID) |
| 22 | : fGL(gl) |
| 23 | , fTexID(texID) |
| 24 | , fOwnsID(ownsID) { |
| 25 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 26 | |
| 27 | virtual ~GrGLTexID() { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 28 | if (0 != fTexID && fOwnsID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 29 | GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | void abandon() { fTexID = 0; } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 34 | GrGLuint id() const { return fTexID; } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 35 | |
| 36 | private: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 37 | const GrGLInterface* fGL; |
| 38 | GrGLuint fTexID; |
| 39 | bool fOwnsID; |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 42 | //////////////////////////////////////////////////////////////////////////////// |
| 43 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 44 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | class GrGLTexture : public GrTexture { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 46 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | public: |
| 48 | enum Orientation { |
| 49 | kBottomUp_Orientation, |
| 50 | kTopDown_Orientation, |
| 51 | }; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 53 | struct TexParams { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 54 | GrGLenum fFilter; |
| 55 | GrGLenum fWrapS; |
| 56 | GrGLenum fWrapT; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 57 | GrGLenum fSwizzleRGBA[4]; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 58 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 59 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 61 | struct Desc { |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 62 | int fWidth; |
| 63 | int fHeight; |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 64 | GrPixelConfig fConfig; |
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 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 82 | virtual intptr_t getTextureHandle() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 84 | // these functions |
| 85 | const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { |
| 86 | *timestamp = fTexParamsTimestamp; |
| 87 | return fTexParams; |
| 88 | } |
| 89 | void setCachedTexParams(const TexParams& texParams, |
| 90 | GrGpu::ResetTimestamp timestamp) { |
| 91 | fTexParams = texParams; |
| 92 | fTexParamsTimestamp = timestamp; |
| 93 | } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 94 | GrGLuint textureID() const { return fTexIDObj->id(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | // Ganesh assumes texture coordinates have their origin |
| 97 | // in the top-left corner of the image. OpenGL, however, |
| 98 | // has the origin in the lower-left corner. For content that |
| 99 | // is loaded by Ganesh we just push the content "upside down" |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 100 | // (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] | 101 | // addressing just works out. However, content generated by GL |
| 102 | // (FBO or externally imported texture) will be updside down |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | // and it is up to the GrGpuGL derivative to handle y-mirroing. |
| 104 | Orientation orientation() const { return fOrientation; } |
| 105 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 106 | static const GrGLenum* WrapMode2GLWrap(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 107 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 108 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 109 | |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 110 | // overrides of GrTexture |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 111 | virtual void onAbandon(); |
| 112 | virtual void onRelease(); |
| 113 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | private: |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 115 | TexParams fTexParams; |
| 116 | GrGpu::ResetTimestamp fTexParamsTimestamp; |
| 117 | GrGLTexID* fTexIDObj; |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 118 | Orientation fOrientation; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 119 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 120 | void init(GrGpuGL* gpu, |
| 121 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 122 | const GrGLRenderTarget::Desc* rtDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 123 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | typedef GrTexture INHERITED; |
| 125 | }; |
| 126 | |
| 127 | #endif |