Increase number of stages from 1 to 2
Move GrTextContext from stage 0 to stage 1 so it doesn't conflict with GrPaint (allow textured text) Switch to dynamically generated shaders git-svn-id: http://skia.googlecode.com/svn/trunk@721 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
1a2e8d233d
commit
7d34d2eecc
@ -50,7 +50,7 @@ public:
|
||||
|
||||
// Currently there is just one stage but this will be changed soon.
|
||||
enum {
|
||||
kNumStages = 1,
|
||||
kNumStages = 2,
|
||||
kMaxTexCoords = kNumStages
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
void flush(); // optional; automatically called by destructor
|
||||
|
||||
private:
|
||||
const GrPaint& fPaint;
|
||||
GrPaint fPaint;
|
||||
GrVertexLayout fVertexLayout;
|
||||
GrContext* fContext;
|
||||
GrDrawTarget* fDrawTarget;
|
||||
|
||||
|
@ -472,9 +472,14 @@ void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
|
||||
|
||||
GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) {
|
||||
fDrawTarget = target;
|
||||
fDrawTarget->saveCurrentDrawState(&fDrawState);
|
||||
if (NULL != fDrawTarget) {
|
||||
fDrawTarget->saveCurrentDrawState(&fDrawState);
|
||||
}
|
||||
}
|
||||
|
||||
GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
|
||||
fDrawTarget->restoreDrawState(fDrawState);
|
||||
if (NULL != fDrawTarget) {
|
||||
fDrawTarget->restoreDrawState(fDrawState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,9 @@ void GrGpu::resetContext() {
|
||||
}
|
||||
|
||||
void GrGpu::unimpl(const char msg[]) {
|
||||
// GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
|
||||
#if GR_DEBUG
|
||||
GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include "GrGLConfig.h"
|
||||
|
||||
#define GR_USE_GLSHADERS2 0
|
||||
#define GR_USE_GLSHADERS2 1
|
||||
|
||||
#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
|
||||
#include "GrGpuGLFixed.h"
|
||||
|
@ -1019,9 +1019,13 @@ void GrGpuGL::flushScissor(const GrIRect* rect) {
|
||||
}
|
||||
|
||||
void GrGpuGL::eraseColor(GrColor color) {
|
||||
if (NULL == fCurrDrawState.fRenderTarget) {
|
||||
return;
|
||||
}
|
||||
flushRenderTarget();
|
||||
if (fHWBounds.fScissorEnabled) {
|
||||
GR_GL(Disable(GL_SCISSOR_TEST));
|
||||
fHWBounds.fScissorEnabled = false;
|
||||
}
|
||||
GR_GL(ColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE));
|
||||
GR_GL(ClearColor(GrColorUnpackR(color)/255.f,
|
||||
@ -1029,19 +1033,21 @@ void GrGpuGL::eraseColor(GrColor color) {
|
||||
GrColorUnpackB(color)/255.f,
|
||||
GrColorUnpackA(color)/255.f));
|
||||
GR_GL(Clear(GL_COLOR_BUFFER_BIT));
|
||||
fHWBounds.fScissorEnabled = false;
|
||||
fWriteMaskChanged = true;
|
||||
}
|
||||
|
||||
void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) {
|
||||
if (NULL == fCurrDrawState.fRenderTarget) {
|
||||
return;
|
||||
}
|
||||
flushRenderTarget();
|
||||
if (fHWBounds.fScissorEnabled) {
|
||||
GR_GL(Disable(GL_SCISSOR_TEST));
|
||||
fHWBounds.fScissorEnabled = false;
|
||||
}
|
||||
GR_GL(StencilMask(mask));
|
||||
GR_GL(ClearStencil(value));
|
||||
GR_GL(Clear(GL_STENCIL_BUFFER_BIT));
|
||||
fHWBounds.fScissorEnabled = false;
|
||||
fWriteMaskChanged = true;
|
||||
}
|
||||
|
||||
|
@ -236,13 +236,17 @@ static uint32_t ror(uint32_t x) {
|
||||
return (x >> 8) | (x << 24);
|
||||
}
|
||||
|
||||
static uint32_t rol(uint32_t x) {
|
||||
return (x << 8) | (x >> 24);
|
||||
}
|
||||
|
||||
GrGpuGLShaders2::ProgramCache::HashKey::HashKey(const ProgramDesc& desc) {
|
||||
fDesc = desc;
|
||||
// if you change the size of the desc, need to update the hash function
|
||||
GR_STATIC_ASSERT(8 == sizeof(ProgramDesc));
|
||||
GR_STATIC_ASSERT(12 == sizeof(ProgramDesc));
|
||||
|
||||
uint32_t* d = (uint32_t*) &fDesc;
|
||||
fHash = d[0] ^ ror(d[1]);
|
||||
fHash = d[0] ^ ror(d[1]) ^ rol(d[2]);
|
||||
}
|
||||
|
||||
bool GrGpuGLShaders2::ProgramCache::HashKey::EQ(const Entry& entry,
|
||||
@ -267,7 +271,6 @@ uint32_t GrGpuGLShaders2::ProgramCache::HashKey::getHash() const {
|
||||
return fHash;
|
||||
}
|
||||
|
||||
|
||||
struct GrGpuGLShaders2::ShaderCodeSegments {
|
||||
GrSStringBuilder<256> fVSUnis;
|
||||
GrSStringBuilder<256> fVSAttrs;
|
||||
|
@ -23,9 +23,11 @@
|
||||
#include "GrTextStrike_impl.h"
|
||||
#include "GrFontScaler.h"
|
||||
|
||||
static const GrVertexLayout VLAYOUT =
|
||||
GrDrawTarget::kTextFormat_VertexLayoutBit |
|
||||
GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
|
||||
static const int TEXT_STAGE = 1;
|
||||
|
||||
static const GrVertexLayout BASE_VLAYOUT =
|
||||
GrDrawTarget::kTextFormat_VertexLayoutBit |
|
||||
GrDrawTarget::StageTexCoordVertexLayoutBit(TEXT_STAGE,0);
|
||||
|
||||
void GrTextContext::flushGlyphs() {
|
||||
if (fCurrVertex > 0) {
|
||||
@ -36,18 +38,17 @@ void GrTextContext::flushGlyphs() {
|
||||
GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
|
||||
GrSamplerState::kRepeat_WrapMode,
|
||||
!fExtMatrix.isIdentity());
|
||||
fDrawTarget->setSamplerState(0, sampler);
|
||||
fDrawTarget->setSamplerState(TEXT_STAGE, sampler);
|
||||
|
||||
GrAssert(GrIsALIGN4(fCurrVertex));
|
||||
int nIndices = fCurrVertex + (fCurrVertex >> 1);
|
||||
GrAssert(fCurrTexture);
|
||||
fDrawTarget->setTexture(0, fCurrTexture);
|
||||
fDrawTarget->setTextureMatrix(0, GrMatrix::I());
|
||||
fDrawTarget->setTexture(TEXT_STAGE, fCurrTexture);
|
||||
fDrawTarget->setTextureMatrix(TEXT_STAGE, GrMatrix::I());
|
||||
fDrawTarget->setIndexSourceToBuffer(fContext->quadIndexBuffer());
|
||||
|
||||
fDrawTarget->drawIndexed(GrDrawTarget::kTriangles_PrimitiveType,
|
||||
0, 0, fCurrVertex, nIndices);
|
||||
|
||||
fDrawTarget->releaseReservedGeometry();
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
@ -82,9 +83,20 @@ GrTextContext::GrTextContext(GrContext* context,
|
||||
}
|
||||
}
|
||||
|
||||
// save the context's original matrix off and restore in destructor
|
||||
// this must be done before getTextTarget.
|
||||
fOrigViewMatrix = fContext->getMatrix();
|
||||
fContext->setMatrix(fExtMatrix);
|
||||
|
||||
fVertexLayout = BASE_VLAYOUT;
|
||||
if (NULL != paint.getTexture()) {
|
||||
fVertexLayout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
|
||||
GrMatrix inverseViewMatrix;
|
||||
if (fOrigViewMatrix.invert(&inverseViewMatrix)) {
|
||||
fPaint.fTextureMatrix.preConcat(inverseViewMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||
@ -191,7 +203,7 @@ HAS_ATLAS:
|
||||
// If we need to reserve vertices allow the draw target to suggest
|
||||
// a number of verts to reserve and whether to perform a flush.
|
||||
fMaxVertices = kMinRequestedVerts;
|
||||
bool flush = fDrawTarget->geometryHints(VLAYOUT,
|
||||
bool flush = fDrawTarget->geometryHints(fVertexLayout,
|
||||
&fMaxVertices,
|
||||
NULL);
|
||||
if (flush) {
|
||||
@ -200,7 +212,7 @@ HAS_ATLAS:
|
||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||
fMaxVertices = kDefaultRequestedVerts;
|
||||
// ignore return, no point in flushing again.
|
||||
fDrawTarget->geometryHints(VLAYOUT,
|
||||
fDrawTarget->geometryHints(fVertexLayout,
|
||||
&fMaxVertices,
|
||||
NULL);
|
||||
}
|
||||
@ -211,7 +223,7 @@ HAS_ATLAS:
|
||||
// don't exceed the limit of the index buffer
|
||||
fMaxVertices = (fContext->maxQuadsInIndexBuffer() * 4);
|
||||
}
|
||||
bool success = fDrawTarget->reserveAndLockGeometry(VLAYOUT,
|
||||
bool success = fDrawTarget->reserveAndLockGeometry(fVertexLayout,
|
||||
fMaxVertices, 0,
|
||||
GrTCast<void**>(&fVertices),
|
||||
NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user