blob: cc8adeb7ce8aef24e1315a93e62e89a5214d439a [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"
bsalomon37dd3312014-11-03 08:47:23 -080013#include "GrTexture.h"
14#include "GrGLUtil.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000016
bsalomonafbf2d62014-09-30 12:18:44 -070017class GrGLTexture : public GrTexture {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000018
reed@google.comac10a2d2010-12-22 21:39:39 +000019public:
bsalomon@google.comda96ea02010-12-23 16:53:57 +000020 struct TexParams {
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +000021 GrGLenum fMinFilter;
22 GrGLenum fMagFilter;
twiz@google.com0f31ca72011-03-18 17:38:11 +000023 GrGLenum fWrapS;
24 GrGLenum fWrapT;
bsalomon@google.com0a97be22011-11-08 19:20:57 +000025 GrGLenum fSwizzleRGBA[4];
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000026 void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
bsalomon@google.comda96ea02010-12-23 16:53:57 +000027 };
reed@google.comac10a2d2010-12-22 21:39:39 +000028
bsalomonb15b4c12014-10-29 12:41:57 -070029 struct IDDesc {
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000030 GrGLuint fTextureID;
bsalomon@google.com72830222013-01-23 20:25:22 +000031 bool fIsWrapped;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000032 };
33
bsalomon861e1032014-12-16 07:33:49 -080034 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000035
mtklein72c9faa2015-01-09 10:06:39 -080036 GrBackendObject getTextureHandle() const SK_OVERRIDE;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000037
mtklein72c9faa2015-01-09 10:06:39 -080038 void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000039
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000040 // These functions are used to track the texture parameters associated with the texture.
bsalomon@google.com80d09b92011-11-05 21:21:13 +000041 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
42 *timestamp = fTexParamsTimestamp;
43 return fTexParams;
44 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000045
bsalomon@google.com80d09b92011-11-05 21:21:13 +000046 void setCachedTexParams(const TexParams& texParams,
47 GrGpu::ResetTimestamp timestamp) {
48 fTexParams = texParams;
49 fTexParamsTimestamp = timestamp;
50 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000051
bsalomonbcaefb02014-11-03 11:07:12 -080052 GrGLuint textureID() const { return fTextureID; }
reed@google.comac10a2d2010-12-22 21:39:39 +000053
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000054protected:
bsalomon37dd3312014-11-03 08:47:23 -080055 // The public constructor registers this object with the cache. However, only the most derived
56 // class should register with the cache. This constructor does not do the registration and
57 // rather moves that burden onto the derived class.
58 enum Derived { kDerived };
bsalomon861e1032014-12-16 07:33:49 -080059 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
bsalomon37dd3312014-11-03 08:47:23 -080060
61 void init(const GrSurfaceDesc&, const IDDesc&);
62
mtklein72c9faa2015-01-09 10:06:39 -080063 void onAbandon() SK_OVERRIDE;
64 void onRelease() SK_OVERRIDE;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000065
reed@google.comac10a2d2010-12-22 21:39:39 +000066private:
bsalomon@google.com80d09b92011-11-05 21:21:13 +000067 TexParams fTexParams;
68 GrGpu::ResetTimestamp fTexParamsTimestamp;
bsalomonbcaefb02014-11-03 11:07:12 -080069 GrGLuint fTextureID;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000070
hendrikw9a0c7ab2014-12-09 14:26:47 -080071 // We track this separately from GrGpuResource because this may be both a texture and a render
72 // target, and the texture may be wrapped while the render target is not.
73 bool fIsWrapped;
74
bsalomonafbf2d62014-09-30 12:18:44 -070075 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000076};
77
78#endif