summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-09-23 16:38:37 -0700
committerJason Sams <rjsams@android.com>2009-09-23 18:07:45 -0700
commit6b9dec00afec359f091ed353f371f08ff150278a (patch)
tree58ad3c03d45525d6f669f6dc86f3d01d39a24513
parent880aaa7fe0706dbadbb8f2f6b39b4f3021f74c01 (diff)
downloadframeworks_base-6b9dec00afec359f091ed353f371f08ff150278a.zip
frameworks_base-6b9dec00afec359f091ed353f371f08ff150278a.tar.gz
frameworks_base-6b9dec00afec359f091ed353f371f08ff150278a.tar.bz2
Remove depricated triangleMesh.
-rw-r--r--graphics/java/android/renderscript/RenderScript.java86
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp79
-rw-r--r--libs/rs/Android.mk3
-rw-r--r--libs/rs/RenderScript.h1
-rw-r--r--libs/rs/RenderScriptEnv.h1
-rw-r--r--libs/rs/rs.spec30
-rw-r--r--libs/rs/rsContext.h3
-rw-r--r--libs/rs/rsScriptC_Lib.cpp43
-rw-r--r--libs/rs/rsSimpleMesh.cpp14
-rw-r--r--libs/rs/rsSimpleMesh.h1
-rw-r--r--libs/rs/rsTriangleMesh.cpp287
-rw-r--r--libs/rs/rsTriangleMesh.h83
12 files changed, 41 insertions, 590 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 1ce7083..b7cd21b 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -65,8 +65,6 @@ public class RenderScript {
native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
native void nContextDestroy(int con);
- //void rsContextBindSampler (uint32_t slot, RsSampler sampler);
- //void rsContextBindRootScript (RsScript sampler);
native void nContextBindRootScript(int script);
native void nContextBindSampler(int sampler, int slot);
native void nContextBindProgramFragmentStore(int pfs);
@@ -92,7 +90,6 @@ public class RenderScript {
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
native int nAllocationCreateTyped(int type);
- //native int nAllocationCreateSized(int elem, int count);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
@@ -112,15 +109,6 @@ public class RenderScript {
native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
native void nAllocationSubReadFromObject(int id, Type t, int offset, Object o);
- native void nTriangleMeshBegin(int vertex, int index);
- native void nTriangleMeshAddVertex_XY (float x, float y);
- native void nTriangleMeshAddVertex_XYZ (float x, float y, float z);
- native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t);
- native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t);
- native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz);
- native void nTriangleMeshAddTriangle(int i1, int i2, int i3);
- native int nTriangleMeshCreate();
-
native void nAdapter1DBindAllocation(int ad, int alloc);
native void nAdapter1DSetConstraint(int ad, int dim, int value);
native void nAdapter1DData(int ad, int[] d);
@@ -230,49 +218,6 @@ public class RenderScript {
}
//////////////////////////////////////////////////////////////////////////////////
- // Triangle Mesh
-
- public class TriangleMesh extends BaseObj {
- TriangleMesh(int id) {
- super(RenderScript.this);
- mID = id;
- }
- }
-
- public void triangleMeshBegin(Element vertex, Element index) {
- nTriangleMeshBegin(vertex.mID, index.mID);
- }
-
- public void triangleMeshAddVertex_XY(float x, float y) {
- nTriangleMeshAddVertex_XY(x, y);
- }
-
- public void triangleMeshAddVertex_XYZ(float x, float y, float z) {
- nTriangleMeshAddVertex_XYZ(x, y, z);
- }
-
- public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) {
- nTriangleMeshAddVertex_XY_ST(x, y, s, t);
- }
-
- public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) {
- nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t);
- }
-
- public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) {
- nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz);
- }
-
- public void triangleMeshAddTriangle(int i1, int i2, int i3) {
- nTriangleMeshAddTriangle(i1, i2, i3);
- }
-
- public TriangleMesh triangleMeshCreate() {
- int id = nTriangleMeshCreate();
- return new TriangleMesh(id);
- }
-
- //////////////////////////////////////////////////////////////////////////////////
// File
public class File extends BaseObj {
@@ -301,32 +246,31 @@ public class RenderScript {
///////////////////////////////////////////////////////////////////////////////////
// Root state
- public void contextBindRootScript(Script s) {
- int id = 0;
- if(s != null) {
- id = s.mID;
+ private int safeID(BaseObj o) {
+ if(o != null) {
+ return o.mID;
}
- nContextBindRootScript(id);
+ return 0;
}
- //public void contextBindSampler(Sampler s, int slot) {
- //nContextBindSampler(s.mID);
- //}
+ public void contextBindRootScript(Script s) {
+ nContextBindRootScript(safeID(s));
+ }
- public void contextBindProgramFragmentStore(ProgramStore pfs) {
- nContextBindProgramFragmentStore(pfs.mID);
+ public void contextBindProgramFragmentStore(ProgramStore p) {
+ nContextBindProgramFragmentStore(safeID(p));
}
- public void contextBindProgramFragment(ProgramFragment pf) {
- nContextBindProgramFragment(pf.mID);
+ public void contextBindProgramFragment(ProgramFragment p) {
+ nContextBindProgramFragment(safeID(p));
}
- public void contextBindProgramRaster(ProgramRaster pf) {
- nContextBindProgramRaster(pf.mID);
+ public void contextBindProgramRaster(ProgramRaster p) {
+ nContextBindProgramRaster(safeID(p));
}
- public void contextBindProgramVertex(ProgramVertex pf) {
- nContextBindProgramVertex(pf.mID);
+ public void contextBindProgramVertex(ProgramVertex p) {
+ nContextBindProgramVertex(safeID(p));
}
}
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 4a8f8a3..f86d86a 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -603,76 +603,6 @@ nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _t
free(bufAlloc);
}
-// -----------------------------------
-
-static void
-nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i);
- rsTriangleMeshBegin(con, (RsElement)v, (RsElement)i);
-}
-
-static void
-nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y)
-{
- float v[] = {x, y};
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y);
- rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z)
-{
- float v[] = {x, y, z};
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z);
- rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t)
-{
- float v[] = {s, t, x, y};
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t);
- rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t)
-{
- float v[] = {s, t, x, y, z};
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
- rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
-{
- float v[] = {nx, ny, nz, s, t, x, y, z};
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
- rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3);
- rsTriangleMeshAddTriangle(con, i1, i2, i3);
-}
-
-static jint
-nTriangleMeshCreate(JNIEnv *_env, jobject _this)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nTriangleMeshCreate, con(%p)", con);
- return (jint) rsTriangleMeshCreate(con);
-}
// -----------------------------------
@@ -1385,15 +1315,6 @@ static JNINativeMethod methods[] = {
{"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject },
{"nAllocationSubReadFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject },
-{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin },
-{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY },
-{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ },
-{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST },
-{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST },
-{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
-{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle },
-{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate },
-
{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation },
{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint },
{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i },
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 2c17599..262ac8d 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -98,8 +98,7 @@ LOCAL_SRC_FILES:= \
rsScriptC_Lib.cpp \
rsSimpleMesh.cpp \
rsThreadIO.cpp \
- rsType.cpp \
- rsTriangleMesh.cpp
+ rsType.cpp
LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui libacc
LOCAL_LDLIBS := -lpthread -ldl
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 9f18b78..fe68511 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -37,7 +37,6 @@ typedef void * RsFile;
typedef void * RsSampler;
typedef void * RsScript;
typedef void * RsScriptBasicTemp;
-typedef void * RsTriangleMesh;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsLight;
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index 5eb8912..ff0a7b1 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -10,7 +10,6 @@ typedef void * RsElement;
typedef void * RsSampler;
typedef void * RsScript;
typedef void * RsScriptBasicTemp;
-typedef void * RsTriangleMesh;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsProgramFragment;
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index d7ae532..a6eb467 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -229,36 +229,6 @@ SamplerCreate {
}
-TriangleMeshBegin {
- param RsElement vertex
- param RsElement index
- }
-
-TriangleMeshAddVertex {
- param const void *vtx
- }
-
-TriangleMeshAddTriangle {
- param uint32_t idx1
- param uint32_t idx2
- param uint32_t idx3
- }
-
-TriangleMeshCreate {
- ret RsTriangleMesh
- }
-
-
-TriangleMeshRender {
- param RsTriangleMesh vtm
- }
-
-TriangleMeshRenderRange {
- param RsTriangleMesh vtm
- param uint32_t start
- param uint32_t count
- }
-
ScriptBindAllocation {
param RsScript vtm
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 1fb697a..8cabf87 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -25,7 +25,6 @@
#include "rsType.h"
#include "rsMatrix.h"
#include "rsAllocation.h"
-#include "rsTriangleMesh.h"
#include "rsSimpleMesh.h"
#include "rsMesh.h"
#include "rsDevice.h"
@@ -70,8 +69,6 @@ public:
ProgramVertexState mStateVertex;
LightState mStateLight;
- TriangleMeshContext mStateTriangleMesh;
-
ScriptCState mScriptC;
void swapBuffers();
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 6dc3e8b..f5f182f 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -92,24 +92,17 @@ static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
return i + offset;
}
-static float* SC_loadTriangleMeshVerticesF(RsTriangleMesh mesh)
+static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
{
- TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
- void *vp = tm->mVertexData;
- float *f = static_cast<float *>(vp);
- return f;
+ SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
+ void *vp = tm->mVertexBuffers[idx]->getPtr();;
+ return static_cast<float *>(vp);
}
-static void SC_updateTriangleMesh(RsTriangleMesh mesh)
+static void SC_updateSimpleMesh(RsSimpleMesh mesh)
{
- TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
- glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
- glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
+ sm->uploadAll();
}
static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
@@ -661,18 +654,6 @@ static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
// Drawing
//////////////////////////////////////////////////////////////////////////////
-static void SC_drawTriangleMesh(RsTriangleMesh mesh)
-{
- GET_TLS();
- rsi_TriangleMeshRender(rsc, mesh);
-}
-
-static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
-{
- GET_TLS();
- rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
-}
-
static void SC_drawLine(float x1, float y1, float z1,
float x2, float y2, float z2)
{
@@ -988,9 +969,9 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
"void", "(int, int, float *)" },
{ "storeMatrix", (void *)&SC_storeMatrix,
"void", "(int, int, float *)" },
- { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
- "float*", "(int)" },
- { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
+ { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
+ "float*", "(int, int)" },
+ { "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
"void", "(int)" },
// math
@@ -1172,10 +1153,6 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
"void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
{ "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
"void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
- { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
- "void", "(int mesh)" },
- { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
- "void", "(int mesh, int start, int count)" },
{ "drawLine", (void *)&SC_drawLine,
"void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
{ "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp
index 7c73eb9..447bcee 100644
--- a/libs/rs/rsSimpleMesh.cpp
+++ b/libs/rs/rsSimpleMesh.cpp
@@ -73,6 +73,20 @@ void SimpleMesh::renderRange(uint32_t start, uint32_t len) const
}
}
+void SimpleMesh::uploadAll()
+{
+ for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
+ if (mVertexBuffers[ct].get()) {
+ mVertexBuffers[ct]->uploadToBufferObject();
+ }
+ }
+ if (mIndexBuffer.get()) {
+ mIndexBuffer->uploadToBufferObject();
+ }
+ if (mPrimitiveBuffer.get()) {
+ mPrimitiveBuffer->uploadToBufferObject();
+ }
+}
SimpleMeshContext::SimpleMeshContext()
diff --git a/libs/rs/rsSimpleMesh.h b/libs/rs/rsSimpleMesh.h
index 03b6c2c..dc5e19c 100644
--- a/libs/rs/rsSimpleMesh.h
+++ b/libs/rs/rsSimpleMesh.h
@@ -47,6 +47,7 @@ public:
void render() const;
void renderRange(uint32_t start, uint32_t len) const;
+ void uploadAll();
protected:
diff --git a/libs/rs/rsTriangleMesh.cpp b/libs/rs/rsTriangleMesh.cpp
deleted file mode 100644
index 64bb71b..0000000
--- a/libs/rs/rsTriangleMesh.cpp
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rsContext.h"
-
-using namespace android;
-using namespace android::renderscript;
-
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-TriangleMesh::TriangleMesh()
-{
- mVertexElement = NULL;
- mIndexElement = NULL;
- mVertexData = NULL;
- mIndexData = NULL;
- mTriangleCount = 0;
- mVertexDataSize = 0;
- mIndexDataSize = 0;
-
- mBufferObjects[0] = 0;
- mBufferObjects[1] = 0;
-
- mOffsetCoord = 0;
- mOffsetTex = 0;
- mOffsetNorm = 0;
-
- mSizeCoord = 0;
- mSizeTex = 0;
- mSizeNorm = 0;
-
-}
-
-TriangleMesh::~TriangleMesh()
-{
- free(mVertexData);
- free(mIndexData);
-}
-
-
-
-TriangleMeshContext::TriangleMeshContext()
-{
- clear();
-}
-
-TriangleMeshContext::~TriangleMeshContext()
-{
-}
-
-void TriangleMeshContext::clear()
-{
- mVertexElement = NULL;
- mVertexSizeBits = 0;
- mIndexElement = NULL;
- mIndexSizeBits = 0;
- mTriangleCount = 0;
- mVertexData.clear();
- mIndexData.clear();
-}
-
-void TriangleMesh::analyzeElement()
-{
- for (uint32_t ct=0; ct < mVertexElement->getComponentCount(); ct++) {
- const Component *c = mVertexElement->getComponent(ct);
-
- if (c->getKind() == Component::X) {
- rsAssert(mSizeCoord == 0);
- mSizeCoord = 1;
- mOffsetCoord = ct;
- }
- if (c->getKind() == Component::Y) {
- rsAssert(mSizeCoord == 1);
- mSizeCoord = 2;
- }
- if (c->getKind() == Component::Z) {
- rsAssert(mSizeCoord == 2);
- mSizeCoord = 3;
- }
- if (c->getKind() == Component::W) {
- rsAssert(mSizeCoord == 4);
- mSizeCoord = 4;
- }
-
- if (c->getKind() == Component::NX) {
- rsAssert(mSizeNorm == 0);
- mSizeNorm = 1;
- mOffsetNorm = ct;
- }
- if (c->getKind() == Component::NY) {
- rsAssert(mSizeNorm == 1);
- mSizeNorm = 2;
- }
- if (c->getKind() == Component::NZ) {
- rsAssert(mSizeNorm == 2);
- mSizeNorm = 3;
- }
-
- if (c->getKind() == Component::S) {
- rsAssert(mSizeTex == 0);
- mSizeTex = 1;
- mOffsetTex = ct;
- }
- if (c->getKind() == Component::T) {
- rsAssert(mSizeTex == 1);
- mSizeTex = 2;
- }
- }
- LOGV("TriangleMesh %i,%i %i,%i %i,%i", mSizeCoord, mOffsetCoord, mSizeNorm, mOffsetNorm, mSizeTex, mOffsetTex);
-
-}
-
-
-namespace android {
-namespace renderscript {
-
-void rsi_TriangleMeshBegin(Context *rsc, RsElement vertex, RsElement index)
-{
- TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
- tmc->clear();
- tmc->mVertexElement = static_cast<Element *>(vertex);
- tmc->mVertexSizeBits = tmc->mVertexElement->getSizeBits();
- tmc->mIndexElement = static_cast<Element *>(index);
- tmc->mIndexSizeBits = tmc->mIndexElement->getSizeBits();
-
- assert(!(tmc->mVertexSizeBits & 0x7));
- assert(!(tmc->mIndexSizeBits & 0x7));
-}
-
-void rsi_TriangleMeshAddVertex(Context *rsc, const void *data)
-{
- TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
- // todo: Make this efficient.
- for (uint32_t ct = 0; (ct * 8) < tmc->mVertexSizeBits; ct++) {
- tmc->mVertexData.add(static_cast<const uint8_t *>(data) [ct]);
- }
-}
-
-void rsi_TriangleMeshAddTriangle(Context *rsc, uint32_t idx1, uint32_t idx2, uint32_t idx3)
-{
- TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
- // todo: Make this efficient.
- switch(tmc->mIndexSizeBits) {
- case 16:
- tmc->mIndexData.add(idx1);
- tmc->mIndexData.add(idx2);
- tmc->mIndexData.add(idx3);
- break;
- default:
- assert(0);
- }
-
- tmc->mTriangleCount++;
-}
-
-RsTriangleMesh rsi_TriangleMeshCreate(Context *rsc)
-{
- TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
- TriangleMesh * tm = new TriangleMesh();
- if (!tm) {
- LOGE("rsTriangleMeshCreate: Error OUT OF MEMORY");
- // error
- return 0;
- }
-
- tm->mTriangleCount = tmc->mTriangleCount;
- tm->mIndexDataSize = tmc->mIndexData.size() * tmc->mIndexSizeBits >> 3;
- tm->mVertexDataSize = tmc->mVertexData.size();
- tm->mIndexElement = tmc->mIndexElement;
- tm->mVertexElement = tmc->mVertexElement;
-
- tm->mIndexData = malloc(tm->mIndexDataSize);
- tm->mVertexData = malloc(tm->mVertexDataSize);
- if (!tm->mIndexData || !tm->mVertexData) {
- LOGE("rsTriangleMeshCreate: Error OUT OF MEMORY");
- delete tm;
- return 0;
- }
-
- memcpy(tm->mVertexData, tmc->mVertexData.array(), tm->mVertexDataSize);
- memcpy(tm->mIndexData, tmc->mIndexData.array(), tm->mIndexDataSize);
- tm->analyzeElement();
-
- tm->incUserRef();
- return tm;
-}
-
-void rsi_TriangleMeshDestroy(Context *rsc, RsTriangleMesh vtm)
-{
- TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
- TriangleMesh * tm = static_cast<TriangleMesh *>(vtm);
-
- free(tm->mIndexData);
- free(tm->mVertexData);
- delete tm;
-}
-
-
-
-void rsi_TriangleMeshRenderRange(Context *rsc, RsTriangleMesh vtm, uint32_t first, uint32_t count)
-{
- TriangleMesh * tm = static_cast<TriangleMesh *>(vtm);
-
- rsc->setupCheck();
-
- if (!tm->mBufferObjects[0]) {
- glGenBuffers(2, &tm->mBufferObjects[0]);
-
- glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
- glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
-
- if (first >= tm->mTriangleCount) {
- return;
- }
- if (count >= (tm->mTriangleCount - first)) {
- count = tm->mTriangleCount - first;
- }
- if (!count) {
- return;
- }
-
- const float *f = (const float *)tm->mVertexData;
-
- glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(tm->mSizeCoord,
- GL_FLOAT,
- tm->mVertexElement->getSizeBytes(),
- (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetCoord));
-
- if (tm->mSizeTex) {
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(tm->mSizeTex,
- GL_FLOAT,
- tm->mVertexElement->getSizeBytes(),
- (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetTex));
- } else {
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
-
- if (tm->mSizeNorm) {
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer(GL_FLOAT,
- tm->mVertexElement->getSizeBytes(),
- (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetNorm));
- } else {
- glDisableClientState(GL_NORMAL_ARRAY);
- }
-
- glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_SHORT, (GLvoid *)(first * 3 * 2));
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-}
-
-void rsi_TriangleMeshRender(Context *rsc, RsTriangleMesh vtm)
-{
- rsi_TriangleMeshRenderRange(rsc, vtm, 0, 0xffffff);
-}
-
-}}
diff --git a/libs/rs/rsTriangleMesh.h b/libs/rs/rsTriangleMesh.h
deleted file mode 100644
index e56c7c2..0000000
--- a/libs/rs/rsTriangleMesh.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_RS_TRIANGLE_MESH_H
-#define ANDROID_RS_TRIANGLE_MESH_H
-
-
-#include "RenderScript.h"
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-
-// An element is a group of Components that occupies one cell in a structure.
-class TriangleMesh : public ObjectBase
-{
-public:
- TriangleMesh();
- ~TriangleMesh();
-
- const Element * mVertexElement;
- const Element * mIndexElement;
-
- void * mVertexData;
- void * mIndexData;
-
- size_t mVertexDataSize;
- size_t mIndexDataSize;
- uint32_t mTriangleCount;
-
- size_t mOffsetCoord;
- size_t mOffsetTex;
- size_t mOffsetNorm;
-
- size_t mSizeCoord;
- size_t mSizeTex;
- size_t mSizeNorm;
-
- // GL buffer info
- uint32_t mBufferObjects[2];
-
- void analyzeElement();
-protected:
-};
-
-class TriangleMeshContext
-{
-public:
- TriangleMeshContext();
- ~TriangleMeshContext();
-
- const Element * mVertexElement;
- const Element * mIndexElement;
- size_t mVertexSizeBits;
- size_t mIndexSizeBits;
-
- Vector<uint8_t> mVertexData;
- Vector<uint16_t> mIndexData;
-
- uint32_t mTriangleCount;
-
- void clear();
-};
-
-
-}
-}
-#endif //ANDROID_RS_TRIANGLE_MESH_H
-