aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/src/GrGpuGLFixed.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-14 16:51:21 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-14 16:51:21 +0000
commit1c13c9668a889e56a0c85b51b9f28139c25b76ff (patch)
tree0319884473e77141a574ab07333c6ed4797f7485 /gpu/src/GrGpuGLFixed.cpp
parentdd53d91b60e368f1bbff6fb22d796765205ae25d (diff)
Refactor how Gr handles vertex and index data. GrGpu and GrInOrderDrawBuffer both GrBufferAllocPool to manage reserved and set-to-array vertex and index data.
rietveld issue 4188049 git-svn-id: http://skia.googlecode.com/svn/trunk@786 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrGpuGLFixed.cpp')
-rw-r--r--gpu/src/GrGpuGLFixed.cpp68
1 files changed, 40 insertions, 28 deletions
diff --git a/gpu/src/GrGpuGLFixed.cpp b/gpu/src/GrGpuGLFixed.cpp
index a028cba154..76494de34c 100644
--- a/gpu/src/GrGpuGLFixed.cpp
+++ b/gpu/src/GrGpuGLFixed.cpp
@@ -95,7 +95,7 @@ void GrGpuGLFixed::resetContextHelper() {
}
fHWGeometryState.fVertexLayout = 0;
- fHWGeometryState.fPositionPtr = (void*) ~0;
+ fHWGeometryState.fVertexOffset = ~0;
GR_GL(EnableClientState(GL_VERTEX_ARRAY));
GR_GL(DisableClientState(GL_TEXTURE_COORD_ARRAY));
GR_GL(ShadeModel(GL_FLAT));
@@ -246,10 +246,10 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
return true;
}
-void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
- uint32_t startIndex,
- uint32_t vertexCount,
- uint32_t indexCount) {
+void GrGpuGLFixed::setupGeometry(int* startVertex,
+ int* startIndex,
+ int vertexCount,
+ int indexCount) {
int newColorOffset;
int newTexCoordOffsets[kNumStages];
@@ -263,9 +263,11 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
oldTexCoordOffsets,
&oldColorOffset);
- const GLvoid* posPtr = setBuffersAndGetVertexStart(newStride, startVertex,
- startIndex, vertexCount,
- indexCount);
+ bool indexed = NULL == startIndex;
+
+ int extraVertexOffset;
+ int extraIndexOffset;
+ setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
GLenum scalarType;
if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) {
@@ -274,32 +276,43 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
scalarType = GrGLType;
}
- bool baseChange = posPtr != fHWGeometryState.fPositionPtr;
- bool scalarChange =
- (GrGLTextType != GrGLType) &&
- (kTextFormat_VertexLayoutBit &
- (fHWGeometryState.fVertexLayout ^ fGeometrySrc.fVertexLayout));
- bool strideChange = newStride != oldStride;
- bool posChange = baseChange || scalarChange || strideChange;
-
- if (posChange || fHWGeometryState.fArrayPtrsDirty) {
- GR_GL(VertexPointer(2, scalarType, newStride, posPtr));
- fHWGeometryState.fPositionPtr = posPtr;
+ size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
+ *startVertex = 0;
+ if (indexed) {
+ *startIndex += extraIndexOffset;
+ }
+
+ // all the Pointers must be set if any of these are true
+ bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty ||
+ vertexOffset != fHWGeometryState.fVertexOffset ||
+ newStride != oldStride;
+
+ // position and tex coord offsets change if above conditions are true
+ // or the type changed based on text vs nontext type coords.
+ bool posAndTexChange = allOffsetsChange ||
+ ((GrGLTextType != GrGLType) &&
+ (kTextFormat_VertexLayoutBit &
+ (fHWGeometryState.fVertexLayout ^
+ fGeometrySrc.fVertexLayout)));
+
+ if (posAndTexChange) {
+ GR_GL(VertexPointer(2, scalarType, newStride, (GLvoid*)vertexOffset));
+ fHWGeometryState.fVertexOffset = vertexOffset;
}
for (int s = 0; s < kNumStages; ++s) {
// need to enable array if tex coord offset is 0
// (using positions as coords)
if (newTexCoordOffsets[s] >= 0) {
- GLvoid* texCoordPtr = (int8_t*)posPtr + newTexCoordOffsets[s];
+ GLvoid* texCoordOffset = (GLvoid*)(vertexOffset + newTexCoordOffsets[s]);
if (oldTexCoordOffsets[s] < 0) {
GR_GL(ClientActiveTexture(GL_TEXTURE0+s));
GR_GL(EnableClientState(GL_TEXTURE_COORD_ARRAY));
- GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr));
- } else if (fHWGeometryState.fArrayPtrsDirty || posChange ||
+ GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
+ } else if (posAndTexChange ||
newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
GR_GL(ClientActiveTexture(GL_TEXTURE0+s));
- GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr));
+ GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
}
} else if (oldTexCoordOffsets[s] >= 0) {
GR_GL(ClientActiveTexture(GL_TEXTURE0+s));
@@ -308,13 +321,12 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
}
if (newColorOffset > 0) {
- GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset;
+ GLvoid* colorOffset = (GLvoid*)(vertexOffset + newColorOffset);
if (oldColorOffset <= 0) {
GR_GL(EnableClientState(GL_COLOR_ARRAY));
- GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr));
- } else if (fHWGeometryState.fArrayPtrsDirty || posChange ||
- newColorOffset != oldColorOffset) {
- GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr));
+ GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorOffset));
+ } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
+ GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorOffset));
}
} else if (oldColorOffset > 0) {
GR_GL(DisableClientState(GL_COLOR_ARRAY));