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.cpp183
1 files changed, 39 insertions, 144 deletions
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index 6c2002d..5062156 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -14,199 +14,94 @@
* 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;
-
-VertexArray::VertexArray()
-{
- clearAll();
-}
-
-VertexArray::~VertexArray()
-{
+VertexArray::VertexArray(const Attrib *attribs, uint32_t numAttribs) {
+ mAttribs = attribs;
+ mCount = numAttribs;
}
-
-void VertexArray::clearAll()
-{
- for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
- mAttribs[ct].clear();
- }
- mActiveBuffer = 0;
- mCount = 0;
+VertexArray::~VertexArray() {
}
-VertexArray::Attrib::Attrib()
-{
+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;
- kind = RS_KIND_USER;
- name.setTo(a.name);
-}
-
-void VertexArray::Attrib::clear()
-{
+void VertexArray::Attrib::clear() {
buffer = 0;
offset = 0;
type = 0;
size = 0;
stride = 0;
+ ptr = NULL;
normalized = false;
name.setTo("");
}
-void VertexArray::clear(uint32_t n)
-{
- mAttribs[n].clear();
-}
-
-void VertexArray::addUser(const Attrib &a, uint32_t stride)
-{
- 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::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset)
-{
- 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::Attrib::set(uint32_t type, uint32_t size, uint32_t stride,
+ bool normalized, uint32_t offset,
+ const char *name) {
+ clear();
+ this->type = type;
+ this->size = size;
+ this->offset = offset;
+ this->normalized = normalized;
+ this->stride = stride;
+ this->name.setTo(name);
}
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,
+ if (idx == 0) {
+ LOGV("Starting vertex attribute binding");
+ }
+ LOGV("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
-{
+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 (sc->isUserVertexProgram()) {
- slot = sc->vtxAttribSlot(ct);
- } else {
- if (mAttribs[ct].kind == RS_KIND_USER) {
- continue;
- }
- slot = sc->vtxAttribSlot(mAttribs[ct].kind);
+ int32_t slot = sc->vtxAttribSlot(mAttribs[ct].name);
+ if (rsc->props.mLogShadersAttr) {
+ logAttrib(ct, slot);
+ }
+ if (slot < 0) {
+ continue;
}
-
- //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");