blob: 327f7cf613cc7d62765912e9d201e05b2a72c814 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
10#include "GrGLTexture.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000011
reed@google.comac10a2d2010-12-22 21:39:39 +000012#include "GrGpuGL.h"
13
bsalomon@google.com8fe72472011-03-30 21:26:44 +000014#define GPUGL static_cast<GrGpuGL*>(getGpu())
15
bsalomon@google.com0b77d682011-08-19 13:28:54 +000016#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
17
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000018const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
19 static const GrGLenum repeatModes[] = {
twiz@google.comb65e0cb2011-03-18 20:41:44 +000020 GR_GL_CLAMP_TO_EDGE,
21 GR_GL_REPEAT,
22 GR_GL_MIRRORED_REPEAT
23 };
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000024 return repeatModes;
reed@google.comac10a2d2010-12-22 21:39:39 +000025};
26
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000027void GrGLTexture::init(GrGpuGL* gpu,
28 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000029 const GrGLRenderTarget::Desc* rtDesc) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000030
31 GrAssert(0 != textureDesc.fTextureID);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000032
bsalomon@google.com80d09b92011-11-05 21:21:13 +000033 fTexParams.invalidate();
34 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000035 fTexIDObj = new GrGLTexID(GPUGL->glInterface(),
36 textureDesc.fTextureID,
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000037 textureDesc.fOwnsID);
bsalomon@google.com6f379512011-11-16 20:36:03 +000038 fInternalFormat = textureDesc.fInternalFormat;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000039 fOrientation = textureDesc.fOrientation;
reed@google.comac10a2d2010-12-22 21:39:39 +000040
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000041 if (NULL != rtDesc) {
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000042 // we render to the top left
43 GrGLIRect vp;
reed@google.comac10a2d2010-12-22 21:39:39 +000044 vp.fLeft = 0;
bsalomon@google.com99621082011-11-15 16:47:16 +000045 vp.fWidth = textureDesc.fWidth;
46 vp.fBottom = 0;
47 vp.fHeight = textureDesc.fHeight;
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000048
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000049 fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this);
reed@google.comac10a2d2010-12-22 21:39:39 +000050 }
reed@google.comac10a2d2010-12-22 21:39:39 +000051}
52
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000053GrGLTexture::GrGLTexture(GrGpuGL* gpu,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000054 const Desc& textureDesc)
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000055 : INHERITED(gpu,
bsalomon@google.com99621082011-11-15 16:47:16 +000056 textureDesc.fWidth,
57 textureDesc.fHeight,
bsalomon@google.com64c4fe42011-11-05 14:51:01 +000058 textureDesc.fConfig) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000059 this->init(gpu, textureDesc, NULL);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000060}
61
62GrGLTexture::GrGLTexture(GrGpuGL* gpu,
63 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000064 const GrGLRenderTarget::Desc& rtDesc)
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000065 : INHERITED(gpu,
bsalomon@google.com99621082011-11-15 16:47:16 +000066 textureDesc.fWidth,
67 textureDesc.fHeight,
bsalomon@google.com64c4fe42011-11-05 14:51:01 +000068 textureDesc.fConfig) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000069 this->init(gpu, textureDesc, &rtDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000070}
71
bsalomon@google.com8fe72472011-03-30 21:26:44 +000072void GrGLTexture::onRelease() {
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000073 INHERITED::onRelease();
Scroggoc29d7cd2011-06-16 13:14:21 +000074 GPUGL->notifyTextureDelete(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000075 if (NULL != fTexIDObj) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000076 fTexIDObj->unref();
77 fTexIDObj = NULL;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000078 }
reed@google.comac10a2d2010-12-22 21:39:39 +000079}
80
bsalomon@google.com8fe72472011-03-30 21:26:44 +000081void GrGLTexture::onAbandon() {
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000082 INHERITED::onAbandon();
bsalomon@google.com8fe72472011-03-30 21:26:44 +000083 if (NULL != fTexIDObj) {
84 fTexIDObj->abandon();
85 }
reed@google.comac10a2d2010-12-22 21:39:39 +000086}
87
bsalomon@google.comcee661a2011-07-26 12:32:36 +000088intptr_t GrGLTexture::getTextureHandle() const {
bsalomon@google.com1da07462011-03-10 14:51:57 +000089 return fTexIDObj->id();
reed@google.comac10a2d2010-12-22 21:39:39 +000090}
91