blob: 62052fd16abb0f17e1af4bb008a4c0c32d0b807c [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
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@google.comac10a2d2010-12-22 21:39:39 +00009#ifndef GrGLTexture_DEFINED
10#define GrGLTexture_DEFINED
11
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000012#include "GrGpu.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000013#include "GrGLRenderTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000014
bsalomon@google.com1da07462011-03-10 14:51:57 +000015/**
16 * A ref counted tex id that deletes the texture in its destructor.
17 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000018class GrGLTexID : public SkRefCnt {
bsalomon@google.com1da07462011-03-10 14:51:57 +000019public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000020 SK_DECLARE_INST_COUNT(GrGLTexID)
21
bsalomon@google.com72830222013-01-23 20:25:22 +000022 GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped)
bsalomon@google.com0b77d682011-08-19 13:28:54 +000023 : fGL(gl)
24 , fTexID(texID)
bsalomon@google.com72830222013-01-23 20:25:22 +000025 , fIsWrapped(isWrapped) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000026 }
bsalomon@google.com1da07462011-03-10 14:51:57 +000027
28 virtual ~GrGLTexID() {
bsalomon@google.com72830222013-01-23 20:25:22 +000029 if (0 != fTexID && !fIsWrapped) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030 GR_GL_CALL(fGL, DeleteTextures(1, &fTexID));
bsalomon@google.com1da07462011-03-10 14:51:57 +000031 }
32 }
33
34 void abandon() { fTexID = 0; }
twiz@google.com0f31ca72011-03-18 17:38:11 +000035 GrGLuint id() const { return fTexID; }
bsalomon@google.com1da07462011-03-10 14:51:57 +000036
37private:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000038 const GrGLInterface* fGL;
39 GrGLuint fTexID;
bsalomon@google.com72830222013-01-23 20:25:22 +000040 bool fIsWrapped;
reed@google.comfa35e3d2012-06-26 20:16:17 +000041
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000042 typedef SkRefCnt INHERITED;
bsalomon@google.com1da07462011-03-10 14:51:57 +000043};
44
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000045////////////////////////////////////////////////////////////////////////////////
46
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000047
reed@google.comac10a2d2010-12-22 21:39:39 +000048class GrGLTexture : public GrTexture {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000049
reed@google.comac10a2d2010-12-22 21:39:39 +000050public:
bsalomon@google.comda96ea02010-12-23 16:53:57 +000051 struct TexParams {
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +000052 GrGLenum fMinFilter;
53 GrGLenum fMagFilter;
twiz@google.com0f31ca72011-03-18 17:38:11 +000054 GrGLenum fWrapS;
55 GrGLenum fWrapT;
bsalomon@google.com0a97be22011-11-08 19:20:57 +000056 GrGLenum fSwizzleRGBA[4];
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000057 void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
bsalomon@google.comda96ea02010-12-23 16:53:57 +000058 };
reed@google.comac10a2d2010-12-22 21:39:39 +000059
robertphillips@google.com32716282012-06-04 12:48:45 +000060 struct Desc : public GrTextureDesc {
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000061 GrGLuint fTextureID;
bsalomon@google.com72830222013-01-23 20:25:22 +000062 bool fIsWrapped;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000063 };
64
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000065 // creates a texture that is also an RT
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000066 GrGLTexture(GrGpuGL* gpu,
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000067 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000068 const GrGLRenderTarget::Desc& rtDesc);
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000069
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000070 // creates a non-RT texture
71 GrGLTexture(GrGpuGL* gpu,
bsalomon@google.com80d09b92011-11-05 21:21:13 +000072 const Desc& textureDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000073
bsalomon@google.com8fe72472011-03-30 21:26:44 +000074 virtual ~GrGLTexture() { this->release(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000075
bsalomon@google.com08afc842012-10-25 18:56:10 +000076 virtual GrBackendObject getTextureHandle() const SK_OVERRIDE;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000077
78 virtual void invalidateCachedState() SK_OVERRIDE { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000079
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000080 // These functions are used to track the texture parameters associated with the texture.
bsalomon@google.com80d09b92011-11-05 21:21:13 +000081 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
82 *timestamp = fTexParamsTimestamp;
83 return fTexParams;
84 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000085
bsalomon@google.com80d09b92011-11-05 21:21:13 +000086 void setCachedTexParams(const TexParams& texParams,
87 GrGpu::ResetTimestamp timestamp) {
88 fTexParams = texParams;
89 fTexParamsTimestamp = timestamp;
90 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000091
92 GrGLuint textureID() const { return (NULL != fTexIDObj.get()) ? fTexIDObj->id() : 0; }
reed@google.comac10a2d2010-12-22 21:39:39 +000093
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000094protected:
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000095 // overrides of GrTexture
junov@chromium.org957ebdd2012-06-12 13:58:36 +000096 virtual void onAbandon() SK_OVERRIDE;
97 virtual void onRelease() SK_OVERRIDE;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000098
reed@google.comac10a2d2010-12-22 21:39:39 +000099private:
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000100 TexParams fTexParams;
101 GrGpu::ResetTimestamp fTexParamsTimestamp;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +0000102 SkAutoTUnref<GrGLTexID> fTexIDObj;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000103
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000104 void init(GrGpuGL* gpu,
105 const Desc& textureDesc,
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000106 const GrGLRenderTarget::Desc* rtDesc);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000107
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 typedef GrTexture INHERITED;
109};
110
111#endif