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 | |
| 9 | |
| 10 | #include "GrGLTexture.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 11 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 12 | #include "GrGpuGL.h" |
| 13 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 14 | #define GPUGL static_cast<GrGpuGL*>(getGpu()) |
| 15 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 16 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 17 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 18 | const GrGLenum* GrGLTexture::WrapMode2GLWrap() { |
| 19 | static const GrGLenum repeatModes[] = { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 20 | GR_GL_CLAMP_TO_EDGE, |
| 21 | GR_GL_REPEAT, |
| 22 | GR_GL_MIRRORED_REPEAT |
| 23 | }; |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 24 | return repeatModes; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 27 | void GrGLTexture::init(GrGpuGL* gpu, |
| 28 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 29 | const GrGLRenderTarget::Desc* rtDesc) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 30 | |
| 31 | GrAssert(0 != textureDesc.fTextureID); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 33 | fTexParams.invalidate(); |
| 34 | fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 35 | fTexIDObj = new GrGLTexID(GPUGL->glInterface(), |
| 36 | textureDesc.fTextureID, |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 37 | textureDesc.fOwnsID); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame^] | 38 | fInternalFormat = textureDesc.fInternalFormat; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 39 | fOrientation = textureDesc.fOrientation; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 41 | if (NULL != rtDesc) { |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 42 | // we render to the top left |
| 43 | GrGLIRect vp; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | vp.fLeft = 0; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 45 | vp.fWidth = textureDesc.fWidth; |
| 46 | vp.fBottom = 0; |
| 47 | vp.fHeight = textureDesc.fHeight; |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 48 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 49 | fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 53 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 54 | const Desc& textureDesc) |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 55 | : INHERITED(gpu, |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 56 | textureDesc.fWidth, |
| 57 | textureDesc.fHeight, |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 58 | textureDesc.fConfig) { |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 59 | this->init(gpu, textureDesc, NULL); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, |
| 63 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 64 | const GrGLRenderTarget::Desc& rtDesc) |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 65 | : INHERITED(gpu, |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 66 | textureDesc.fWidth, |
| 67 | textureDesc.fHeight, |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 68 | textureDesc.fConfig) { |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 69 | this->init(gpu, textureDesc, &rtDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 70 | } |
| 71 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 72 | void GrGLTexture::onRelease() { |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 73 | INHERITED::onRelease(); |
Scroggo | c29d7cd | 2011-06-16 13:14:21 +0000 | [diff] [blame] | 74 | GPUGL->notifyTextureDelete(this); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 75 | if (NULL != fTexIDObj) { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 76 | fTexIDObj->unref(); |
| 77 | fTexIDObj = NULL; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 78 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 79 | } |
| 80 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 81 | void GrGLTexture::onAbandon() { |
bsalomon@google.com | 6dcf499 | 2011-04-05 21:16:14 +0000 | [diff] [blame] | 82 | INHERITED::onAbandon(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 83 | if (NULL != fTexIDObj) { |
| 84 | fTexIDObj->abandon(); |
| 85 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | } |
| 87 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 88 | intptr_t GrGLTexture::getTextureHandle() const { |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 89 | return fTexIDObj->id(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | } |
| 91 | |