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.cpp119
1 files changed, 36 insertions, 83 deletions
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index 6c2002d..001927c 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -14,10 +14,15 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-
#include <GLES/gl.h>
#include <GLES2/gl2.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif
+
using namespace android;
using namespace android::renderscript;
@@ -39,6 +44,7 @@ void VertexArray::clearAll()
mAttribs[ct].clear();
}
mActiveBuffer = 0;
+ mActivePointer = NULL;
mCount = 0;
}
@@ -50,12 +56,12 @@ VertexArray::Attrib::Attrib()
void VertexArray::Attrib::set(const Attrib &a)
{
buffer = a.buffer;
+ ptr = a.ptr;
offset = a.offset;
type = a.type;
size = a.size;
stride = a.stride;
normalized = a.normalized;
- kind = RS_KIND_USER;
name.setTo(a.name);
}
@@ -66,6 +72,7 @@ void VertexArray::Attrib::clear()
type = 0;
size = 0;
stride = 0;
+ ptr = NULL;
normalized = false;
name.setTo("");
}
@@ -75,138 +82,84 @@ void VertexArray::clear(uint32_t n)
mAttribs[n].clear();
}
-void VertexArray::addUser(const Attrib &a, uint32_t stride)
+void VertexArray::add(const Attrib &a, uint32_t stride)
{
- assert(mCount < RS_MAX_ATTRIBS);
+ rsAssert(mCount < RS_MAX_ATTRIBS);
mAttribs[mCount].set(a);
mAttribs[mCount].buffer = mActiveBuffer;
+ mAttribs[mCount].ptr = mActivePointer;
mAttribs[mCount].stride = stride;
- mAttribs[mCount].kind = RS_KIND_USER;
mCount ++;
}
-void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset)
+void VertexArray::add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name)
{
- assert(mCount < RS_MAX_ATTRIBS);
+ rsAssert(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;
+ mAttribs[mCount].name.setTo(name);
+
+ mAttribs[mCount].buffer = mActiveBuffer;
+ mAttribs[mCount].ptr = mActivePointer;
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 kind=%i stride=0x%x norm=%i offset=0x%x", idx, slot,
+ LOGE("va %i: slot=%i name=%s buf=%i ptr=%p size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx, slot,
mAttribs[idx].name.string(),
mAttribs[idx].buffer,
+ mAttribs[idx].ptr,
mAttribs[idx].size,
mAttribs[idx].type,
- mAttribs[idx].kind,
mAttribs[idx].stride,
mAttribs[idx].normalized,
mAttribs[idx].offset);
}
-void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const
-{
- glClientActiveTexture(GL_TEXTURE0);
- 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;
-
- default:
- rsAssert(0);
- }
- }
-
- rsc->checkError("VertexArray::setupGL");
-}
-
void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const
{
rsc->checkError("VertexArray::setupGL2 start");
- for (uint32_t ct=1; ct <= state->mLastEnableCount; ct++) {
+ for (uint32_t ct=1; ct <= 0xf/*state->mLastEnableCount*/; ct++) {
glDisableVertexAttribArray(ct);
}
rsc->checkError("VertexArray::setupGL2 disabled");
for (uint32_t ct=0; ct < mCount; ct++) {
uint32_t slot = 0;
+
+ if (mAttribs[ct].name[0] == '#') {
+ continue;
+ }
+
if (sc->isUserVertexProgram()) {
slot = sc->vtxAttribSlot(ct);
} else {
- if (mAttribs[ct].kind == RS_KIND_USER) {
+ if (mAttribs[ct].name == "position") {
+ slot = 0;
+ } else if (mAttribs[ct].name == "color") {
+ slot = 1;
+ } else if (mAttribs[ct].name == "normal") {
+ slot = 2;
+ } else if (mAttribs[ct].name == "texture0") {
+ slot = 3;
+ } else {
continue;
}
- 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);
+ mAttribs[ct].ptr + mAttribs[ct].offset);
}
state->mLastEnableCount = mCount;
rsc->checkError("VertexArray::setupGL2 done");