summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsVertexArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsVertexArray.cpp')
-rw-r--r--libs/rs/rsVertexArray.cpp100
1 files changed, 66 insertions, 34 deletions
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index 2ba0ef9..7124eb5 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -25,7 +25,6 @@ using namespace android::renderscript;
VertexArray::VertexArray()
{
- memset(mAttribs, 0, sizeof(mAttribs));
mActiveBuffer = 0;
}
@@ -36,13 +35,42 @@ VertexArray::~VertexArray()
void VertexArray::clearAll()
{
- memset(mAttribs, 0, sizeof(mAttribs));
+ for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
+ mAttribs[ct].clear();
+ }
mActiveBuffer = 0;
}
+VertexArray::Attrib::Attrib()
+{
+ clear();
+}
+
+void VertexArray::Attrib::set(const Attrib &a)
+{
+ buffer = a.buffer;
+ offset = a.offset;
+ type = a.type;
+ size = a.size;
+ stride = a.stride;
+ normalized = a.normalized;
+ name.setTo(a.name);
+}
+
+void VertexArray::Attrib::clear()
+{
+ buffer = 0;
+ offset = 0;
+ type = 0;
+ size = 0;
+ stride = 0;
+ normalized = false;
+ name.setTo("");
+}
+
void VertexArray::clear(AttribName n)
{
- mAttribs[n].size = 0;
+ mAttribs[n].clear();
}
void VertexArray::setPosition(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset)
@@ -85,18 +113,30 @@ void VertexArray::setPointSize(uint32_t type, uint32_t stride, uint32_t offset)
mAttribs[POINT_SIZE].normalized = false;
}
-void VertexArray::setTexture(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset, uint32_t num)
+void VertexArray::setTexture(uint32_t size, uint32_t type, uint32_t stride, 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)
{
- mAttribs[TEXTURE_0 + num].buffer = mActiveBuffer;
- mAttribs[TEXTURE_0 + num].type = type;
- mAttribs[TEXTURE_0 + num].size = size;
- mAttribs[TEXTURE_0 + num].offset = offset;
- mAttribs[TEXTURE_0 + num].stride = stride;
- mAttribs[TEXTURE_0 + num].normalized = false;
+ // 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;
}
-void VertexArray::logAttrib(uint32_t idx) const {
- LOGE("va %i: buf=%i size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx,
+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,
+ mAttribs[idx].name.string(),
mAttribs[idx].buffer,
mAttribs[idx].size,
mAttribs[idx].type,
@@ -143,21 +183,18 @@ void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) con
glDisableClientState(GL_COLOR_ARRAY);
}
- for (uint32_t ct=0; ct < RS_MAX_TEXTURE; ct++) {
- glClientActiveTexture(GL_TEXTURE0 + ct);
- if (mAttribs[TEXTURE_0 + ct].size) {
- //logAttrib(TEXTURE_0 + ct);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[TEXTURE_0 + ct].buffer);
- glTexCoordPointer(mAttribs[TEXTURE_0 + ct].size,
- mAttribs[TEXTURE_0 + ct].type,
- mAttribs[TEXTURE_0 + ct].stride,
- (void *)mAttribs[TEXTURE_0 + ct].offset);
- } else {
- glDisableClientState(GL_TEXTURE_COORD_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);
+ }
if (mAttribs[POINT_SIZE].size) {
//logAttrib(POINT_SIZE);
@@ -178,12 +215,11 @@ void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, Sh
glDisableVertexAttribArray(ct);
}
- for (int ct=0; ct < _LAST; ct++) {
- if (mAttribs[ct].size) {
- //logAttrib(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);
- //LOGV("attp %i %i", ct, sc->vtxAttribSlot(ct));
glVertexAttribPointer(sc->vtxAttribSlot(ct),
mAttribs[ct].size,
@@ -191,9 +227,6 @@ void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, Sh
mAttribs[ct].normalized,
mAttribs[ct].stride,
(void *)mAttribs[ct].offset);
- } else {
- //glDisableVertexAttribArray(ct);
- rsAssert(ct);
}
}
rsc->checkError("VertexArray::setupGL2");
@@ -201,6 +234,5 @@ void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, Sh
////////////////////////////////////////////
void VertexArrayState::init(Context *) {
- memset(this, 0, sizeof(this));
}