Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d71e218 authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Moving attrib creation to Mesh. Adding arrays as shader inputs.

Removing fixed size arrays.

Change-Id: I0213e403a2f1283dd43f21bea770aeb059561903
parent 5b59e02e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ public class Mesh extends BaseObj {
                rs.nMeshBindVertex(id, alloc.getID(), ct);
                newMesh.mVertexBuffers[ct] = alloc;
            }
            rs.nMeshInitVertexAttribs(id);

            return newMesh;
        }
@@ -294,6 +295,7 @@ public class Mesh extends BaseObj {
                rs.nMeshBindVertex(id, entry.a.mID, ct);
                newMesh.mVertexBuffers[ct] = entry.a;
            }
            rs.nMeshInitVertexAttribs(id);

            return newMesh;
        }
+4 −0
Original line number Diff line number Diff line
@@ -486,6 +486,10 @@ public class RenderScript {
    synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) {
        rsnMeshBindIndex(mContext, id, alloc, prim, slot);
    }
    native void rsnMeshInitVertexAttribs(int con, int id);
    synchronized void nMeshInitVertexAttribs(int id) {
        rsnMeshInitVertexAttribs(mContext, id);
    }
    native int  rsnMeshGetVertexBufferCount(int con, int id);
    synchronized int nMeshGetVertexBufferCount(int id) {
        return rsnMeshGetVertexBufferCount(mContext, id);
+9 −0
Original line number Diff line number Diff line
@@ -1152,6 +1152,14 @@ nMeshBindIndex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc
    rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot);
}

static void
nMeshInitVertexAttribs(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
{
    LOG_API("nMeshInitVertexAttribs, con(%p), Mesh(%p)", con, (RsMesh)mesh);
    rsMeshInitVertexAttribs(con, (RsMesh)mesh);
}


static jint
nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
{
@@ -1334,6 +1342,7 @@ static JNINativeMethod methods[] = {
{"rsnMeshCreate",                    "(III)I",                                (void*)nMeshCreate },
{"rsnMeshBindVertex",                "(IIII)V",                               (void*)nMeshBindVertex },
{"rsnMeshBindIndex",                 "(IIIII)V",                              (void*)nMeshBindIndex },
{"rsnMeshInitVertexAttribs",         "(II)V",                                 (void*)nMeshInitVertexAttribs },

{"rsnMeshGetVertexBufferCount",      "(II)I",                                 (void*)nMeshGetVertexBufferCount },
{"rsnMeshGetIndexCount",             "(II)I",                                 (void*)nMeshGetIndexCount },
+16 −0
Original line number Diff line number Diff line

varying lowp float light0_Diffuse;
varying lowp float light0_Specular;
varying lowp float light1_Diffuse;
varying lowp float light1_Specular;
varying vec2 varTex0;

void main() {
   vec2 t0 = varTex0.xy;
   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
   col.xyz = col.xyz * (light0_Diffuse * UNI_light_DiffuseColor[0].xyz + light1_Diffuse * UNI_light_DiffuseColor[1].xyz);
   col.xyz += light0_Specular * UNI_light_SpecularColor[0].xyz;
   col.xyz += light1_Specular * UNI_light_SpecularColor[1].xyz;
   gl_FragColor = col;
}
+32 −0
Original line number Diff line number Diff line
varying float light0_Diffuse;
varying float light0_Specular;
varying float light1_Diffuse;
varying float light1_Specular;
varying vec2 varTex0;

// This is where actual shader code begins
void main() {
   vec4 worldPos = UNI_model[0] * ATTRIB_position;
   worldPos = UNI_model[1] * worldPos;
   gl_Position = UNI_proj * worldPos;

   mat4 model0 = UNI_model[0];
   mat3 model3 = mat3(model0[0].xyz, model0[1].xyz, model0[2].xyz);
   vec3 worldNorm = model3 * ATTRIB_normal;
   vec3 V = normalize(-worldPos.xyz);

   vec3 light0Vec = normalize(UNI_light_Posision[0].xyz - worldPos.xyz);
   vec3 light0R = -reflect(light0Vec, worldNorm);
   light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light_Diffuse[0];
   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
   light0_Specular = pow(light0Spec, UNI_light_CosinePower[0]) * UNI_light_Specular[0];

   vec3 light1Vec = normalize(UNI_light_Posision[1].xyz - worldPos.xyz);
   vec3 light1R = reflect(light1Vec, worldNorm);
   light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light_Diffuse[1];
   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
   light1_Specular = pow(light1Spec, UNI_light_CosinePower[1]) * UNI_light_Specular[1];

   gl_PointSize = 1.0;
   varTex0 = ATTRIB_texture0;
}
Loading