diff options
author | Jason Sams <rjsams@android.com> | 2010-06-01 15:47:01 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-06-01 15:47:01 -0700 |
commit | 8cb39de03aef6097a90033600d11a60ae000a6e4 (patch) | |
tree | cc9eb5fa87de5e14713684e7e177368d10550384 | |
parent | c9d0a87d504b3f0322b43f971f9cb4838ee521fb (diff) | |
download | frameworks_base-8cb39de03aef6097a90033600d11a60ae000a6e4.zip frameworks_base-8cb39de03aef6097a90033600d11a60ae000a6e4.tar.gz frameworks_base-8cb39de03aef6097a90033600d11a60ae000a6e4.tar.bz2 |
Remove RS_KIND from vertex arrays types.
Legacy vertex programs now bind by name just like the user programs.
This removes the need for two different ways of declairing the same
information.
Change-Id: I0178c0962842a1bbffb6726984ae1b8f5bb7529c
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 214 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 46 | ||||
-rw-r--r-- | graphics/java/android/renderscript/SimpleMesh.java | 18 | ||||
-rw-r--r-- | libs/rs/java/Fountain/res/raw/fountain.rs | 17 | ||||
-rw-r--r-- | libs/rs/java/Fountain/res/raw/fountain_bc.bc | bin | 2196 -> 2384 bytes | |||
-rw-r--r-- | libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java | 6 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 20 | ||||
-rw-r--r-- | libs/rs/rsScriptC_LibGL.cpp | 27 | ||||
-rw-r--r-- | libs/rs/rsShaderCache.cpp | 15 | ||||
-rw-r--r-- | libs/rs/rsSimpleMesh.cpp | 19 | ||||
-rw-r--r-- | libs/rs/rsType.cpp | 127 | ||||
-rw-r--r-- | libs/rs/rsType.h | 11 | ||||
-rw-r--r-- | libs/rs/rsVertexArray.cpp | 99 | ||||
-rw-r--r-- | libs/rs/rsVertexArray.h | 6 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_core.rsh | 8 |
15 files changed, 182 insertions, 451 deletions
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index f801794..974a36e 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -91,109 +91,109 @@ public class Element extends BaseObj { } } - public static Element USER_U8(RenderScript rs) { - if(rs.mElement_USER_U8 == null) { - rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8); + public static Element U8(RenderScript rs) { + if(rs.mElement_U8 == null) { + rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8); } - return rs.mElement_USER_U8; + return rs.mElement_U8; } - public static Element USER_I8(RenderScript rs) { - if(rs.mElement_USER_I8 == null) { - rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8); + public static Element I8(RenderScript rs) { + if(rs.mElement_I8 == null) { + rs.mElement_I8 = createUser(rs, DataType.SIGNED_8); } - return rs.mElement_USER_I8; + return rs.mElement_I8; } - public static Element USER_U32(RenderScript rs) { - if(rs.mElement_USER_U32 == null) { - rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32); + public static Element U32(RenderScript rs) { + if(rs.mElement_U32 == null) { + rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32); } - return rs.mElement_USER_U32; + return rs.mElement_U32; } - public static Element USER_I32(RenderScript rs) { - if(rs.mElement_USER_I32 == null) { - rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32); + public static Element I32(RenderScript rs) { + if(rs.mElement_I32 == null) { + rs.mElement_I32 = createUser(rs, DataType.SIGNED_32); } - return rs.mElement_USER_I32; + return rs.mElement_I32; } - public static Element USER_F32(RenderScript rs) { - if(rs.mElement_USER_F32 == null) { - rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32); + public static Element F32(RenderScript rs) { + if(rs.mElement_F32 == null) { + rs.mElement_F32 = createUser(rs, DataType.FLOAT_32); } - return rs.mElement_USER_F32; + return rs.mElement_F32; } - public static Element USER_ELEMENT(RenderScript rs) { - if(rs.mElement_USER_ELEMENT == null) { - rs.mElement_USER_ELEMENT = createUser(rs, DataType.RS_ELEMENT); + public static Element ELEMENT(RenderScript rs) { + if(rs.mElement_ELEMENT == null) { + rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT); } - return rs.mElement_USER_ELEMENT; + return rs.mElement_ELEMENT; } - public static Element USER_TYPE(RenderScript rs) { - if(rs.mElement_USER_TYPE == null) { - rs.mElement_USER_TYPE = createUser(rs, DataType.RS_TYPE); + public static Element TYPE(RenderScript rs) { + if(rs.mElement_TYPE == null) { + rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE); } - return rs.mElement_USER_TYPE; + return rs.mElement_TYPE; } - public static Element USER_ALLOCATION(RenderScript rs) { - if(rs.mElement_USER_ALLOCATION == null) { - rs.mElement_USER_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION); + public static Element ALLOCATION(RenderScript rs) { + if(rs.mElement_ALLOCATION == null) { + rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION); } - return rs.mElement_USER_ALLOCATION; + return rs.mElement_ALLOCATION; } - public static Element USER_SAMPLER(RenderScript rs) { - if(rs.mElement_USER_SAMPLER == null) { - rs.mElement_USER_SAMPLER = createUser(rs, DataType.RS_SAMPLER); + public static Element SAMPLER(RenderScript rs) { + if(rs.mElement_SAMPLER == null) { + rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER); } - return rs.mElement_USER_SAMPLER; + return rs.mElement_SAMPLER; } - public static Element USER_SCRIPT(RenderScript rs) { - if(rs.mElement_USER_SCRIPT == null) { - rs.mElement_USER_SCRIPT = createUser(rs, DataType.RS_SCRIPT); + public static Element SCRIPT(RenderScript rs) { + if(rs.mElement_SCRIPT == null) { + rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT); } - return rs.mElement_USER_SCRIPT; + return rs.mElement_SCRIPT; } - public static Element USER_MESH(RenderScript rs) { - if(rs.mElement_USER_MESH == null) { - rs.mElement_USER_MESH = createUser(rs, DataType.RS_MESH); + public static Element MESH(RenderScript rs) { + if(rs.mElement_MESH == null) { + rs.mElement_MESH = createUser(rs, DataType.RS_MESH); } - return rs.mElement_USER_MESH; + return rs.mElement_MESH; } - public static Element USER_PROGRAM_FRAGMENT(RenderScript rs) { - if(rs.mElement_USER_PROGRAM_FRAGMENT == null) { - rs.mElement_USER_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT); + public static Element PROGRAM_FRAGMENT(RenderScript rs) { + if(rs.mElement_PROGRAM_FRAGMENT == null) { + rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT); } - return rs.mElement_USER_PROGRAM_FRAGMENT; + return rs.mElement_PROGRAM_FRAGMENT; } - public static Element USER_PROGRAM_VERTEX(RenderScript rs) { - if(rs.mElement_USER_PROGRAM_VERTEX == null) { - rs.mElement_USER_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX); + public static Element PROGRAM_VERTEX(RenderScript rs) { + if(rs.mElement_PROGRAM_VERTEX == null) { + rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX); } - return rs.mElement_USER_PROGRAM_VERTEX; + return rs.mElement_PROGRAM_VERTEX; } - public static Element USER_PROGRAM_RASTER(RenderScript rs) { - if(rs.mElement_USER_PROGRAM_RASTER == null) { - rs.mElement_USER_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER); + public static Element PROGRAM_RASTER(RenderScript rs) { + if(rs.mElement_PROGRAM_RASTER == null) { + rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER); } - return rs.mElement_USER_PROGRAM_RASTER; + return rs.mElement_PROGRAM_RASTER; } - public static Element USER_PROGRAM_STORE(RenderScript rs) { - if(rs.mElement_USER_PROGRAM_STORE == null) { - rs.mElement_USER_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE); + public static Element PROGRAM_STORE(RenderScript rs) { + if(rs.mElement_PROGRAM_STORE == null) { + rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE); } - return rs.mElement_USER_PROGRAM_STORE; + return rs.mElement_PROGRAM_STORE; } @@ -246,47 +246,34 @@ public class Element extends BaseObj { return rs.mElement_INDEX_16; } - public static Element ATTRIB_POSITION_2(RenderScript rs) { - if(rs.mElement_POSITION_2 == null) { - rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2); + public static Element F32_2(RenderScript rs) { + if(rs.mElement_FLOAT_2 == null) { + rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2); } - return rs.mElement_POSITION_2; + return rs.mElement_FLOAT_2; } - public static Element ATTRIB_POSITION_3(RenderScript rs) { - if(rs.mElement_POSITION_3 == null) { - rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3); + public static Element F32_3(RenderScript rs) { + if(rs.mElement_FLOAT_3 == null) { + rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3); } - return rs.mElement_POSITION_3; + return rs.mElement_FLOAT_3; } - public static Element ATTRIB_TEXTURE_2(RenderScript rs) { - if(rs.mElement_TEXTURE_2 == null) { - rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2); + public static Element F32_4(RenderScript rs) { + if(rs.mElement_FLOAT_4 == null) { + rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4); } - return rs.mElement_TEXTURE_2; + return rs.mElement_FLOAT_4; } - public static Element ATTRIB_NORMAL_3(RenderScript rs) { - if(rs.mElement_NORMAL_3 == null) { - rs.mElement_NORMAL_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.NORMAL, 3); + public static Element U8_4(RenderScript rs) { + if(rs.mElement_UCHAR_4 == null) { + rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4); } - return rs.mElement_NORMAL_3; + return rs.mElement_UCHAR_4; } - public static Element ATTRIB_COLOR_U8_4(RenderScript rs) { - if(rs.mElement_COLOR_U8_4 == null) { - rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4); - } - return rs.mElement_COLOR_U8_4; - } - - public static Element ATTRIB_COLOR_F32_4(RenderScript rs) { - if(rs.mElement_COLOR_F32_4 == null) { - rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4); - } - return rs.mElement_COLOR_F32_4; - } Element(RenderScript rs, Element[] e, String[] n) { super(rs); @@ -331,55 +318,6 @@ public class Element extends BaseObj { return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1); } - public static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int size) { - if (!(dt == DataType.FLOAT_32 || - dt == DataType.UNSIGNED_8 || - dt == DataType.UNSIGNED_16 || - dt == DataType.UNSIGNED_32 || - dt == DataType.SIGNED_8 || - dt == DataType.SIGNED_16 || - dt == DataType.SIGNED_32)) { - throw new IllegalArgumentException("Unsupported DataType"); - } - - if (!(dk == DataKind.COLOR || - dk == DataKind.POSITION || - dk == DataKind.TEXTURE || - dk == DataKind.NORMAL || - dk == DataKind.POINT_SIZE || - dk == DataKind.USER)) { - throw new IllegalArgumentException("Unsupported DataKind"); - } - - if (dk == DataKind.COLOR && - ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) || - size < 3 || size > 4)) { - throw new IllegalArgumentException("Bad combo"); - } - if (dk == DataKind.POSITION && (size < 1 || size > 4)) { - throw new IllegalArgumentException("Bad combo"); - } - if (dk == DataKind.TEXTURE && - (dt != DataType.FLOAT_32 || size < 1 || size > 4)) { - throw new IllegalArgumentException("Bad combo"); - } - if (dk == DataKind.NORMAL && - (dt != DataType.FLOAT_32 || size != 3)) { - throw new IllegalArgumentException("Bad combo"); - } - if (dk == DataKind.POINT_SIZE && - (dt != DataType.FLOAT_32 || size != 1)) { - throw new IllegalArgumentException("Bad combo"); - } - - boolean norm = false; - if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) { - norm = true; - } - - return new Element(rs, dt, dk, norm, size); - } - public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) { if (!(dk == DataKind.PIXEL_L || dk == DataKind.PIXEL_A || diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index acc58bc..eda849e 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -192,24 +192,24 @@ public class RenderScript { @SuppressWarnings({"FieldCanBeLocal"}) protected MessageThread mMessageThread; - Element mElement_USER_U8; - Element mElement_USER_I8; - Element mElement_USER_U16; - Element mElement_USER_I16; - Element mElement_USER_U32; - Element mElement_USER_I32; - Element mElement_USER_F32; - - Element mElement_USER_ELEMENT; - Element mElement_USER_TYPE; - Element mElement_USER_ALLOCATION; - Element mElement_USER_SAMPLER; - Element mElement_USER_SCRIPT; - Element mElement_USER_MESH; - Element mElement_USER_PROGRAM_FRAGMENT; - Element mElement_USER_PROGRAM_VERTEX; - Element mElement_USER_PROGRAM_RASTER; - Element mElement_USER_PROGRAM_STORE; + Element mElement_U8; + Element mElement_I8; + Element mElement_U16; + Element mElement_I16; + Element mElement_U32; + Element mElement_I32; + Element mElement_F32; + + Element mElement_ELEMENT; + Element mElement_TYPE; + Element mElement_ALLOCATION; + Element mElement_SAMPLER; + Element mElement_SCRIPT; + Element mElement_MESH; + Element mElement_PROGRAM_FRAGMENT; + Element mElement_PROGRAM_VERTEX; + Element mElement_PROGRAM_RASTER; + Element mElement_PROGRAM_STORE; Element mElement_A_8; Element mElement_RGB_565; @@ -219,12 +219,10 @@ public class RenderScript { Element mElement_RGBA_8888; Element mElement_INDEX_16; - Element mElement_POSITION_2; - Element mElement_POSITION_3; - Element mElement_TEXTURE_2; - Element mElement_NORMAL_3; - Element mElement_COLOR_U8_4; - Element mElement_COLOR_F32_4; + Element mElement_FLOAT_2; + Element mElement_FLOAT_3; + Element mElement_FLOAT_4; + Element mElement_UCHAR_4; Sampler mSampler_CLAMP_NEAREST; Sampler mSampler_CLAMP_LINEAR; diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java index 4a217a9..fc011b5 100644 --- a/graphics/java/android/renderscript/SimpleMesh.java +++ b/graphics/java/android/renderscript/SimpleMesh.java @@ -313,30 +313,20 @@ public class SimpleMesh extends BaseObj { public SimpleMesh create() { Element.Builder b = new Element.Builder(mRS); int floatCount = mVtxSize; - b.add(Element.createAttrib(mRS, + b.add(Element.createVector(mRS, Element.DataType.FLOAT_32, - Element.DataKind.POSITION, mVtxSize), "position"); if ((mFlags & COLOR) != 0) { floatCount += 4; - b.add(Element.createAttrib(mRS, - Element.DataType.FLOAT_32, - Element.DataKind.COLOR, - 4), "color"); + b.add(Element.F32_4(mRS), "color"); } if ((mFlags & TEXTURE_0) != 0) { floatCount += 2; - b.add(Element.createAttrib(mRS, - Element.DataType.FLOAT_32, - Element.DataKind.TEXTURE, - 2), "texture"); + b.add(Element.F32_2(mRS), "texture0"); } if ((mFlags & NORMAL) != 0) { floatCount += 3; - b.add(Element.createAttrib(mRS, - Element.DataType.FLOAT_32, - Element.DataKind.NORMAL, - 3), "normal"); + b.add(Element.F32_3(mRS), "normal"); } mElement = b.create(); diff --git a/libs/rs/java/Fountain/res/raw/fountain.rs b/libs/rs/java/Fountain/res/raw/fountain.rs index 67f7ef5..fe2ca33 100644 --- a/libs/rs/java/Fountain/res/raw/fountain.rs +++ b/libs/rs/java/Fountain/res/raw/fountain.rs @@ -40,6 +40,18 @@ int root() { return 1; } +// Putting the overloadable attribute on this function breaks rendering +// appears to be a bug. +static uchar4 /*__attribute__((overloadable))*/ pack(float r, float g, float b) +{ + uchar4 c; + c.x = (uchar)(r * 255.f); + c.y = (uchar)(g * 255.f); + c.z = (uchar)(b * 255.f); + c.w = 255; + return c; +} + void addParticles(int rate, int x, int y) { //rsDebug("partColor", partColor); @@ -51,7 +63,10 @@ void addParticles(int rate, int x, int y) float rMax = ((float)rate) * 0.005f; int size = rsAllocationGetDimX(rsGetAllocation(point)); - uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z); + //uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z); + uchar4 c = pack(partColor.x, partColor.y, partColor.z); + c.x = 255; + c.w = 255; //rsDebug("color ", ((int *)&c)[0]); Point_t * np = &point[newPart]; diff --git a/libs/rs/java/Fountain/res/raw/fountain_bc.bc b/libs/rs/java/Fountain/res/raw/fountain_bc.bc Binary files differindex 7b2e88b..d223460 100644 --- a/libs/rs/java/Fountain/res/raw/fountain_bc.bc +++ b/libs/rs/java/Fountain/res/raw/fountain_bc.bc diff --git a/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java index b091f39..91db2c6 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java @@ -30,9 +30,9 @@ public class ScriptField_Point mItemArray = new Item[count]; Element.Builder eb = new Element.Builder(rs); - eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta"); - eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position"); - eb.add(Element.createAttrib(rs, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color"); + eb.add(Element.F32_2(rs), "delta"); + eb.add(Element.F32_2(rs), "position"); + eb.add(Element.U8_4(rs), "color"); mElement = eb.create(); init(rs, count); diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index d4c29c8..d667c86 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -178,11 +178,11 @@ void ProgramVertex::createShader() } mShader.append(mUserShader); } else { - mShader.append("attribute vec4 ATTRIB_LegacyPosition;\n"); - mShader.append("attribute vec4 ATTRIB_LegacyColor;\n"); - mShader.append("attribute vec3 ATTRIB_LegacyNormal;\n"); - mShader.append("attribute float ATTRIB_LegacyPointSize;\n"); - mShader.append("attribute vec4 ATTRIB_LegacyTexture;\n"); + mShader.append("attribute vec4 ATTRIB_position;\n"); + mShader.append("attribute vec4 ATTRIB_color;\n"); + mShader.append("attribute vec3 ATTRIB_normal;\n"); + mShader.append("attribute float ATTRIB_pointSize;\n"); + mShader.append("attribute vec4 ATTRIB_texture0;\n"); for (uint32_t ct=0; ct < mUniformCount; ct++) { mShader.append("uniform mat4 "); @@ -191,14 +191,14 @@ void ProgramVertex::createShader() } mShader.append("void main() {\n"); - mShader.append(" gl_Position = UNI_MVP * ATTRIB_LegacyPosition;\n"); - mShader.append(" gl_PointSize = ATTRIB_LegacyPointSize;\n"); + mShader.append(" gl_Position = UNI_MVP * ATTRIB_position;\n"); + mShader.append(" gl_PointSize = ATTRIB_pointSize;\n"); - mShader.append(" varColor = ATTRIB_LegacyColor;\n"); + mShader.append(" varColor = ATTRIB_color;\n"); if (mTextureMatrixEnable) { - mShader.append(" varTex0 = UNI_TexMatrix * ATTRIB_LegacyTexture;\n"); + mShader.append(" varTex0 = UNI_TexMatrix * ATTRIB_texture0;\n"); } else { - mShader.append(" varTex0 = ATTRIB_LegacyTexture;\n"); + mShader.append(" varTex0 = ATTRIB_texture0;\n"); } //mShader.append(" pos.x = pos.x / 480.0;\n"); //mShader.append(" pos.y = pos.y / 800.0;\n"); diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp index 18f873e..8f650f8 100644 --- a/libs/rs/rsScriptC_LibGL.cpp +++ b/libs/rs/rsScriptC_LibGL.cpp @@ -131,12 +131,8 @@ static void SC_drawLine(float x1, float y1, float z1, float vtx[] = { x1, y1, z1, x2, y2, z2 }; VertexArray va; - va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx); - if (rsc->checkVersion2_0()) { - va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); - } else { - va.setupGL(rsc, &rsc->mStateVertexArray); - } + va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position"); + va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); glDrawArrays(GL_LINES, 0, 2); } @@ -151,12 +147,8 @@ static void SC_drawPoint(float x, float y, float z) float vtx[] = { x, y, z }; VertexArray va; - va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx); - if (rsc->checkVersion2_0()) { - va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); - } else { - va.setupGL(rsc, &rsc->mStateVertexArray); - } + va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position"); + va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); glDrawArrays(GL_POINTS, 0, 1); } @@ -185,14 +177,9 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1, const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4}; VertexArray va; - va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx); - va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex); - if (rsc->checkVersion2_0()) { - va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); - } else { - va.setupGL(rsc, &rsc->mStateVertexArray); - } - + va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position"); + va.add(GL_FLOAT, 2, 8, false, (uint32_t)tex, "texture0"); + va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp index 0218dc5..504ffba 100644 --- a/libs/rs/rsShaderCache.cpp +++ b/libs/rs/rsShaderCache.cpp @@ -98,16 +98,11 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag glAttachShader(pgm, frag->getShaderID()); if (!vtx->isUserProgram()) { - glBindAttribLocation(pgm, 0, "ATTRIB_LegacyPosition"); - glBindAttribLocation(pgm, 1, "ATTRIB_LegacyColor"); - glBindAttribLocation(pgm, 2, "ATTRIB_LegacyNormal"); - glBindAttribLocation(pgm, 3, "ATTRIB_LegacyPointSize"); - glBindAttribLocation(pgm, 4, "ATTRIB_LegacyTexture"); - e->mVtxAttribSlots[RS_KIND_POSITION] = 0; - e->mVtxAttribSlots[RS_KIND_COLOR] = 1; - e->mVtxAttribSlots[RS_KIND_NORMAL] = 2; - e->mVtxAttribSlots[RS_KIND_POINT_SIZE] = 3; - e->mVtxAttribSlots[RS_KIND_TEXTURE] = 4; + glBindAttribLocation(pgm, 0, "ATTRIB_position"); + glBindAttribLocation(pgm, 1, "ATTRIB_color"); + glBindAttribLocation(pgm, 2, "ATTRIB_normal"); + glBindAttribLocation(pgm, 3, "ATTRIB_pointSize"); + glBindAttribLocation(pgm, 4, "ATTRIB_texture0"); } //LOGE("e2 %x", glGetError()); diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp index 170b792..2dd082d 100644 --- a/libs/rs/rsSimpleMesh.cpp +++ b/libs/rs/rsSimpleMesh.cpp @@ -68,21 +68,12 @@ void SimpleMesh::renderRange(Context *rsc, uint32_t start, uint32_t len) const rsc->checkError("SimpleMesh::renderRange 1"); VertexArray va; - if (rsc->checkVersion2_0()) { - for (uint32_t ct=0; ct < mVertexTypeCount; ct++) { - mVertexBuffers[ct]->uploadCheck(rsc); - va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID()); - mVertexTypes[ct]->enableGLVertexBuffer2(&va); - } - va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); - } else { - for (uint32_t ct=0; ct < mVertexTypeCount; ct++) { - mVertexBuffers[ct]->uploadCheck(rsc); - va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID()); - mVertexTypes[ct]->enableGLVertexBuffer(&va); - } - va.setupGL(rsc, 0); + for (uint32_t ct=0; ct < mVertexTypeCount; ct++) { + mVertexBuffers[ct]->uploadCheck(rsc); + va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID()); + mVertexTypes[ct]->enableGLVertexBuffer(&va); } + va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache); rsc->checkError("SimpleMesh::renderRange 2"); if (mIndexType.get()) { diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp index 8f99209..89e73b0 100644 --- a/libs/rs/rsType.cpp +++ b/libs/rs/rsType.cpp @@ -148,131 +148,22 @@ void Type::makeGLComponents() for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) { const Component &c = getElement()->getField(ct)->getComponent(); - switch(c.getKind()) { - case RS_KIND_USER: - mGL.mUser[userNum].size = c.getVectorSize(); - mGL.mUser[userNum].offset = mElement->getFieldOffsetBytes(ct); - mGL.mUser[userNum].type = c.getGLType(); - mGL.mUser[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized(); - mGL.mUser[userNum].name.setTo(getElement()->getFieldName(ct)); - userNum ++; - break; - - case RS_KIND_POSITION: - rsAssert(mGL.mVtx.size == 0); - mGL.mVtx.size = c.getVectorSize(); - mGL.mVtx.offset = mElement->getFieldOffsetBytes(ct); - mGL.mVtx.type = c.getGLType(); - mGL.mVtx.normalized = false; - mGL.mVtx.name.setTo("Position"); - break; - - case RS_KIND_COLOR: - rsAssert(mGL.mColor.size == 0); - mGL.mColor.size = c.getVectorSize(); - mGL.mColor.offset = mElement->getFieldOffsetBytes(ct); - mGL.mColor.type = c.getGLType(); - mGL.mColor.normalized = c.getType() != RS_TYPE_FLOAT_32; - mGL.mColor.name.setTo("Color"); - break; - - case RS_KIND_NORMAL: - rsAssert(mGL.mNorm.size == 0); - mGL.mNorm.size = c.getVectorSize(); - mGL.mNorm.offset = mElement->getFieldOffsetBytes(ct); - mGL.mNorm.type = c.getGLType(); - mGL.mNorm.normalized = false; - mGL.mNorm.name.setTo("Normal"); - break; - - case RS_KIND_TEXTURE: - rsAssert(mGL.mTex.size == 0); - mGL.mTex.size = c.getVectorSize(); - mGL.mTex.offset = mElement->getFieldOffsetBytes(ct); - mGL.mTex.type = c.getGLType(); - mGL.mTex.normalized = false; - mGL.mTex.name.setTo("Texture"); - break; - - case RS_KIND_POINT_SIZE: - rsAssert(!mGL.mPointSize.size); - mGL.mPointSize.size = c.getVectorSize(); - mGL.mPointSize.offset = mElement->getFieldOffsetBytes(ct); - mGL.mPointSize.type = c.getGLType(); - mGL.mPointSize.normalized = false; - mGL.mPointSize.name.setTo("PointSize"); - break; - - default: - break; - } + mAttribs[userNum].size = c.getVectorSize(); + mAttribs[userNum].offset = mElement->getFieldOffsetBytes(ct); + mAttribs[userNum].type = c.getGLType(); + mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized(); + mAttribs[userNum].name.setTo(getElement()->getFieldName(ct)); + userNum ++; } } -void Type::enableGLVertexBuffer(VertexArray *va) const -{ - // Note: We are only going to enable buffers and never disable them - // here. The reason is more than one Allocation may be used as a vertex - // source. So we cannot disable arrays that may have been in use by - // another allocation. - uint32_t stride = mElement->getSizeBytes(); - if (mGL.mVtx.size) { - va->addLegacy(mGL.mVtx.type, - mGL.mVtx.size, - stride, - RS_KIND_POSITION, - false, - mGL.mVtx.offset); - } - - if (mGL.mNorm.size) { - va->addLegacy(mGL.mNorm.type, - 3, - stride, - RS_KIND_NORMAL, - false, - mGL.mNorm.offset); - } - - if (mGL.mColor.size) { - va->addLegacy(mGL.mColor.type, - mGL.mColor.size, - stride, - RS_KIND_COLOR, - true, - mGL.mColor.offset); - } - - if (mGL.mTex.size) { - va->addLegacy(mGL.mTex.type, - mGL.mTex.size, - stride, - RS_KIND_TEXTURE, - false, - mGL.mTex.offset); - } - - if (mGL.mPointSize.size) { - va->addLegacy(mGL.mPointSize.type, - 1, - stride, - RS_KIND_POINT_SIZE, - false, - mGL.mPointSize.offset); - } - -} - -void Type::enableGLVertexBuffer2(VertexArray *va) const +void Type::enableGLVertexBuffer(VertexArray *va) const { - // Do legacy buffers - enableGLVertexBuffer(va); - uint32_t stride = mElement->getSizeBytes(); for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) { - if (mGL.mUser[ct].size) { - va->addUser(mGL.mUser[ct], stride); + if (mAttribs[ct].size) { + va->add(mAttribs[ct], stride); } } } diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h index 664f343..f598f64 100644 --- a/libs/rs/rsType.h +++ b/libs/rs/rsType.h @@ -71,7 +71,6 @@ public: void compute(); void enableGLVertexBuffer(class VertexArray *) const; - void enableGLVertexBuffer2(class VertexArray *) const; void dumpLOGV(const char *prefix) const; virtual void serialize(OStream *stream) const; @@ -115,15 +114,7 @@ protected: LOD *mLODs; uint32_t mLODCount; - struct GLState_t { - VertexArray::Attrib mUser[RS_MAX_ATTRIBS]; - VertexArray::Attrib mVtx; - VertexArray::Attrib mNorm; - VertexArray::Attrib mColor; - VertexArray::Attrib mTex; - VertexArray::Attrib mPointSize; - }; - GLState_t mGL; + VertexArray::Attrib mAttribs[RS_MAX_ATTRIBS]; void makeGLComponents(); private: diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp index b42d1c4..425b584 100644 --- a/libs/rs/rsVertexArray.cpp +++ b/libs/rs/rsVertexArray.cpp @@ -60,7 +60,6 @@ void VertexArray::Attrib::set(const Attrib &a) size = a.size; stride = a.stride; normalized = a.normalized; - kind = RS_KIND_USER; name.setTo(a.name); } @@ -80,17 +79,16 @@ void VertexArray::clear(uint32_t n) mAttribs[n].clear(); } -void VertexArray::addUser(const Attrib &a, uint32_t stride) +void VertexArray::add(const Attrib &a, uint32_t stride) { rsAssert(mCount < RS_MAX_ATTRIBS); mAttribs[mCount].set(a); mAttribs[mCount].buffer = mActiveBuffer; mAttribs[mCount].stride = stride; - mAttribs[mCount].kind = RS_KIND_USER; mCount ++; } -void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset) +void VertexArray::add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name) { rsAssert(mCount < RS_MAX_ATTRIBS); mAttribs[mCount].clear(); @@ -100,96 +98,25 @@ void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDat mAttribs[mCount].normalized = normalized; mAttribs[mCount].buffer = mActiveBuffer; mAttribs[mCount].stride = stride; - mAttribs[mCount].kind = kind; + mAttribs[mCount].name.setTo(name); mCount ++; } void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const { - LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x kind=%i stride=0x%x norm=%i offset=0x%x", idx, slot, + LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx, slot, mAttribs[idx].name.string(), mAttribs[idx].buffer, mAttribs[idx].size, mAttribs[idx].type, - mAttribs[idx].kind, mAttribs[idx].stride, mAttribs[idx].normalized, mAttribs[idx].offset); } -void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const -{ - glClientActiveTexture(GL_TEXTURE0); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -#ifndef ANDROID_RS_BUILD_FOR_HOST // GLES only - glDisableClientState(GL_POINT_SIZE_ARRAY_OES); -#endif //ANDROID_RS_BUILD_FOR_HOST - - for (uint32_t ct=0; ct < mCount; ct++) { - switch(mAttribs[ct].kind) { - case RS_KIND_POSITION: - //logAttrib(POSITION); - glEnableClientState(GL_VERTEX_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glVertexPointer(mAttribs[ct].size, - mAttribs[ct].type, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); - break; - - case RS_KIND_NORMAL: - //logAttrib(NORMAL); - glEnableClientState(GL_NORMAL_ARRAY); - rsAssert(mAttribs[ct].size == 3); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glNormalPointer(mAttribs[ct].type, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); - break; - - case RS_KIND_COLOR: - //logAttrib(COLOR); - glEnableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glColorPointer(mAttribs[ct].size, - mAttribs[ct].type, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); - break; - - case RS_KIND_TEXTURE: - //logAttrib(TEXTURE); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glTexCoordPointer(mAttribs[ct].size, - mAttribs[ct].type, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); - break; -#ifndef ANDROID_RS_BUILD_FOR_HOST // GLES only - case RS_KIND_POINT_SIZE: - //logAttrib(POINT_SIZE); - glEnableClientState(GL_POINT_SIZE_ARRAY_OES); - glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glPointSizePointerOES(mAttribs[ct].type, - mAttribs[ct].stride, - (void *)mAttribs[ct].offset); - break; -#endif //ANDROID_RS_BUILD_FOR_HOST - - default: - rsAssert(0); - } - } - - rsc->checkError("VertexArray::setupGL"); -} - void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const { rsc->checkError("VertexArray::setupGL2 start"); - for (uint32_t ct=1; ct <= state->mLastEnableCount; ct++) { + for (uint32_t ct=1; ct <= 0xf/*state->mLastEnableCount*/; ct++) { glDisableVertexAttribArray(ct); } @@ -199,16 +126,24 @@ void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, Sh if (sc->isUserVertexProgram()) { slot = sc->vtxAttribSlot(ct); } else { - if (mAttribs[ct].kind == RS_KIND_USER) { + if (mAttribs[ct].name == "position") { + slot = 0; + } else if (mAttribs[ct].name == "color") { + slot = 1; + } else if (mAttribs[ct].name == "normal") { + slot = 2; + } else if (mAttribs[ct].name == "pointSize") { + slot = 3; + } else if (mAttribs[ct].name == "texture0") { + slot = 4; + } else { continue; } - slot = sc->vtxAttribSlot(mAttribs[ct].kind); } - //logAttrib(ct, slot); + logAttrib(ct, slot); glEnableVertexAttribArray(slot); glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); - glVertexAttribPointer(slot, mAttribs[ct].size, mAttribs[ct].type, diff --git a/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h index 3904cb6..e5b51d7 100644 --- a/libs/rs/rsVertexArray.h +++ b/libs/rs/rsVertexArray.h @@ -43,7 +43,6 @@ public: uint32_t stride; bool normalized; String8 name; - RsDataKind kind; Attrib(); void set(const Attrib &); @@ -53,8 +52,9 @@ public: void clearAll(); void setActiveBuffer(uint32_t id) {mActiveBuffer = id;} - void addUser(const Attrib &, uint32_t stride); - void addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset); + void add(const Attrib &, uint32_t stride); + //void addLegacy(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset); + void add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name); void setupGL(const Context *rsc, class VertexArrayState *) const; void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const; diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh index a2a5bab..c0ba4af 100644 --- a/libs/rs/scriptc/rs_core.rsh +++ b/libs/rs/scriptc/rs_core.rsh @@ -1,10 +1,10 @@ #ifndef __RS_CORE_RSH__ #define __RS_CORE_RSH__ -uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b); -uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a); +//uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b); +//uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a); -uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b) +static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b) { uchar4 c; c.x = (uchar)(r * 255.f); @@ -14,7 +14,7 @@ uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b return c; } -uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a) +static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a) { uchar4 c; c.x = (uchar)(r * 255.f); |