am e31c0b56: Merge change 26708 into eclair

Merge commit 'e31c0b5693f8887410d54d590ebf1ccb05ba0cc8' into eclair-plus-aosp

* commit 'e31c0b5693f8887410d54d590ebf1ccb05ba0cc8':
  Remove depricated triangleMesh.
This commit is contained in:
Jason Sams
2009-09-24 12:43:30 -07:00
committed by Android Git Automerger
12 changed files with 42 additions and 591 deletions

View File

@@ -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);
@@ -229,49 +217,6 @@ public class RenderScript {
mDev = 0;
}
//////////////////////////////////////////////////////////////////////////////////
// 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
@@ -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 contextBindProgramFragmentStore(ProgramStore pfs) {
nContextBindProgramFragmentStore(pfs.mID);
public void contextBindRootScript(Script s) {
nContextBindRootScript(safeID(s));
}
public void contextBindProgramFragment(ProgramFragment pf) {
nContextBindProgramFragment(pf.mID);
public void contextBindProgramFragmentStore(ProgramStore p) {
nContextBindProgramFragmentStore(safeID(p));
}
public void contextBindProgramRaster(ProgramRaster pf) {
nContextBindProgramRaster(pf.mID);
public void contextBindProgramFragment(ProgramFragment p) {
nContextBindProgramFragment(safeID(p));
}
public void contextBindProgramVertex(ProgramVertex pf) {
nContextBindProgramVertex(pf.mID);
public void contextBindProgramRaster(ProgramRaster p) {
nContextBindProgramRaster(safeID(p));
}
public void contextBindProgramVertex(ProgramVertex p) {
nContextBindProgramVertex(safeID(p));
}
}

View File

@@ -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 },

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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();

View File

@@ -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,

View File

@@ -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()

View File

@@ -47,6 +47,7 @@ public:
void render() const;
void renderRange(uint32_t start, uint32_t len) const;
void uploadAll();
protected:

View File

@@ -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);
}
}}

View File

@@ -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