aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'gpu')
-rw-r--r--gpu/include/GrGLTexture.h16
-rw-r--r--gpu/src/GrGLTexture.cpp13
-rw-r--r--gpu/src/GrGpuGL.cpp77
-rw-r--r--gpu/src/GrGpuGL.h3
4 files changed, 59 insertions, 50 deletions
diff --git a/gpu/include/GrGLTexture.h b/gpu/include/GrGLTexture.h
index ada31512f5..165320fd55 100644
--- a/gpu/include/GrGLTexture.h
+++ b/gpu/include/GrGLTexture.h
@@ -93,13 +93,19 @@ public:
kBottomUp_Orientation,
kTopDown_Orientation,
};
+
+ struct TexParams {
+ GLenum fFilter;
+ GLenum fWrapS;
+ GLenum fWrapT;
+ };
protected:
struct GLTextureDesc {
uint32_t fContentWidth;
uint32_t fContentHeight;
uint32_t fAllocWidth;
- uint32_t fAllocHeight;
+ uint32_t fAllocHeight;
PixelConfig fFormat;
GLuint fTextureID;
GLenum fUploadFormat;
@@ -110,6 +116,7 @@ protected:
typedef GrGLRenderTarget::GLRenderTargetIDs GLRenderTargetIDs;
GrGLTexture(const GLTextureDesc& textureDesc,
const GLRenderTargetIDs& rtIDs,
+ const TexParams& initialTexParams,
GrGpuGL* gl);
public:
@@ -127,9 +134,8 @@ public:
const void* srcData);
virtual intptr_t getTextureHandle();
- const GrSamplerState& samplerState() const { return fSamplerState; }
- void setSamplerState(const GrSamplerState& state)
- { fSamplerState = state; }
+ const TexParams& getTexParams() const { return fTexParams; }
+ void setTexParams(const TexParams& texParams) { fTexParams = texParams; }
GLuint textureID() const { return fTextureID; }
GLenum uploadFormat() const { return fUploadFormat; }
@@ -147,7 +153,7 @@ public:
Orientation orientation() const { return fOrientation; }
private:
- GrSamplerState fSamplerState;
+ TexParams fTexParams;
GLuint fTextureID;
GLenum fUploadFormat;
GLenum fUploadByteCount;
diff --git a/gpu/src/GrGLTexture.cpp b/gpu/src/GrGLTexture.cpp
index b75cad5ec0..4e9d9223de 100644
--- a/gpu/src/GrGLTexture.cpp
+++ b/gpu/src/GrGLTexture.cpp
@@ -75,12 +75,14 @@ const GLenum GrGLTexture::gWrapMode2GLWrap[] = {
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),
@@ -101,15 +103,6 @@ GrGLTexture::GrGLTexture(const GLTextureDesc& textureDesc,
(int32_t)textureDesc.fContentHeight;
fRenderTarget = new GrGLRenderTarget(rtIDs, vp, this, gl);
}
-
- fSamplerState.setClampNoFilter();
-
- GR_GL(BindTexture(GL_TEXTURE_2D, fTextureID));
- gl->notifyTextureBind(this);
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
GrGLTexture::~GrGLTexture() {
@@ -124,7 +117,7 @@ GrGLTexture::~GrGLTexture() {
void GrGLTexture::abandon() {
fTextureID = 0;
if (NULL != fRenderTarget) {
- fRenderTarget->abandon();
+ fRenderTarget->abandon();
}
}
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index 7a7300655f..5198dbbc4e 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -426,7 +426,7 @@ void GrGpuGL::resetContextHelper() {
#if GR_GL_DESKTOP
GR_GL(Disable(GL_LINE_SMOOTH));
GR_GL(Disable(GL_POINT_SMOOTH));
- GR_GL(Disable(GL_MULTISAMPLE));
+ GR_GL(Disable(GL_MULTISAMPLE));
#endif
// we only ever use lines in hairline mode
@@ -533,6 +533,13 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
#if GR_COLLECT_STATS
++fStats.fTextureCreateCnt;
#endif
+
+ static const GrGLTexture::TexParams DEFAULT_PARAMS = {
+ GL_NEAREST,
+ GL_CLAMP_TO_EDGE,
+ GL_CLAMP_TO_EDGE
+ };
+
GrGLTexture::GLTextureDesc glDesc;
GLenum internalFormat;
@@ -607,6 +614,18 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
}
GR_GL(BindTexture(GL_TEXTURE_2D, glDesc.fTextureID));
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MAG_FILTER,
+ DEFAULT_PARAMS.fFilter));
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MIN_FILTER,
+ DEFAULT_PARAMS.fFilter));
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_WRAP_S,
+ DEFAULT_PARAMS.fWrapS));
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_WRAP_T,
+ DEFAULT_PARAMS.fWrapT));
#if GR_COLLECT_STATS
++fStats.fTextureChngCnt;
#endif
@@ -898,7 +917,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
GrPrintf("--- new texture [%d] size=(%d %d) bpp=%d\n",
tex->fTextureID, width, height, tex->fUploadByteCount);
#endif
- GrGLTexture* tex = new GrGLTexture(glDesc, rtIDs, this);
+ GrGLTexture* tex = new GrGLTexture(glDesc, rtIDs, DEFAULT_PARAMS, this);
if (0 != rtIDs.fTexFBOID) {
GrRenderTarget* rt = tex->asRenderTarget();
@@ -1014,18 +1033,6 @@ void GrGpuGL::flushScissor(const GrIRect* rect) {
}
}
-void GrGpuGL::setSamplerStateImm(const GrSamplerState& state) {
-
- GLenum filter = state.isFilter() ? GL_LINEAR : GL_NEAREST;
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GrGLTexture::gWrapMode2GLWrap[state.getWrapX()]));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GrGLTexture::gWrapMode2GLWrap[state.getWrapY()]));
-
-}
-
void GrGpuGL::eraseColor(GrColor color) {
flushRenderTarget();
if (fHWBounds.fScissorEnabled) {
@@ -1433,27 +1440,33 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) {
//GrPrintf("---- bindtexture %d\n", nextTexture->textureID());
fHWDrawState.fTexture = nextTexture;
}
- const GrSamplerState& lastSampler = nextTexture->samplerState();
- if (lastSampler.isFilter() != fCurrDrawState.fSamplerState.isFilter()) {
- GLenum filter = fCurrDrawState.fSamplerState.isFilter() ?
- GL_LINEAR :
- GL_NEAREST;
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- filter));
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- filter));
+ const GrGLTexture::TexParams& oldTexParams = nextTexture->getTexParams();
+ GrGLTexture::TexParams newTexParams;
+ newTexParams.fFilter = fCurrDrawState.fSamplerState.isFilter() ?
+ GL_LINEAR :
+ GL_NEAREST;
+ newTexParams.fWrapS = GrGLTexture::gWrapMode2GLWrap[fCurrDrawState.fSamplerState.getWrapX()];
+ newTexParams.fWrapT = GrGLTexture::gWrapMode2GLWrap[fCurrDrawState.fSamplerState.getWrapY()];
+
+ if (newTexParams.fFilter != oldTexParams.fFilter) {
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MAG_FILTER,
+ newTexParams.fFilter));
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MIN_FILTER,
+ newTexParams.fFilter));
}
- if (lastSampler.getWrapX() != fCurrDrawState.fSamplerState.getWrapX()) {
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GrGLTexture::gWrapMode2GLWrap[
- fCurrDrawState.fSamplerState.getWrapX()]));
+ if (newTexParams.fWrapS != oldTexParams.fWrapS) {
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_WRAP_S,
+ newTexParams.fWrapS));
}
- if (lastSampler.getWrapY() != fCurrDrawState.fSamplerState.getWrapY()) {
- GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GrGLTexture::gWrapMode2GLWrap[
- fCurrDrawState.fSamplerState.getWrapY()]));
+ if (newTexParams.fWrapT != oldTexParams.fWrapT) {
+ GR_GL(TexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_WRAP_T,
+ newTexParams.fWrapT));
}
- nextTexture->setSamplerState(fCurrDrawState.fSamplerState);
+ nextTexture->setTexParams(newTexParams);
} else {
GrAssert(!"Rendering with texture vert flag set but no texture");
if (NULL != fHWDrawState.fTexture) {
diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h
index bedb85af72..7701df99ee 100644
--- a/gpu/src/GrGpuGL.h
+++ b/gpu/src/GrGpuGL.h
@@ -98,9 +98,6 @@ protected:
// line width
void flushGLStateCommon(PrimitiveType type);
- // pushes the filtering and tiling modes to GL
- void setSamplerStateImm(const GrSamplerState& samplerState);
-
// set when this class changes the rendertarget.
// Subclass should notice at flush time, take appropriate action,
// and set false.