Code cleanup to make formatting consistent
across all the renderscript files.
Change-Id: Idf5fcc60877e44c8f074f7176e37f70b3b895a3c
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index f2dd687..baf4c53 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -27,12 +27,10 @@
#include <OpenGl/glext.h>
#endif
-
using namespace android;
using namespace android::renderscript;
-Mesh::Mesh(Context *rsc) : ObjectBase(rsc)
-{
+Mesh::Mesh(Context *rsc) : ObjectBase(rsc) {
mPrimitives = NULL;
mPrimitivesCount = 0;
mVertexBuffers = NULL;
@@ -43,20 +41,19 @@
mAttribCount = 0;
}
-Mesh::~Mesh()
-{
- if(mVertexBuffers) {
+Mesh::~Mesh() {
+ if (mVertexBuffers) {
delete[] mVertexBuffers;
}
- if(mPrimitives) {
- for(uint32_t i = 0; i < mPrimitivesCount; i ++) {
+ if (mPrimitives) {
+ for (uint32_t i = 0; i < mPrimitivesCount; i ++) {
delete mPrimitives[i];
}
delete[] mPrimitives;
}
- if(mAttribs) {
+ if (mAttribs) {
delete[] mAttribs;
delete[] mAttribAllocationIndex;
}
@@ -64,14 +61,14 @@
bool Mesh::isValidGLComponent(const Element *elem, uint32_t fieldIdx) {
// Do not create attribs for padding
- if(elem->getFieldName(fieldIdx)[0] == '#') {
+ if (elem->getFieldName(fieldIdx)[0] == '#') {
return false;
}
// Only GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED, GL_FLOAT are accepted.
// Filter rs types accordingly
RsDataType dt = elem->getField(fieldIdx)->getComponent().getType();
- if(dt != RS_TYPE_FLOAT_32 && dt != RS_TYPE_UNSIGNED_8 &&
+ if (dt != RS_TYPE_FLOAT_32 && dt != RS_TYPE_UNSIGNED_8 &&
dt != RS_TYPE_UNSIGNED_16 && dt != RS_TYPE_SIGNED_8 &&
dt != RS_TYPE_SIGNED_16) {
return false;
@@ -79,7 +76,7 @@
// Now make sure they are not arrays
uint32_t arraySize = elem->getFieldArraySize(fieldIdx);
- if(arraySize != 1) {
+ if (arraySize != 1) {
return false;
}
@@ -92,19 +89,19 @@
for (uint32_t ct=0; ct < mVertexBufferCount; ct++) {
const Element *elem = mVertexBuffers[ct]->getType()->getElement();
for (uint32_t ct=0; ct < elem->getFieldCount(); ct++) {
- if(isValidGLComponent(elem, ct)) {
+ if (isValidGLComponent(elem, ct)) {
mAttribCount ++;
}
}
}
- if(mAttribs) {
+ if (mAttribs) {
delete [] mAttribs;
delete [] mAttribAllocationIndex;
mAttribs = NULL;
mAttribAllocationIndex = NULL;
}
- if(!mAttribCount) {
+ if (!mAttribCount) {
return;
}
@@ -118,7 +115,7 @@
for (uint32_t fieldI=0; fieldI < elem->getFieldCount(); fieldI++) {
const Component &c = elem->getField(fieldI)->getComponent();
- if(!isValidGLComponent(elem, fieldI)) {
+ if (!isValidGLComponent(elem, fieldI)) {
continue;
}
@@ -138,9 +135,8 @@
}
}
-void Mesh::render(Context *rsc) const
-{
- for(uint32_t ct = 0; ct < mPrimitivesCount; ct ++) {
+void Mesh::render(Context *rsc) const {
+ for (uint32_t ct = 0; ct < mPrimitivesCount; ct ++) {
renderPrimitive(rsc, ct);
}
}
@@ -161,8 +157,7 @@
renderPrimitiveRange(rsc, primIndex, 0, mVertexBuffers[0]->getType()->getDimX());
}
-void Mesh::renderPrimitiveRange(Context *rsc, uint32_t primIndex, uint32_t start, uint32_t len) const
-{
+void Mesh::renderPrimitiveRange(Context *rsc, uint32_t primIndex, uint32_t start, uint32_t len) const {
if (len < 1 || primIndex >= mPrimitivesCount || mAttribCount == 0) {
LOGE("Invalid mesh or parameters");
return;
@@ -202,8 +197,7 @@
}
-void Mesh::uploadAll(Context *rsc)
-{
+void Mesh::uploadAll(Context *rsc) {
for (uint32_t ct = 0; ct < mVertexBufferCount; ct ++) {
if (mVertexBuffers[ct].get()) {
mVertexBuffers[ct]->deferedUploadToBufferObject(rsc);
@@ -217,10 +211,9 @@
}
}
-void Mesh::updateGLPrimitives()
-{
- for(uint32_t i = 0; i < mPrimitivesCount; i ++) {
- switch(mPrimitives[i]->mPrimitive) {
+void Mesh::updateGLPrimitives() {
+ for (uint32_t i = 0; i < mPrimitivesCount; i ++) {
+ switch (mPrimitives[i]->mPrimitive) {
case RS_PRIMITIVE_POINT: mPrimitives[i]->mGLPrimitive = GL_POINTS; break;
case RS_PRIMITIVE_LINE: mPrimitives[i]->mGLPrimitive = GL_LINES; break;
case RS_PRIMITIVE_LINE_STRIP: mPrimitives[i]->mGLPrimitive = GL_LINE_STRIP; break;
@@ -231,8 +224,7 @@
}
}
-void Mesh::serialize(OStream *stream) const
-{
+void Mesh::serialize(OStream *stream) const {
// Need to identify ourselves
stream->addU32((uint32_t)getClassId());
@@ -241,7 +233,7 @@
// Store number of vertex streams
stream->addU32(mVertexBufferCount);
- for(uint32_t vCount = 0; vCount < mVertexBufferCount; vCount ++) {
+ for (uint32_t vCount = 0; vCount < mVertexBufferCount; vCount ++) {
mVertexBuffers[vCount]->serialize(stream);
}
@@ -252,21 +244,19 @@
stream->addU8((uint8_t)prim->mPrimitive);
- if(prim->mIndexBuffer.get()) {
+ if (prim->mIndexBuffer.get()) {
stream->addU32(1);
prim->mIndexBuffer->serialize(stream);
- }
- else {
+ } else {
stream->addU32(0);
}
}
}
-Mesh *Mesh::createFromStream(Context *rsc, IStream *stream)
-{
+Mesh *Mesh::createFromStream(Context *rsc, IStream *stream) {
// First make sure we are reading the correct object
RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
- if(classID != RS_A3D_CLASS_ID_MESH) {
+ if (classID != RS_A3D_CLASS_ID_MESH) {
LOGE("mesh loading skipped due to invalid class id");
return NULL;
}
@@ -278,17 +268,17 @@
mesh->setName(name.string(), name.size());
mesh->mVertexBufferCount = stream->loadU32();
- if(mesh->mVertexBufferCount) {
+ if (mesh->mVertexBufferCount) {
mesh->mVertexBuffers = new ObjectBaseRef<Allocation>[mesh->mVertexBufferCount];
- for(uint32_t vCount = 0; vCount < mesh->mVertexBufferCount; vCount ++) {
+ for (uint32_t vCount = 0; vCount < mesh->mVertexBufferCount; vCount ++) {
Allocation *vertexAlloc = Allocation::createFromStream(rsc, stream);
mesh->mVertexBuffers[vCount].set(vertexAlloc);
}
}
mesh->mPrimitivesCount = stream->loadU32();
- if(mesh->mPrimitivesCount) {
+ if (mesh->mPrimitivesCount) {
mesh->mPrimitives = new Primitive_t *[mesh->mPrimitivesCount];
// load all primitives
@@ -300,7 +290,7 @@
// Check to see if the index buffer was stored
uint32_t isIndexPresent = stream->loadU32();
- if(isIndexPresent) {
+ if (isIndexPresent) {
Allocation *indexAlloc = Allocation::createFromStream(rsc, stream);
prim->mIndexBuffer.set(indexAlloc);
}
@@ -325,7 +315,7 @@
const Element *bufferElem = bufferType->getElement();
for (uint32_t ct=0; ct < bufferElem->getFieldCount(); ct++) {
- if(strcmp(bufferElem->getFieldName(ct), "position") == 0) {
+ if (strcmp(bufferElem->getFieldName(ct), "position") == 0) {
vectorSize = bufferElem->getField(ct)->getComponent().getVectorSize();
stride = bufferElem->getSizeBytes() / sizeof(float);
uint32_t offset = bufferElem->getFieldOffsetBytes(ct);
@@ -334,22 +324,22 @@
break;
}
}
- if(posPtr) {
+ if (posPtr) {
break;
}
}
mBBoxMin[0] = mBBoxMin[1] = mBBoxMin[2] = 1e6;
mBBoxMax[0] = mBBoxMax[1] = mBBoxMax[2] = -1e6;
- if(!posPtr) {
+ if (!posPtr) {
LOGE("Unable to compute bounding box");
mBBoxMin[0] = mBBoxMin[1] = mBBoxMin[2] = 0.0f;
mBBoxMax[0] = mBBoxMax[1] = mBBoxMax[2] = 0.0f;
return;
}
- for(uint32_t i = 0; i < numVerts; i ++) {
- for(uint32_t v = 0; v < vectorSize; v ++) {
+ for (uint32_t i = 0; i < numVerts; i ++) {
+ for (uint32_t v = 0; v < vectorSize; v ++) {
mBBoxMin[v] = rsMin(mBBoxMin[v], posPtr[v]);
mBBoxMax[v] = rsMax(mBBoxMax[v], posPtr[v]);
}
@@ -358,25 +348,22 @@
}
-MeshContext::MeshContext()
-{
+MeshContext::MeshContext() {
}
-MeshContext::~MeshContext()
-{
+MeshContext::~MeshContext() {
}
namespace android {
namespace renderscript {
-RsMesh rsi_MeshCreate(Context *rsc, uint32_t vtxCount, uint32_t idxCount)
-{
+RsMesh rsi_MeshCreate(Context *rsc, uint32_t vtxCount, uint32_t idxCount) {
Mesh *sm = new Mesh(rsc);
sm->incUserRef();
sm->mPrimitivesCount = idxCount;
sm->mPrimitives = new Mesh::Primitive_t *[sm->mPrimitivesCount];
- for(uint32_t ct = 0; ct < idxCount; ct ++) {
+ for (uint32_t ct = 0; ct < idxCount; ct ++) {
sm->mPrimitives[ct] = new Mesh::Primitive_t;
}
@@ -386,16 +373,14 @@
return sm;
}
-void rsi_MeshBindVertex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t slot)
-{
+void rsi_MeshBindVertex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t slot) {
Mesh *sm = static_cast<Mesh *>(mv);
rsAssert(slot < sm->mVertexBufferCount);
sm->mVertexBuffers[slot].set((Allocation *)va);
}
-void rsi_MeshBindIndex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t primType, uint32_t slot)
-{
+void rsi_MeshBindIndex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t primType, uint32_t slot) {
Mesh *sm = static_cast<Mesh *>(mv);
rsAssert(slot < sm->mPrimitivesCount);
@@ -404,48 +389,42 @@
sm->updateGLPrimitives();
}
-void rsi_MeshInitVertexAttribs(Context *rsc, RsMesh mv)
-{
+void rsi_MeshInitVertexAttribs(Context *rsc, RsMesh mv) {
Mesh *sm = static_cast<Mesh *>(mv);
sm->initVertexAttribs();
}
}}
-void rsaMeshGetVertexBufferCount(RsContext con, RsMesh mv, int32_t *numVtx)
-{
+void rsaMeshGetVertexBufferCount(RsContext con, RsMesh mv, int32_t *numVtx) {
Mesh *sm = static_cast<Mesh *>(mv);
*numVtx = sm->mVertexBufferCount;
}
-void rsaMeshGetIndexCount(RsContext con, RsMesh mv, int32_t *numIdx)
-{
+void rsaMeshGetIndexCount(RsContext con, RsMesh mv, int32_t *numIdx) {
Mesh *sm = static_cast<Mesh *>(mv);
*numIdx = sm->mPrimitivesCount;
}
-void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_t vtxDataCount)
-{
+void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_t vtxDataCount) {
Mesh *sm = static_cast<Mesh *>(mv);
rsAssert(vtxDataCount == sm->mVertexBufferCount);
- for(uint32_t ct = 0; ct < vtxDataCount; ct ++) {
+ for (uint32_t ct = 0; ct < vtxDataCount; ct ++) {
vtxData[ct] = sm->mVertexBuffers[ct].get();
sm->mVertexBuffers[ct]->incUserRef();
}
}
-void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount)
-{
+void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount) {
Mesh *sm = static_cast<Mesh *>(mv);
rsAssert(idxDataCount == sm->mPrimitivesCount);
- for(uint32_t ct = 0; ct < idxDataCount; ct ++) {
+ for (uint32_t ct = 0; ct < idxDataCount; ct ++) {
va[ct] = sm->mPrimitives[ct]->mIndexBuffer.get();
primType[ct] = sm->mPrimitives[ct]->mPrimitive;
- if(sm->mPrimitives[ct]->mIndexBuffer.get()) {
+ if (sm->mPrimitives[ct]->mIndexBuffer.get()) {
sm->mPrimitives[ct]->mIndexBuffer->incUserRef();
}
}
-
}