1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
Copyright 2010 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "GrGLTexture.h"
#include "GrGpuGL.h"
GrGLRenderTarget::GrGLRenderTarget(const GLRenderTargetIDs& ids,
const GrIRect& viewport,
GrGLTexture* texture,
GrGpuGL* gl) : INHERITED(texture) {
fGL = gl;
fRTFBOID = ids.fRTFBOID;
fTexFBOID = ids.fTexFBOID;
fStencilRenderbufferID = ids.fStencilRenderbufferID;
fMSColorRenderbufferID = ids.fMSColorRenderbufferID;
fNeedsResolve = false;
fViewport = viewport;
fOwnIDs = ids.fOwnIDs;
// viewport should be GL's viewport with top >= bottom
GrAssert(viewport.height() <= 0);
}
GrGLRenderTarget::~GrGLRenderTarget() {
fGL->notifyRenderTargetDelete(this);
if (fOwnIDs) {
if (fTexFBOID) {
GR_GLEXT(fGL->extensions(), DeleteFramebuffers(1, &fTexFBOID));
}
if (fRTFBOID && fRTFBOID != fTexFBOID) {
GR_GLEXT(fGL->extensions(), DeleteFramebuffers(1, &fRTFBOID));
}
if (fStencilRenderbufferID) {
GR_GLEXT(fGL->extensions(), DeleteRenderbuffers(1, &fStencilRenderbufferID));
}
if (fMSColorRenderbufferID) {
GR_GLEXT(fGL->extensions(), DeleteRenderbuffers(1, &fMSColorRenderbufferID));
}
}
}
void GrGLRenderTarget::abandon() {
fRTFBOID = 0;
fTexFBOID = 0;
fStencilRenderbufferID = 0;
fMSColorRenderbufferID = 0;
}
////////////////////////////////////////////////////////////////////////////////
const GLenum GrGLTexture::gWrapMode2GLWrap[] = {
GL_CLAMP_TO_EDGE,
GL_REPEAT,
#ifdef GL_MIRRORED_REPEAT
GL_MIRRORED_REPEAT
#else
GL_REPEAT // GL_MIRRORED_REPEAT not supported :(
#endif
};
GrGLTexture::GrGLTexture(const GLTextureDesc& textureDesc,
const GLRenderTargetIDs& rtIDs,
const TexParams& initialTexParams,
GrGpuGL* gl) :
INHERITED(textureDesc.fContentWidth,
textureDesc.fContentHeight,
textureDesc.fAllocWidth,
textureDesc.fAllocHeight,
textureDesc.fFormat),
fTexParams(initialTexParams),
fTextureID(textureDesc.fTextureID),
fUploadFormat(textureDesc.fUploadFormat),
fUploadByteCount(textureDesc.fUploadByteCount),
fUploadType(textureDesc.fUploadType),
fOrientation(textureDesc.fOrientation),
fRenderTarget(NULL),
fGpuGL(gl) {
GrAssert(0 != textureDesc.fTextureID);
if (rtIDs.fTexFBOID) {
GrIRect vp;
vp.fLeft = 0;
vp.fRight = (int32_t) textureDesc.fContentWidth;
// viewport for GL is top > bottom
vp.fTop = (int32_t) textureDesc.fAllocHeight;
vp.fBottom = (int32_t) textureDesc.fAllocHeight -
(int32_t)textureDesc.fContentHeight;
fRenderTarget = new GrGLRenderTarget(rtIDs, vp, this, gl);
}
}
GrGLTexture::~GrGLTexture() {
// make sure we haven't been abandoned
if (fTextureID) {
fGpuGL->notifyTextureDelete(this);
GR_GL(DeleteTextures(1, &fTextureID));
}
delete fRenderTarget;
}
void GrGLTexture::abandon() {
fTextureID = 0;
if (NULL != fRenderTarget) {
fRenderTarget->abandon();
}
}
bool GrGLTexture::isRenderTarget() const {
return NULL != fRenderTarget;
}
GrRenderTarget* GrGLTexture::asRenderTarget() {
return (GrRenderTarget*)fRenderTarget;
}
void GrGLTexture::removeRenderTarget() {
GrAssert(NULL != fRenderTarget);
if (NULL != fRenderTarget) {
// must do this notify before the delete
fGpuGL->notifyTextureRemoveRenderTarget(this);
delete fRenderTarget;
fRenderTarget = NULL;
}
}
void GrGLTexture::uploadTextureData(uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
const void* srcData) {
fGpuGL->setSpareTextureUnit();
// glCompressedTexSubImage2D doesn't support any formats
// (at least without extensions)
GrAssert(fUploadFormat != GR_PALETTE8_RGBA8);
// If we need to update textures that are created upside down
// then we have to modify this code to flip the srcData
GrAssert(kTopDown_Orientation == fOrientation);
GR_GL(BindTexture(GL_TEXTURE_2D, fTextureID));
GR_GL(PixelStorei(GL_UNPACK_ALIGNMENT, fUploadByteCount));
GR_GL(TexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
fUploadFormat, fUploadType, srcData));
}
intptr_t GrGLTexture::getTextureHandle() {
return fTextureID;
}
|