Skip to content

Commit

Permalink
Fix for issue #1722, GVRCubeSceneObject with texture array throw invo…
Browse files Browse the repository at this point in the history
…cation exception (#1723)

* Fixing issue #1722, GVRCubeSceneObject with texture array throw invocation exception

* Ensure the right buffers are bound
  • Loading branch information
liaxim authored Feb 7, 2018
1 parent 5083fa4 commit 426f34c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public GVRCubeSceneObject(GVRContext gvrContext, boolean facingOut,
"The length of textureList is not 6.");
}

createSimpleCubeSixMeshes(gvrContext, facingOut, "float a_position float a_texcoord float a_normal", textureList);
createSimpleCubeSixMeshes(gvrContext, facingOut, "float3 a_position float2 a_texcoord float3 a_normal", textureList);
}

/**
Expand Down Expand Up @@ -555,34 +555,36 @@ private void createSimpleCubeSixMeshes(GVRContext gvrContext,
{
GVRSceneObject[] children = new GVRSceneObject[6];
GVRMesh[] meshes = new GVRMesh[6];
GVRVertexBuffer vbuf = new GVRVertexBuffer(gvrContext, vertexDesc, SIMPLE_VERTICES.length);
GVRVertexBuffer vbuf = new GVRVertexBuffer(gvrContext, vertexDesc, SIMPLE_VERTICES.length / 3);

if (facingOut)
{
vbuf.setFloatArray("a_normal", SIMPLE_OUTWARD_NORMALS);
vbuf.setFloatArray("a_texcoord", SIMPLE_OUTWARD_TEXCOORDS);
meshes[0] = createMesh(vbuf, 0, SIMPLE_OUTWARD_FRONT_INDICES);
meshes[1] = createMesh(vbuf, 6, SIMPLE_OUTWARD_RIGHT_INDICES);
meshes[2] = createMesh(vbuf, 12, SIMPLE_OUTWARD_BACK_INDICES);
meshes[3] = createMesh(vbuf, 18, SIMPLE_OUTWARD_LEFT_INDICES);
meshes[4] = createMesh(vbuf, 24, SIMPLE_OUTWARD_TOP_INDICES);
meshes[5] = createMesh(vbuf, 30, SIMPLE_OUTWARD_BOTTOM_INDICES);
vbuf.setFloatArray("a_position", SIMPLE_VERTICES, 3, 0);
vbuf.setFloatArray("a_normal", SIMPLE_OUTWARD_NORMALS, 3, 0);
vbuf.setFloatArray("a_texcoord", SIMPLE_OUTWARD_TEXCOORDS, 2, 0);
meshes[0] = createMesh(vbuf, SIMPLE_OUTWARD_FRONT_INDICES);
meshes[1] = createMesh(vbuf, SIMPLE_OUTWARD_RIGHT_INDICES);
meshes[2] = createMesh(vbuf, SIMPLE_OUTWARD_BACK_INDICES);
meshes[3] = createMesh(vbuf, SIMPLE_OUTWARD_LEFT_INDICES);
meshes[4] = createMesh(vbuf, SIMPLE_OUTWARD_TOP_INDICES);
meshes[5] = createMesh(vbuf, SIMPLE_OUTWARD_BOTTOM_INDICES);
}
else
{
vbuf.setFloatArray("a_normal", SIMPLE_INWARD_NORMALS);
vbuf.setFloatArray("a_texcoord", SIMPLE_INWARD_TEXCOORDS);
meshes[0] = createMesh(vbuf, 0, SIMPLE_INWARD_FRONT_INDICES);
meshes[1] = createMesh(vbuf, 6, SIMPLE_INWARD_RIGHT_INDICES);
meshes[2] = createMesh(vbuf, 12, SIMPLE_INWARD_BACK_INDICES);
meshes[3] = createMesh(vbuf, 18, SIMPLE_INWARD_LEFT_INDICES);
meshes[4] = createMesh(vbuf, 24, SIMPLE_INWARD_TOP_INDICES);
meshes[5] = createMesh(vbuf, 30, SIMPLE_INWARD_BOTTOM_INDICES);
vbuf.setFloatArray("a_position", SIMPLE_VERTICES, 3, 0);
vbuf.setFloatArray("a_normal", SIMPLE_INWARD_NORMALS, 3, 0);
vbuf.setFloatArray("a_texcoord", SIMPLE_INWARD_TEXCOORDS, 2, 0);
meshes[0] = createMesh(vbuf, SIMPLE_INWARD_FRONT_INDICES);
meshes[1] = createMesh(vbuf, SIMPLE_INWARD_RIGHT_INDICES);
meshes[2] = createMesh(vbuf, SIMPLE_INWARD_BACK_INDICES);
meshes[3] = createMesh(vbuf, SIMPLE_INWARD_LEFT_INDICES);
meshes[4] = createMesh(vbuf, SIMPLE_INWARD_TOP_INDICES);
meshes[5] = createMesh(vbuf, SIMPLE_INWARD_BOTTOM_INDICES);
}

for (int i = 0; i < 6; i++)
{
children[i] = new GVRSceneObject(gvrContext,
meshes[i], textureList.get(i));
children[i] = new GVRSceneObject(gvrContext, meshes[i], textureList.get(i));
addChildObject(children[i]);
}

Expand All @@ -591,18 +593,11 @@ private void createSimpleCubeSixMeshes(GVRContext gvrContext,
attachRenderData(renderData);
}

private GVRMesh createMesh(GVRVertexBuffer vbuf, int offset, char[] indices)
private GVRMesh createMesh(GVRVertexBuffer vbuf, char[] indices)
{
char[] temp = new char[6];
GVRIndexBuffer ibuf = new GVRIndexBuffer(vbuf.getGVRContext(), 2, 6);
GVRMesh mesh = new GVRMesh(vbuf, ibuf);
for (int i = 0; i < 6; ++i)
{
temp[i] = indices[i];
temp[i] += offset;
}
ibuf.setShortVec(temp);
return mesh;
final GVRIndexBuffer ibuf = new GVRIndexBuffer(vbuf.getGVRContext(), 2, 6);
ibuf.setShortVec(indices);
return new GVRMesh(vbuf, ibuf);
}

private void createComplexCube(GVRContext gvrContext,
Expand Down
11 changes: 6 additions & 5 deletions GVRf/Framework/framework/src/main/jni/gl/gl_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ namespace gvr {
GLuint programId = static_cast<GLShader*>(shader)->getProgramId();

glBindVertexArray(mVArrayID);
if (mProgramID == programId)
{
return;
}
mProgramID = programId;
if (ibuf)
{
ibuf->bindBuffer(shader);
}
LOGV("VertexBuffer::bindToShader bind vertex array %d to shader %d", mVBufferID, programId);
glBindBuffer(GL_ARRAY_BUFFER, mVBufferID);

if (mProgramID == programId)
{
return;
}
mProgramID = programId;

shader->getVertexDescriptor().forEachEntry([this, programId](const DataDescriptor::DataEntry &e)
{
GLint loc = glGetAttribLocation(programId, e.Name);
Expand Down

0 comments on commit 426f34c

Please sign in to comment.