summaryrefslogtreecommitdiff
path: root/rsMesh.cpp
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-05-21 12:53:13 -0700
committerAlex Sakhartchouk <alexst@google.com>2010-05-21 14:00:10 -0700
commitfb6b614bcea88a587a7ea4530be45ff0ffa0210e (patch)
treea2a4b9bd296205421c718f1581e9b5824c7305ee /rsMesh.cpp
parent66070bf7aae61cedde97cfdeb6a64f435abe8cde (diff)
downloadrs-fb6b614bcea88a587a7ea4530be45ff0ffa0210e.tar.gz
Removed unnecessary change based on comments.
Now using android utils lib. collada_to_a3d seems to work with android util libs. Integrating old changelist Changing assert to rsAssrt in VertexArray making context compile. Change-Id: I33890defa777f09253bfab630d97782359ec49d7 Added serialization code to rsLib Integrated old changelist Change-Id: Ie4746113f6d1817fbb3264f97fdddde25b779311 Added serialization code to rsLib Change-Id: Ie4746113f6d1817fbb3264f97fdddde25b779311
Diffstat (limited to 'rsMesh.cpp')
-rw-r--r--rsMesh.cpp171
1 files changed, 168 insertions, 3 deletions
diff --git a/rsMesh.cpp b/rsMesh.cpp
index d595b4e0..b51e28a4 100644
--- a/rsMesh.cpp
+++ b/rsMesh.cpp
@@ -14,13 +14,22 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-using namespace android;
-using namespace android::renderscript;
-
#include <GLES/gl.h>
+#include <GLES2/gl2.h>
#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif
+
+
+using namespace android;
+using namespace android::renderscript;
Mesh::Mesh(Context *rsc) : ObjectBase(rsc)
{
@@ -36,6 +45,162 @@ Mesh::~Mesh()
{
}
+void Mesh::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ stream->addU32(mVerticiesCount);
+
+ for(uint32_t vCount = 0; vCount < mVerticiesCount; vCount ++) {
+ Verticies_t *verts = mVerticies[vCount];
+
+ stream->addU32(verts->mAllocationCount);
+
+ for (uint32_t aCount = 0; aCount < verts->mAllocationCount; aCount++) {
+ verts->mAllocations[aCount]->serialize(stream);
+ }
+ stream->addU32(verts->mVertexDataSize);
+
+ stream->addU32(verts->mOffsetCoord);
+ stream->addU32(verts->mOffsetTex);
+ stream->addU32(verts->mOffsetNorm);
+
+ stream->addU32(verts->mSizeCoord);
+ stream->addU32(verts->mSizeTex);
+ stream->addU32(verts->mSizeNorm );
+ }
+
+ stream->addU32(mPrimitivesCount);
+ // Store the primitives
+ for (uint32_t pCount = 0; pCount < mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = mPrimitives[pCount];
+
+ stream->addU8((uint8_t)prim->mType);
+
+ // We store the index to the vertices
+ // So iterate over our vertices to find which one we point to
+ uint32_t vertexIndex = 0;
+ for(uint32_t vCount = 0; vCount < mVerticiesCount; vCount ++) {
+ if(prim->mVerticies == mVerticies[vCount]) {
+ vertexIndex = vCount;
+ break;
+ }
+ }
+ stream->addU32(vertexIndex);
+
+ stream->addU32(prim->mIndexCount);
+ for (uint32_t ct = 0; ct < prim->mIndexCount; ct++) {
+ stream->addU16(prim->mIndicies[ct]);
+ }
+
+ stream->addU32(prim->mRestartCounts);
+ for (uint32_t ct = 0; ct < prim->mRestartCounts; ct++) {
+ stream->addU16(prim->mRestarts[ct]);
+ }
+ }
+}
+
+Mesh *Mesh::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ A3DClassID classID = (A3DClassID)stream->loadU32();
+ if(classID != A3D_CLASS_ID_MESH) {
+ LOGE("mesh loading skipped due to invalid class id");
+ return NULL;
+ }
+
+ Mesh * mesh = new Mesh(rsc);
+
+ String8 name;
+ stream->loadString(&name);
+ mesh->setName(name.string(), name.size());
+
+ mesh->mVerticiesCount = stream->loadU32();
+ if(mesh->mVerticiesCount) {
+ mesh->mVerticies = new Verticies_t *[mesh->mVerticiesCount];
+ }
+ else {
+ mesh->mVerticies = NULL;
+ }
+
+ for(uint32_t vCount = 0; vCount < mesh->mVerticiesCount; vCount ++) {
+ Verticies_t *verts = new Verticies_t();
+ // Store our vertices one the mesh
+ mesh->mVerticies[vCount] = verts;
+
+ verts->mAllocationCount = stream->loadU32();
+ verts->mAllocations = new Allocation *[verts->mAllocationCount];
+
+ LOGE("processChunk_Verticies count %i", verts->mAllocationCount);
+ for (uint32_t aCount = 0; aCount < verts->mAllocationCount; aCount++) {
+ verts->mAllocations[aCount] = Allocation::createFromStream(rsc, stream);
+ }
+ verts->mVertexDataSize = stream->loadU32();
+
+ verts->mOffsetCoord = stream->loadU32();
+ verts->mOffsetTex = stream->loadU32();
+ verts->mOffsetNorm = stream->loadU32();
+
+ verts->mSizeCoord = stream->loadU32();
+ verts->mSizeTex = stream->loadU32();
+ verts->mSizeNorm = stream->loadU32();
+ }
+
+ mesh->mPrimitivesCount = stream->loadU32();
+ if(mesh->mPrimitivesCount) {
+ mesh->mPrimitives = new Primitive_t *[mesh->mPrimitivesCount];
+ }
+ else {
+ mesh->mPrimitives = NULL;
+ }
+
+ // load all primitives
+ for (uint32_t pCount = 0; pCount < mesh->mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = new Primitive_t;
+ mesh->mPrimitives[pCount] = prim;
+
+ prim->mType = (RsPrimitive)stream->loadU8();
+
+ // We store the index to the vertices
+ uint32_t vertexIndex = stream->loadU32();
+ if(vertexIndex < mesh->mVerticiesCount) {
+ prim->mVerticies = mesh->mVerticies[vertexIndex];
+ }
+ else {
+ prim->mVerticies = NULL;
+ }
+
+ prim->mIndexCount = stream->loadU32();
+ if(prim->mIndexCount){
+ prim->mIndicies = new uint16_t[prim->mIndexCount];
+ for (uint32_t ct = 0; ct < prim->mIndexCount; ct++) {
+ prim->mIndicies[ct] = stream->loadU16();
+ }
+ }
+ else {
+ prim->mIndicies = NULL;
+ }
+
+ prim->mRestartCounts = stream->loadU32();
+ if (prim->mRestartCounts) {
+ prim->mRestarts = new uint16_t[prim->mRestartCounts];
+ for (uint32_t ct = 0; ct < prim->mRestartCounts; ct++) {
+ prim->mRestarts[ct] = stream->loadU16();
+
+ }
+ }
+ else {
+ prim->mRestarts = NULL;
+ }
+
+ }
+
+ return mesh;
+}
MeshContext::MeshContext()