diff options
author | Jason Sams <rjsams@android.com> | 2010-01-25 12:31:24 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-01-25 12:41:19 -0800 |
commit | be504f2d0c5db4485e6db5b406e9e8b8c390dea9 (patch) | |
tree | 8a27d6a2d5acdf753e1205f66659b9e9bdaeb49c /rsVertexArray.cpp | |
parent | cc0ad35c1108e072221edc7f5accb8193ecdb861 (diff) | |
download | rs-be504f2d0c5db4485e6db5b406e9e8b8c390dea9.tar.gz |
Cleanup seperation of Legacy and user attribs. All user programs now use the new names. Legacy vertex attribs are given default names.
Diffstat (limited to 'rsVertexArray.cpp')
-rw-r--r-- | rsVertexArray.cpp | 228 |
1 files changed, 101 insertions, 127 deletions
diff --git a/rsVertexArray.cpp b/rsVertexArray.cpp index 7124eb56..a1fd7442 100644 --- a/rsVertexArray.cpp +++ b/rsVertexArray.cpp @@ -25,7 +25,7 @@ using namespace android::renderscript; VertexArray::VertexArray() { - mActiveBuffer = 0; + clearAll(); } VertexArray::~VertexArray() @@ -39,6 +39,7 @@ void VertexArray::clearAll() mAttribs[ct].clear(); } mActiveBuffer = 0; + mCount = 0; } VertexArray::Attrib::Attrib() @@ -54,6 +55,7 @@ void VertexArray::Attrib::set(const Attrib &a) size = a.size; stride = a.stride; normalized = a.normalized; + kind = RS_KIND_USER; name.setTo(a.name); } @@ -68,78 +70,42 @@ void VertexArray::Attrib::clear() name.setTo(""); } -void VertexArray::clear(AttribName n) +void VertexArray::clear(uint32_t n) { mAttribs[n].clear(); } -void VertexArray::setPosition(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset) -{ - mAttribs[POSITION].buffer = mActiveBuffer; - mAttribs[POSITION].type = type; - mAttribs[POSITION].size = size; - mAttribs[POSITION].offset = offset; - mAttribs[POSITION].stride = stride; - mAttribs[POSITION].normalized = false; -} - -void VertexArray::setColor(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset) -{ - mAttribs[COLOR].buffer = mActiveBuffer; - mAttribs[COLOR].type = type; - mAttribs[COLOR].size = size; - mAttribs[COLOR].offset = offset; - mAttribs[COLOR].stride = stride; - mAttribs[COLOR].normalized = type != GL_FLOAT; -} - -void VertexArray::setNormal(uint32_t type, uint32_t stride, uint32_t offset) -{ - mAttribs[NORMAL].buffer = mActiveBuffer; - mAttribs[NORMAL].type = type; - mAttribs[NORMAL].size = 3; - mAttribs[NORMAL].offset = offset; - mAttribs[NORMAL].stride = stride; - mAttribs[NORMAL].normalized = type != GL_FLOAT; -} - -void VertexArray::setPointSize(uint32_t type, uint32_t stride, uint32_t offset) +void VertexArray::addUser(const Attrib &a, uint32_t stride) { - mAttribs[POINT_SIZE].buffer = mActiveBuffer; - mAttribs[POINT_SIZE].type = type; - mAttribs[POINT_SIZE].size = 1; - mAttribs[POINT_SIZE].offset = offset; - mAttribs[POINT_SIZE].stride = stride; - mAttribs[POINT_SIZE].normalized = false; + assert(mCount < RS_MAX_ATTRIBS); + mAttribs[mCount].set(a); + mAttribs[mCount].buffer = mActiveBuffer; + mAttribs[mCount].stride = stride; + mAttribs[mCount].kind = RS_KIND_USER; + mCount ++; } -void VertexArray::setTexture(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset) +void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset) { - mAttribs[TEXTURE].buffer = mActiveBuffer; - mAttribs[TEXTURE].type = type; - mAttribs[TEXTURE].size = size; - mAttribs[TEXTURE].offset = offset; - mAttribs[TEXTURE].stride = stride; - mAttribs[TEXTURE].normalized = false; -} - -void VertexArray::setUser(const Attrib &a, uint32_t stride) -{ - // Find empty slot, some may be taken by legacy 1.1 slots. - uint32_t slot = 0; - while (mAttribs[slot].size) slot++; - rsAssert(slot < RS_MAX_ATTRIBS); - mAttribs[slot].set(a); - mAttribs[slot].buffer = mActiveBuffer; - mAttribs[slot].stride = stride; + assert(mCount < RS_MAX_ATTRIBS); + mAttribs[mCount].clear(); + mAttribs[mCount].type = type; + mAttribs[mCount].size = size; + mAttribs[mCount].offset = offset; + mAttribs[mCount].normalized = normalized; + mAttribs[mCount].buffer = mActiveBuffer; + mAttribs[mCount].stride = stride; + mAttribs[mCount].kind = kind; + mCount ++; } void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const { - LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx, slot, + LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x kind=%i stride=0x%x norm=%i offset=0x%x", idx, slot, mAttribs[idx].name.string(), mAttribs[idx].buffer, mAttribs[idx].size, mAttribs[idx].type, + mAttribs[idx].kind, mAttribs[idx].stride, mAttribs[idx].normalized, mAttribs[idx].offset); @@ -147,87 +113,95 @@ void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const { void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const { - if (mAttribs[POSITION].size) { - //logAttrib(POSITION); - glEnableClientState(GL_VERTEX_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[POSITION].buffer); - glVertexPointer(mAttribs[POSITION].size, - mAttribs[POSITION].type, - mAttribs[POSITION].stride, - (void *)mAttribs[POSITION].offset); - } else { - rsAssert(0); - } - - if (mAttribs[NORMAL].size) { - //logAttrib(NORMAL); - glEnableClientState(GL_NORMAL_ARRAY); - rsAssert(mAttribs[NORMAL].size == 3); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[NORMAL].buffer); - glNormalPointer(mAttribs[NORMAL].type, - mAttribs[NORMAL].stride, - (void *)mAttribs[NORMAL].offset); - } else { - glDisableClientState(GL_NORMAL_ARRAY); - } - - if (mAttribs[COLOR].size) { - //logAttrib(COLOR); - glEnableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[COLOR].buffer); - glColorPointer(mAttribs[COLOR].size, - mAttribs[COLOR].type, - mAttribs[COLOR].stride, - (void *)mAttribs[COLOR].offset); - } else { - glDisableClientState(GL_COLOR_ARRAY); - } - glClientActiveTexture(GL_TEXTURE0); - if (mAttribs[TEXTURE].size) { - //logAttrib(TEXTURE); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[TEXTURE].buffer); - glTexCoordPointer(mAttribs[TEXTURE].size, - mAttribs[TEXTURE].type, - mAttribs[TEXTURE].stride, - (void *)mAttribs[TEXTURE].offset); - } else { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_POINT_SIZE_ARRAY_OES); + + for (uint32_t ct=0; ct < mCount; ct++) { + switch(mAttribs[ct].kind) { + case RS_KIND_POSITION: + //logAttrib(POSITION); + glEnableClientState(GL_VERTEX_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + glVertexPointer(mAttribs[ct].size, + mAttribs[ct].type, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); + break; + + case RS_KIND_NORMAL: + //logAttrib(NORMAL); + glEnableClientState(GL_NORMAL_ARRAY); + rsAssert(mAttribs[ct].size == 3); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + glNormalPointer(mAttribs[ct].type, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); + break; + + case RS_KIND_COLOR: + //logAttrib(COLOR); + glEnableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + glColorPointer(mAttribs[ct].size, + mAttribs[ct].type, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); + break; + + case RS_KIND_TEXTURE: + //logAttrib(TEXTURE); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + glTexCoordPointer(mAttribs[ct].size, + mAttribs[ct].type, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); + break; + + case RS_KIND_POINT_SIZE: + //logAttrib(POINT_SIZE); + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + glPointSizePointerOES(mAttribs[ct].type, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); + break; - if (mAttribs[POINT_SIZE].size) { - //logAttrib(POINT_SIZE); - glEnableClientState(GL_POINT_SIZE_ARRAY_OES); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[POINT_SIZE].buffer); - glPointSizePointerOES(mAttribs[POINT_SIZE].type, - mAttribs[POINT_SIZE].stride, - (void *)mAttribs[POINT_SIZE].offset); - } else { - glDisableClientState(GL_POINT_SIZE_ARRAY_OES); + default: + rsAssert(0); + } } + rsc->checkError("VertexArray::setupGL"); } void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const { - for (int ct=1; ct < _LAST; ct++) { + for (int ct=1; ct < RS_MAX_ATTRIBS; ct++) { glDisableVertexAttribArray(ct); } - for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) { - if (mAttribs[ct].size && (sc->vtxAttribSlot(ct) >= 0)) { - //logAttrib(ct, sc->vtxAttribSlot(ct)); - glEnableVertexAttribArray(sc->vtxAttribSlot(ct)); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - - glVertexAttribPointer(sc->vtxAttribSlot(ct), - mAttribs[ct].size, - mAttribs[ct].type, - mAttribs[ct].normalized, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); + for (uint32_t ct=0; ct < mCount; ct++) { + uint32_t slot = 0; + if (sc->isUserVertexProgram()) { + slot = sc->vtxAttribSlot(ct); + } else { + slot = sc->vtxAttribSlot(mAttribs[ct].kind); } + + //logAttrib(ct, slot); + glEnableVertexAttribArray(slot); + glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); + + glVertexAttribPointer(slot, + mAttribs[ct].size, + mAttribs[ct].type, + mAttribs[ct].normalized, + mAttribs[ct].stride, + (void *)mAttribs[ct].offset); } rsc->checkError("VertexArray::setupGL2"); } |