Commit ed9e6db9 authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
Browse files

Add support for isosurfaces.

No transparent shader yet.
parent 4295630a
......@@ -8,14 +8,19 @@ LOCAL_MODULE := ovrapp
LOCAL_SRC_FILES := ../../../Src/OvrApp.cpp ../../../Src/rply/rply.c \
../../../Src/NOMADVRLib/ConfigFile.cpp ../../../Src/NOMADVRLib/atoms.cpp \
../../../Src/happyhttp/happyhttp.cpp \
../../../Src/NOMADVRLib/atomsGL.cpp ../../../Src/NOMADVRLib/CompileGLShader.cpp \
../../../Src/NOMADVRLib/TessShaders.cpp ../../../Src/NOMADVRLib/UnitCellShaders.cpp \
../../../Src/NOMADVRLib/polyhedron.cpp
../../../Src/NOMADVRLib/atomsGL.cpp \
../../../Src/NOMADVRLib/CompileGLShader.cpp \
../../../Src/NOMADVRLib/TessShaders.cpp \
../../../Src/NOMADVRLib/UnitCellShaders.cpp \
../../../Src/NOMADVRLib/polyhedron.cpp \
../../../Src/NOMADVRLib/IsosurfacesGL.cpp \
../../../Src/NOMADVRLib/IsoShaders.cpp
LOCAL_STATIC_LIBRARIES := vrsound vrmodel vrlocale vrgui vrappframework systemutils libovrkernel
LOCAL_SHARED_LIBRARIES := vrapi
LOCAL_CPP_FEATURES += exceptions
LOCAL_CFLAGS := -DINDICESGL32 -I../../../Src/
LOCAL_CFLAGS := -DINDICESGL32 -DOCULUSMOBILE
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../Src/
include $(BUILD_SHARED_LIBRARY)
$(call import-module,LibOVRKernel/Projects/AndroidPrebuilt/jni)
......
......@@ -21,6 +21,7 @@ Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved.
#include "NOMADVRLib/UnitCellShaders.h"
#include "NOMADVRLib/TessShaders.h"
#include "NOMADVRLib/polyhedron.h"
#include "NOMADVRLib/IsosurfacesGL.h"
using namespace OVR;
......@@ -209,6 +210,69 @@ LOG("OneTimeInit, 4");
if (e!=GL_NO_ERROR)
eprintf ("SetupUnitCell error %d", e);
if (ISOS) {
PrepareISOShader(&ISOP, &ISOMatrixLoc);
std::vector<float> vertices;
#ifndef INDICESGL32
std::vector<short> indices;
#else
std::vector<GLuint> indices;
#endif
numISOIndices=new int[TIMESTEPS*ISOS];
ISOVAO=new GLuint[TIMESTEPS*ISOS];
ISOBuffer=new GLuint[TIMESTEPS*ISOS];
ISOIndices=new GLuint[TIMESTEPS*ISOS];
glGenBuffers(TIMESTEPS*ISOS, ISOBuffer);
glGenVertexArrays(TIMESTEPS*ISOS, ISOVAO);
glGenBuffers(TIMESTEPS*ISOS, ISOIndices);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("opengl error %d, glGenBuffers\n", e);
char tmpname[250];
int timestep=1;
for (int p = 0; p < TIMESTEPS*ISOS; p++) {
sprintf(tmpname, "%s%d-%s.ply", PATH, timestep,
plyfiles[p % ISOS]);
Matrix4f matFinal=Matrix4f::RotationX(-M_PI_2) *
Matrix4f::Translation(translations[p%ISOS][0],
translations[p%ISOS][1],
translations[p%ISOS][2]);
float t[16];
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
t[j*4+i]=matFinal.M[i][j];
if (!AddModelToScene(t, vertices, indices, tmpname, false,
isocolours[p%ISOS][0]<0, p%ISOS))
{
eprintf("Error loading ply file %s\n", tmpname);
//return;
}
#ifndef INDICESGL32
if (vertices.size() > 65535 * numComponents)
{
eprintf("Mesh has more than 64k vertices (%d), unsupported\n", vertdataarray[currentlod][p].size() / numComponents);
return;
}
#endif
numISOIndices[p] = indices.size();
if (GL_NO_ERROR!=PrepareGLiso(ISOVAO[p], ISOBuffer[p],
vertices, ISOIndices[p], indices))
eprintf ("PrepareGLiso, GL error");
vertices.clear();
indices.clear();
if (p % ISOS == ISOS - 1) {
eprintf ("timestep %d", timestep);
timestep++;
}
}
}
// LOG("End of OneTimeInit");
}
......@@ -291,6 +355,53 @@ Matrix4f OvrApp::Frame( const VrFrame & vrFrame )
return CenterEyeViewMatrix;
}
void OvrApp::RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso) {
GLenum e;
Matrix4f trans=Matrix4f::Translation(UserTranslation[0], UserTranslation[1], UserTranslation[2]);
//trans.translate(iPos).rotateX(-90).translate(UserPosition);
Matrix4f transform = eyeViewProjection*trans*Matrix4f::Scaling(0.2);
float t[16];
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
t[j*4+i]=transform.M[i][j];
glUseProgram(ISOP);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("1 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
glUniformMatrix4fv(ISOMatrixLoc, 1, GL_FALSE, t);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("2 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
if (iso!=ISOS) {
glBindVertexArray(ISOVAO[currentSet*ISOS+iso]);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("3 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
eprintf ("Drawing %d vertices, isos", numISOIndices[currentSet*ISOS+iso]);
glDrawElements(GL_TRIANGLES,numISOIndices[currentSet*ISOS+iso], GL_UNSIGNED_INT, 0);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("4 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
} else {
for (int i=0;i<ISOS;i++) {
glBindVertexArray(ISOVAO[currentSet*ISOS+i]);
glBindBuffer(GL_ARRAY_BUFFER, ISOBuffer[currentSet*ISOS+i]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ISOIndices[currentSet*ISOS+i]);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 10*sizeof(float), (const void *)(0*sizeof(float)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 10*sizeof(float), (const void *)(3*sizeof(float)));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 10*sizeof(float), (const void *)(6*sizeof(float)));
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("5 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
eprintf ("Drawing %d vertices, isos", numISOIndices[currentSet*ISOS+i]);
glDrawElements(GL_TRIANGLES,numISOIndices[currentSet*ISOS+i] , GL_UNSIGNED_INT, 0);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("6 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
}
}
}
void OvrApp::RenderAtoms(const float *m) //m[16]
{
eprintf ("RenderAtoms start numatoms %d", numAtoms);
......@@ -454,6 +565,10 @@ Matrix4f OvrApp::DrawEyeView( const int eye, const float fovDegreesX, const floa
//LOG ("DrawEyeView 2");
RenderUnitCell(eyeViewProjection);
//LOG ("DrawEyeView 3");
if (ISOS)
RenderIsos(eyeViewProjection, ISOS);
GL( glBindVertexArray( 0 ) );
GL( glUseProgram( 0 ) );
......@@ -466,33 +581,4 @@ Matrix4f OvrApp::DrawEyeView( const int eye, const float fovDegreesX, const floa
} // namespace OvrTemplateApp
/*
static int vertex_cb(p_ply_argument argument) {
long what;
ply_get_argument_user_data(argument, NULL, &what);
if (what <=2 ) {
if (what==0)
OvrTemplateApp::currentVertex++;
OvrTemplateApp::cubeVertices.positions[OvrTemplateApp::currentVertex][what]=ply_get_argument_value(argument);
} else if (what <=5 ){
OvrTemplateApp::cubeVertices.normals[OvrTemplateApp::currentVertex][what-3]=ply_get_argument_value(argument);
} else if (what >9) {
OvrTemplateApp::cubeVertices.uvs[OvrTemplateApp::currentVertex][what-10]=ply_get_argument_value(argument);
} else {
OvrTemplateApp::cubeVertices.colors[OvrTemplateApp::currentVertex][what-6]=ply_get_argument_value(argument)/255.0;
//if (what==9)
// OvrTemplateApp::currentVertex++;
}
return 1;
}
static int face_cb(p_ply_argument argument) {
long length, value_index;
ply_get_argument_property(argument, NULL, &length, &value_index);
//discard the first call with a 3
if (value_index>=0 && value_index<=2)
OvrTemplateApp::cubeIndices[OvrTemplateApp::currentCubeIndex++]=(int)(ply_get_argument_value(argument));
return 1;
}
*/
......@@ -54,13 +54,20 @@ private:
int animateCounter=0;
GLuint textures[2]; // white, atoms
//if no tesselation is available, we still need the tess atoms for the trajectories!
GLuint *AtomTVAO=0, *AtomTBuffer=0, *AtomVAO=0, *AtomBuffer=0, *AtomIndices=0,//[2], atoms, extraatoms
GLuint *AtomTVAO=nullptr, *AtomTBuffer=nullptr, *AtomVAO=nullptr, *AtomBuffer=nullptr, *AtomIndices=nullptr,//[2], atoms, extraatoms
UnitCellVAO, UnitCellBuffer, UnitCellIndexBuffer;
GLuint *ISOVAO=nullptr/*[ISOS*TIMESTEPS]*/, *ISOBuffer=nullptr/*[ISOS*TIMESTEPS]*/,
*ISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
GLuint ISOP;
GLint ISOMatrixLoc;
int *numISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
void RenderAtoms(const float *m);
void RenderUnitCell(const OVR::Matrix4f eyeViewProjection);
void RenderAtomTrajectoriesUnitCell();
bool hasTess=true;
void RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso);
};
} // namespace OvrTemplateApp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment