blob: 3d30610d745c390df1beece59f4b00ad290df3ab [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
8
9#include "GrGLTexture.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#include "GrGpuGL.h"
12
bsalomon@google.com8fe72472011-03-30 21:26:44 +000013#define GPUGL static_cast<GrGpuGL*>(getGpu())
14
bsalomon@google.com0b77d682011-08-19 13:28:54 +000015#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
16
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000017const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
18 static const GrGLenum repeatModes[] = {
twiz@google.comb65e0cb2011-03-18 20:41:44 +000019 GR_GL_CLAMP_TO_EDGE,
20 GR_GL_REPEAT,
21 GR_GL_MIRRORED_REPEAT
22 };
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000023 return repeatModes;
reed@google.comac10a2d2010-12-22 21:39:39 +000024};
25
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000026void GrGLTexture::init(GrGpuGL* gpu,
27 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000028 const GrGLRenderTarget::Desc* rtDesc) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000029
30 GrAssert(0 != textureDesc.fTextureID);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000031
bsalomon@google.com80d09b92011-11-05 21:21:13 +000032 fTexParams.invalidate();
33 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000034 fTexIDObj = new GrGLTexID(GPUGL->glInterface(),
35 textureDesc.fTextureID,
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000036 textureDesc.fOwnsID);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000037 fOrientation = textureDesc.fOrientation;
reed@google.comac10a2d2010-12-22 21:39:39 +000038
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000039 if (NULL != rtDesc) {
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000040 // we render to the top left
41 GrGLIRect vp;
reed@google.comac10a2d2010-12-22 21:39:39 +000042 vp.fLeft = 0;
bsalomon@google.com99621082011-11-15 16:47:16 +000043 vp.fWidth = textureDesc.fWidth;
44 vp.fBottom = 0;
45 vp.fHeight = textureDesc.fHeight;
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000046
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000047 fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this);
reed@google.comac10a2d2010-12-22 21:39:39 +000048 }
reed@google.comac10a2d2010-12-22 21:39:39 +000049}
50
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000051GrGLTexture::GrGLTexture(GrGpuGL* gpu,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000052 const Desc& textureDesc)
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000053 : INHERITED(gpu,
bsalomon@google.com99621082011-11-15 16:47:16 +000054 textureDesc.fWidth,
55 textureDesc.fHeight,
bsalomon@google.com64c4fe42011-11-05 14:51:01 +000056 textureDesc.fConfig) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000057 this->init(gpu, textureDesc, NULL);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000058}
59
60GrGLTexture::GrGLTexture(GrGpuGL* gpu,
61 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000062 const GrGLRenderTarget::Desc& rtDesc)
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000063 : INHERITED(gpu,
bsalomon@google.com99621082011-11-15 16:47:16 +000064 textureDesc.fWidth,
65 textureDesc.fHeight,
bsalomon@google.com64c4fe42011-11-05 14:51:01 +000066 textureDesc.fConfig) {
bsalomon@google.com80d09b92011-11-05 21:21:13 +000067 this->init(gpu, textureDesc, &rtDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000068}
69
bsalomon@google.com8fe72472011-03-30 21:26:44 +000070void GrGLTexture::onRelease() {
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000071 INHERITED::onRelease();
Scroggoc29d7cd2011-06-16 13:14:21 +000072 GPUGL->notifyTextureDelete(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000073 if (NULL != fTexIDObj) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000074 fTexIDObj->unref();
75 fTexIDObj = NULL;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000076 }
reed@google.comac10a2d2010-12-22 21:39:39 +000077}
78
bsalomon@google.com8fe72472011-03-30 21:26:44 +000079void GrGLTexture::onAbandon() {
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000080 INHERITED::onAbandon();
bsalomon@google.com8fe72472011-03-30 21:26:44 +000081 if (NULL != fTexIDObj) {
82 fTexIDObj->abandon();
83 }
reed@google.comac10a2d2010-12-22 21:39:39 +000084}
85
bsalomon@google.comcee661a2011-07-26 12:32:36 +000086intptr_t GrGLTexture::getTextureHandle() const {
bsalomon@google.com1da07462011-03-10 14:51:57 +000087 return fTexIDObj->id();
reed@google.comac10a2d2010-12-22 21:39:39 +000088}
89