Work on synchronizing a3d created files and java layer.
Adding culling to ProgramRaster Change-Id: I58ccc82d37edc9539289d5eba44ea0e720874af5
This commit is contained in:
@ -40,6 +40,11 @@ public class Allocation extends BaseObj {
|
||||
mType = t;
|
||||
}
|
||||
|
||||
Allocation(int id, RenderScript rs) {
|
||||
super(rs);
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return mType;
|
||||
}
|
||||
|
@ -81,5 +81,10 @@ class BaseObj {
|
||||
mRS.nObjDestroy(mID);
|
||||
}
|
||||
|
||||
// If an object came from an a3d file, java fields need to be
|
||||
// created with objects from the native layer
|
||||
void updateFromNative() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,38 @@ public class Mesh extends BaseObj {
|
||||
return mPrimitives[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
void updateFromNative() {
|
||||
int vtxCount = mRS.nMeshGetVertexBufferCount(mID);
|
||||
int idxCount = mRS.nMeshGetIndexCount(mID);
|
||||
|
||||
int[] vtxIDs = new int[vtxCount];
|
||||
int[] idxIDs = new int[idxCount];
|
||||
int[] primitives = new int[idxCount];
|
||||
|
||||
mRS.nMeshGetVertices(mID, vtxIDs, vtxCount);
|
||||
mRS.nMeshGetIndices(mID, idxIDs, primitives, vtxCount);
|
||||
|
||||
mVertexBuffers = new Allocation[vtxCount];
|
||||
mIndexBuffers = new Allocation[idxCount];
|
||||
mPrimitives = new Primitive[idxCount];
|
||||
|
||||
for(int i = 0; i < vtxCount; i ++) {
|
||||
if(vtxIDs[i] != 0) {
|
||||
mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS);
|
||||
mVertexBuffers[i].updateFromNative();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < idxCount; i ++) {
|
||||
if(idxIDs[i] != 0) {
|
||||
mIndexBuffers[i] = new Allocation(idxIDs[i], mRS);
|
||||
mIndexBuffers[i].updateFromNative();
|
||||
}
|
||||
mPrimitives[i] = Primitive.values()[primitives[i]];
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
|
||||
|
@ -26,12 +26,23 @@ import android.util.Log;
|
||||
*
|
||||
**/
|
||||
public class ProgramRaster extends BaseObj {
|
||||
|
||||
public enum CullMode {
|
||||
BACK (0),
|
||||
FRONT (1),
|
||||
NONE (2);
|
||||
|
||||
int mID;
|
||||
CullMode(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
boolean mPointSmooth;
|
||||
boolean mLineSmooth;
|
||||
boolean mPointSprite;
|
||||
float mLineWidth;
|
||||
Element mIn;
|
||||
Element mOut;
|
||||
CullMode mCullMode;
|
||||
|
||||
ProgramRaster(int id, RenderScript rs) {
|
||||
super(rs);
|
||||
@ -41,6 +52,8 @@ public class ProgramRaster extends BaseObj {
|
||||
mPointSmooth = false;
|
||||
mLineSmooth = false;
|
||||
mPointSprite = false;
|
||||
|
||||
mCullMode = CullMode.BACK;
|
||||
}
|
||||
|
||||
public void setLineWidth(float w) {
|
||||
@ -49,45 +62,48 @@ public class ProgramRaster extends BaseObj {
|
||||
mRS.nProgramRasterSetLineWidth(mID, w);
|
||||
}
|
||||
|
||||
void internalInit() {
|
||||
int inID = 0;
|
||||
int outID = 0;
|
||||
if (mIn != null) {
|
||||
inID = mIn.mID;
|
||||
}
|
||||
if (mOut != null) {
|
||||
outID = mOut.mID;
|
||||
}
|
||||
mID = mRS.nProgramRasterCreate(inID, outID, mPointSmooth, mLineSmooth, mPointSprite);
|
||||
public void setCullMode(CullMode m) {
|
||||
mRS.validate();
|
||||
mCullMode = m;
|
||||
mRS.nProgramRasterSetCullMode(mID, m.mID);
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
ProgramRaster mPR;
|
||||
boolean mPointSprite;
|
||||
boolean mPointSmooth;
|
||||
boolean mLineSmooth;
|
||||
|
||||
// Legacy to not break app in other projects, will be removed in cleanup pass
|
||||
public Builder(RenderScript rs, Element in, Element out) {
|
||||
mRS = rs;
|
||||
mPR = new ProgramRaster(0, rs);
|
||||
mPointSmooth = false;
|
||||
mLineSmooth = false;
|
||||
mPointSprite = false;
|
||||
}
|
||||
|
||||
public Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
mPointSmooth = false;
|
||||
mLineSmooth = false;
|
||||
mPointSprite = false;
|
||||
}
|
||||
|
||||
public void setPointSpriteEnable(boolean enable) {
|
||||
mPR.mPointSprite = enable;
|
||||
mPointSprite = enable;
|
||||
}
|
||||
|
||||
public void setPointSmoothEnable(boolean enable) {
|
||||
mPR.mPointSmooth = enable;
|
||||
mPointSmooth = enable;
|
||||
}
|
||||
|
||||
public void setLineSmoothEnable(boolean enable) {
|
||||
mPR.mLineSmooth = enable;
|
||||
mLineSmooth = enable;
|
||||
}
|
||||
|
||||
|
||||
static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
|
||||
b.mPR.internalInit();
|
||||
ProgramRaster pr = b.mPR;
|
||||
b.mPR = new ProgramRaster(0, b.mRS);
|
||||
int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
|
||||
ProgramRaster pr = new ProgramRaster(id, rs);
|
||||
return pr;
|
||||
}
|
||||
|
||||
@ -103,3 +119,4 @@ public class ProgramRaster extends BaseObj {
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -165,8 +165,9 @@ public class RenderScript {
|
||||
native void nProgramStoreDither(boolean enable);
|
||||
native int nProgramStoreCreate();
|
||||
|
||||
native int nProgramRasterCreate(int in, int out, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
|
||||
native int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
|
||||
native void nProgramRasterSetLineWidth(int pr, float v);
|
||||
native void nProgramRasterSetCullMode(int pr, int mode);
|
||||
|
||||
native void nProgramBindConstants(int pv, int slot, int mID);
|
||||
native void nProgramBindTexture(int vpf, int slot, int a);
|
||||
@ -188,6 +189,10 @@ public class RenderScript {
|
||||
native int nMeshCreate(int vtxCount, int indexCount);
|
||||
native void nMeshBindVertex(int id, int alloc, int slot);
|
||||
native void nMeshBindIndex(int id, int alloc, int prim, int slot);
|
||||
native int nMeshGetVertexBufferCount(int id);
|
||||
native int nMeshGetIndexCount(int id);
|
||||
native void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount);
|
||||
native void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount);
|
||||
|
||||
native void nAnimationBegin(int attribCount, int keyframeCount);
|
||||
native void nAnimationAdd(float time, float[] attribs);
|
||||
@ -357,3 +362,4 @@ public class RenderScript {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -725,12 +725,10 @@ nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jint native_asset)
|
||||
static int
|
||||
nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jint fileA3D)
|
||||
{
|
||||
LOGV("______nFileA3D %u", (uint32_t) fileA3D);
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
|
||||
int32_t numEntries = 0;
|
||||
rsFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
|
||||
LOGV("______nFileA3D NumEntries %u", (uint32_t) numEntries);
|
||||
return numEntries;
|
||||
}
|
||||
|
||||
@ -1203,13 +1201,12 @@ nProgramVertexCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray par
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static jint
|
||||
nProgramRasterCreate(JNIEnv *_env, jobject _this, jint in, jint out,
|
||||
jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite)
|
||||
nProgramRasterCreate(JNIEnv *_env, jobject _this, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nProgramRasterCreate, con(%p), in(%p), out(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
|
||||
con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite);
|
||||
return (jint)rsProgramRasterCreate(con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite);
|
||||
LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
|
||||
con, pointSmooth, lineSmooth, pointSprite);
|
||||
return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1217,7 +1214,15 @@ nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, jint vpr, jfloat v)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v);
|
||||
rsProgramRasterSetLineWidth(con, (RsProgramFragment)vpr, v);
|
||||
rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v);
|
||||
}
|
||||
|
||||
static void
|
||||
nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, jint vpr, jint v)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v);
|
||||
rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v);
|
||||
}
|
||||
|
||||
|
||||
@ -1352,19 +1357,75 @@ nMeshCreate(JNIEnv *_env, jobject _this, jint vtxCount, jint idxCount)
|
||||
}
|
||||
|
||||
static void
|
||||
nMeshBindVertex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint slot)
|
||||
nMeshBindVertex(JNIEnv *_env, jobject _this, jint mesh, jint alloc, jint slot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)s, (RsAllocation)alloc, slot);
|
||||
rsMeshBindVertex(con, (RsMesh)s, (RsAllocation)alloc, slot);
|
||||
LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot);
|
||||
rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot);
|
||||
}
|
||||
|
||||
static void
|
||||
nMeshBindIndex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint primID, jint slot)
|
||||
nMeshBindIndex(JNIEnv *_env, jobject _this, jint mesh, jint alloc, jint primID, jint slot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)s, (RsAllocation)alloc);
|
||||
rsMeshBindIndex(con, (RsMesh)s, (RsAllocation)alloc, primID, slot);
|
||||
LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc);
|
||||
rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot);
|
||||
}
|
||||
|
||||
static jint
|
||||
nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jint mesh)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
|
||||
jint vtxCount = 0;
|
||||
rsMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
|
||||
return vtxCount;
|
||||
}
|
||||
|
||||
static jint
|
||||
nMeshGetIndexCount(JNIEnv *_env, jobject _this, jint mesh)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
|
||||
jint idxCount = 0;
|
||||
rsMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
|
||||
return idxCount;
|
||||
}
|
||||
|
||||
static void
|
||||
nMeshGetVertices(JNIEnv *_env, jobject _this, jint mesh, jintArray _ids, int numVtxIDs)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
|
||||
|
||||
RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
|
||||
rsMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
|
||||
|
||||
for(jint i = 0; i < numVtxIDs; i ++) {
|
||||
_env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
|
||||
}
|
||||
|
||||
free(allocs);
|
||||
}
|
||||
|
||||
static void
|
||||
nMeshGetIndices(JNIEnv *_env, jobject _this, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
|
||||
|
||||
RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
|
||||
uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
|
||||
|
||||
rsMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
|
||||
|
||||
for(jint i = 0; i < numIndices; i ++) {
|
||||
_env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
|
||||
_env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
|
||||
}
|
||||
|
||||
free(allocs);
|
||||
free(prims);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -1473,8 +1534,9 @@ static JNINativeMethod methods[] = {
|
||||
{"nProgramFragmentCreate", "([I)I", (void*)nProgramFragmentCreate },
|
||||
{"nProgramFragmentCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate2 },
|
||||
|
||||
{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate },
|
||||
{"nProgramRasterCreate", "(ZZZ)I", (void*)nProgramRasterCreate },
|
||||
{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth },
|
||||
{"nProgramRasterSetCullMode", "(II)V", (void*)nProgramRasterSetCullMode },
|
||||
|
||||
{"nProgramVertexCreate", "(Z)I", (void*)nProgramVertexCreate },
|
||||
{"nProgramVertexCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramVertexCreate2 },
|
||||
@ -1500,6 +1562,11 @@ static JNINativeMethod methods[] = {
|
||||
{"nMeshBindVertex", "(III)V", (void*)nMeshBindVertex },
|
||||
{"nMeshBindIndex", "(IIII)V", (void*)nMeshBindIndex },
|
||||
|
||||
{"nMeshGetVertexBufferCount", "(I)I", (void*)nMeshGetVertexBufferCount },
|
||||
{"nMeshGetIndexCount", "(I)I", (void*)nMeshGetIndexCount },
|
||||
{"nMeshGetVertices", "(I[II)V", (void*)nMeshGetVertices },
|
||||
{"nMeshGetIndices", "(I[I[II)V", (void*)nMeshGetIndices },
|
||||
|
||||
};
|
||||
|
||||
static int registerFuncs(JNIEnv *_env)
|
||||
@ -1532,3 +1599,4 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
bail:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -244,6 +244,12 @@ enum RsA3DClassID {
|
||||
RS_A3D_CLASS_ID_SCRIPT_C
|
||||
};
|
||||
|
||||
enum RsCullMode {
|
||||
RS_CULL_BACK,
|
||||
RS_CULL_FRONT,
|
||||
RS_CULL_NONE
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
RsA3DClassID classID;
|
||||
const char* objectName;
|
||||
|
Binary file not shown.
@ -347,8 +347,6 @@ ProgramStoreCreate {
|
||||
}
|
||||
|
||||
ProgramRasterCreate {
|
||||
param RsElement in
|
||||
param RsElement out
|
||||
param bool pointSmooth
|
||||
param bool lineSmooth
|
||||
param bool pointSprite
|
||||
@ -360,6 +358,10 @@ ProgramRasterSetLineWidth {
|
||||
param float lw
|
||||
}
|
||||
|
||||
ProgramRasterSetCullMode {
|
||||
param RsProgramRaster pr
|
||||
param RsCullMode mode
|
||||
}
|
||||
|
||||
ProgramBindConstants {
|
||||
param RsProgram vp
|
||||
@ -492,6 +494,29 @@ MeshBindVertex {
|
||||
param uint32_t slot
|
||||
}
|
||||
|
||||
MeshGetVertexBufferCount {
|
||||
param RsMesh mesh
|
||||
param int32_t *numVtx
|
||||
}
|
||||
|
||||
MeshGetIndexCount {
|
||||
param RsMesh mesh
|
||||
param int32_t *numIdx
|
||||
}
|
||||
|
||||
MeshGetVertices {
|
||||
param RsMesh mv
|
||||
param RsAllocation *vtxData
|
||||
param uint32_t vtxDataCount
|
||||
}
|
||||
|
||||
MeshGetIndices {
|
||||
param RsMesh mv
|
||||
param RsAllocation *va
|
||||
param uint32_t *primType
|
||||
param uint32_t idxDataCount
|
||||
}
|
||||
|
||||
AnimationCreate {
|
||||
param const float *inValues
|
||||
param const float *outValues
|
||||
|
@ -683,6 +683,14 @@ void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
|
||||
a->read(data);
|
||||
}
|
||||
|
||||
const void* rsi_AllocationGetType(Context *rsc, RsAllocation va)
|
||||
{
|
||||
Allocation *a = static_cast<Allocation *>(va);
|
||||
a->getType()->incUserRef();
|
||||
|
||||
return a->getType();
|
||||
}
|
||||
|
||||
#endif //ANDROID_RS_BUILD_FOR_HOST
|
||||
|
||||
}
|
||||
|
@ -511,6 +511,9 @@ void FontState::issueDrawCommand() {
|
||||
ObjectBaseRef<const ProgramVertex> tmpV(mRSC->getVertex());
|
||||
mRSC->setVertex(mRSC->getDefaultProgramVertex());
|
||||
|
||||
ObjectBaseRef<const ProgramRaster> tmpR(mRSC->getRaster());
|
||||
mRSC->setRaster(mRSC->getDefaultProgramRaster());
|
||||
|
||||
ObjectBaseRef<const ProgramFragment> tmpF(mRSC->getFragment());
|
||||
mRSC->setFragment(mFontShaderF.get());
|
||||
|
||||
@ -519,6 +522,7 @@ void FontState::issueDrawCommand() {
|
||||
|
||||
if (!mRSC->setupCheck()) {
|
||||
mRSC->setVertex((ProgramVertex *)tmpV.get());
|
||||
mRSC->setRaster((ProgramRaster *)tmpR.get());
|
||||
mRSC->setFragment((ProgramFragment *)tmpF.get());
|
||||
mRSC->setFragmentStore((ProgramStore *)tmpPS.get());
|
||||
return;
|
||||
@ -538,6 +542,7 @@ void FontState::issueDrawCommand() {
|
||||
|
||||
// Reset the state
|
||||
mRSC->setVertex((ProgramVertex *)tmpV.get());
|
||||
mRSC->setRaster((ProgramRaster *)tmpR.get());
|
||||
mRSC->setFragment((ProgramFragment *)tmpF.get());
|
||||
mRSC->setFragmentStore((ProgramStore *)tmpPS.get());
|
||||
}
|
||||
|
@ -271,4 +271,45 @@ void rsi_MeshBindIndex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t primTy
|
||||
sm->updateGLPrimitives();
|
||||
}
|
||||
|
||||
void rsi_MeshGetVertexBufferCount(Context *rsc, RsMesh mv, int32_t *numVtx)
|
||||
{
|
||||
Mesh *sm = static_cast<Mesh *>(mv);
|
||||
*numVtx = sm->mVertexBufferCount;
|
||||
}
|
||||
|
||||
void rsi_MeshGetIndexCount(Context *rsc, RsMesh mv, int32_t *numIdx)
|
||||
{
|
||||
Mesh *sm = static_cast<Mesh *>(mv);
|
||||
*numIdx = sm->mPrimitivesCount;
|
||||
}
|
||||
|
||||
void rsi_MeshGetVertices(Context *rsc, 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 ++) {
|
||||
vtxData[ct] = sm->mVertexBuffers[ct].get();
|
||||
sm->mVertexBuffers[ct]->incUserRef();
|
||||
}
|
||||
}
|
||||
|
||||
void rsi_MeshGetIndices(Context *rsc, 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 ++) {
|
||||
va[ct] = sm->mPrimitives[ct]->mIndexBuffer.get();
|
||||
primType[ct] = sm->mPrimitives[ct]->mPrimitive;
|
||||
if(sm->mPrimitives[ct]->mIndexBuffer.get()) {
|
||||
sm->mPrimitives[ct]->mIndexBuffer->incUserRef();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}}
|
||||
|
@ -42,6 +42,7 @@ ProgramRaster::ProgramRaster(Context *rsc,
|
||||
mLineSmooth = lineSmooth;
|
||||
mPointSprite = pointSprite;
|
||||
mLineWidth = 1.0f;
|
||||
mCull = RS_CULL_BACK;
|
||||
}
|
||||
|
||||
ProgramRaster::~ProgramRaster()
|
||||
@ -51,14 +52,22 @@ ProgramRaster::~ProgramRaster()
|
||||
void ProgramRaster::setLineWidth(float s)
|
||||
{
|
||||
mLineWidth = s;
|
||||
mDirty = true;
|
||||
}
|
||||
|
||||
void ProgramRaster::setCullMode(RsCullMode mode)
|
||||
{
|
||||
mCull = mode;
|
||||
mDirty = true;
|
||||
}
|
||||
|
||||
void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
|
||||
{
|
||||
if (state->mLast.get() == this) {
|
||||
if (state->mLast.get() == this && !mDirty) {
|
||||
return;
|
||||
}
|
||||
state->mLast.set(this);
|
||||
mDirty = false;
|
||||
|
||||
if (mPointSmooth) {
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
@ -82,14 +91,43 @@ void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
|
||||
}
|
||||
#endif //ANDROID_RS_BUILD_FOR_HOST
|
||||
}
|
||||
|
||||
switch(mCull) {
|
||||
case RS_CULL_BACK:
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
break;
|
||||
case RS_CULL_FRONT:
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
break;
|
||||
case RS_CULL_NONE:
|
||||
glDisable(GL_CULL_FACE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
|
||||
{
|
||||
if (state->mLast.get() == this) {
|
||||
if (state->mLast.get() == this && !mDirty) {
|
||||
return;
|
||||
}
|
||||
state->mLast.set(this);
|
||||
mDirty = false;
|
||||
|
||||
switch(mCull) {
|
||||
case RS_CULL_BACK:
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
break;
|
||||
case RS_CULL_FRONT:
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
break;
|
||||
case RS_CULL_NONE:
|
||||
glDisable(GL_CULL_FACE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramRaster::serialize(OStream *stream) const
|
||||
@ -126,7 +164,7 @@ void ProgramRasterState::deinit(Context *rsc)
|
||||
namespace android {
|
||||
namespace renderscript {
|
||||
|
||||
RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
|
||||
RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
|
||||
bool pointSmooth,
|
||||
bool lineSmooth,
|
||||
bool pointSprite)
|
||||
@ -145,6 +183,12 @@ void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
|
||||
pr->setLineWidth(s);
|
||||
}
|
||||
|
||||
void rsi_ProgramRasterSetCullMode(Context * rsc, RsProgramRaster vpr, RsCullMode mode)
|
||||
{
|
||||
ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
|
||||
pr->setCullMode(mode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,14 @@ public:
|
||||
static ProgramRaster *createFromStream(Context *rsc, IStream *stream);
|
||||
|
||||
void setLineWidth(float w);
|
||||
void setCullMode(RsCullMode mode);
|
||||
|
||||
protected:
|
||||
bool mPointSmooth;
|
||||
bool mLineSmooth;
|
||||
bool mPointSprite;
|
||||
float mLineWidth;
|
||||
RsCullMode mCull;
|
||||
};
|
||||
|
||||
class ProgramRasterState
|
||||
|
Reference in New Issue
Block a user