Render opaque isos before transparent isos.

This provides a better visualization when we have only opaque surfaces,
and paves the way for mixture of opaque and transparent surfaces.
parent 19ce1113
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lrz.NOMADGearvrT"
android:versionCode="2"
android:versionName="1.0"
android:versionCode="4"
android:versionName="1.2"
android:installLocation="auto"
>
......
......@@ -15,8 +15,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
versionCode 2
versionName "0.2"
versionCode 4
versionName "1.2"
}
sourceSets {
......
......@@ -2,7 +2,7 @@
/*These licenses are compatible with Apache 2.0*/
/*
# Copyright 2016-2018 Ruben Jesus Garcia Hernandez
# Copyright 2016-2019 Ruben Jesus Garcia Hernandez
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
......@@ -175,6 +175,11 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO
LOG("NOMADGearVRT No atom glyph specified, using Icosahedron");
solid=new Solid(Solid::Type::Icosahedron);
}
UserTranslation[0]=-userpos[0];
UserTranslation[1]=-userpos[2];
UserTranslation[2]=userpos[1];
// LOG("OneTimeInit, 2");
const ovrJava * java = app->GetJava();
SoundEffectContext = new ovrSoundEffectContext( *java->Env, java->ActivityObject );
......@@ -239,6 +244,7 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO
if (ISOS || markers) {
PrepareISOShader(&ISOP, &ISOMatrixLoc);
currentISO=ISOS;
}
if (ISOS) {
......@@ -365,7 +371,15 @@ void OvrApp::OneTimeShutdown()
bool OvrApp::OnKeyEvent( const int keyCode, const int repeatCount, const KeyEventType eventType )
{
animateTimesteps=!animateTimesteps;
if (eventType==KEY_EVENT_SHORT_PRESS) {
if (backbuttonTimesteps) {
animateTimesteps=!animateTimesteps;
} else {
currentISO++;
if (currentISO==ISOS+1)
currentISO=0;
}
}
//eprintf("OnKeyEvent called! keycode=%d", keyCode);
return true;
/*if ( GuiSys->OnKeyEvent( keyCode, repeatCount, eventType ) )
......@@ -426,6 +440,26 @@ Matrix4f OvrApp::Frame( const VrFrame & vrFrame )
return CenterEyeViewMatrix;
}
void OvrApp::RenderOneIso(int i) {
GLenum e;
//rgh FIXME, redo this when we have the new rendering code for atom trajectories
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::RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso) {
GLenum e;
Matrix4f trans=Matrix4f::Translation(UserTranslation[0], UserTranslation[1], UserTranslation[2]);
......@@ -452,26 +486,20 @@ void OvrApp::RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso) {
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("4 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
} else {
//rgh: render explicitly opaque surfaces first, then rest
//rgh: isocolours alpha == 1 for these surfaces
for (int i=0;i<ISOS;i++) {
if (isocolours[i][3]==1) {
RenderOneIso(i);
}
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDepthMask(GL_FALSE);
for (int i=0;i<ISOS;i++) {
//rgh FIXME, redo this when we have the new rendering code for atom trajectories
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);
if (isocolours[i][3]==1)
continue;
RenderOneIso(i);
}
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
......@@ -712,7 +740,7 @@ Matrix4f OvrApp::DrawEyeView( const int eye, const float fovDegreesX, const floa
RenderAtomTrajectories(eyeViewProjection);
if (ISOS)
RenderIsos(eyeViewProjection, ISOS);
RenderIsos(eyeViewProjection, currentISO);
GL( glBindVertexArray( 0 ) );
GL( glUseProgram( 0 ) );
......
......@@ -37,6 +37,8 @@ public:
class OVR::ovrLocale & GetLocale() { return *Locale; }
private:
void RenderOneIso(int iso);
OVR::ovrSoundEffectContext * SoundEffectContext;
OVR::OvrGuiSys::SoundEffectPlayer * SoundEffectPlayer;
OVR::OvrGuiSys * GuiSys;
......@@ -47,9 +49,10 @@ private:
GLint VertexTransformAttribute, VTAGrid;
ovrMatrix4f CenterEyeViewMatrix;
OVR::Vector4f UserTranslation=OVR::Vector4f(0,0,-30,0);
OVR::Vector4f UserTranslation=OVR::Vector4f(0,0,0,0);
OVR::Vector4f eyedir=OVR::Vector4f(0,0,0,0);
int currentSet=0;
int currentISO;
bool animateTimesteps=false;
int animateCounter=0;
GLuint textures[2]; // white, atoms
......
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