/* # Copyright 2016-2018 The NOMAD Developers Group # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. */ #include #include "eprintf.h" #include "TessShaders.h" #include "UnitCellShaders.h" #include "markerShaders.h" #include "atomsGL.h" #include "atoms.hpp" #include "ConfigFile.h" #include "CompileGLShader.h" #include "polyhedron.h" #include "Grid.h" int getAtomTimesteps() { if (fixedAtoms) return 1; else return TIMESTEPS; } GLenum atomTexture(GLuint t) { GLenum e; int finalatoms=getTotalAtomsInTexture(); //rgh: scale atoms here //in google cardboard, this is called again if the program is running, so leave original or atoms get progresivelly smaller! float *a=new float[finalatoms*4]; for (int i = 0; i < atomsInPeriodicTable; i++) { a[i*4+0]=atomColours[i][0]; a[i*4+1]=atomColours[i][1]; a[i*4+2]=atomColours[i][2]; a[i*4+3]=atomColours[i][3] * atomScaling; } for (int i=0;inVerts); float *tmp = new float[solid->nVerts * 7 * totalatoms]; //eprintf ("SetupAtomsNoTess 6"); #ifdef INDICESGL32 int *tmpi = new int[solid->nFaces*3 * totalatoms]; //eprintf ("SetupAtomsNoTess 7"); int *currenti=tmpi; #else unsigned short *tmpi = new unsigned short[solid->nFaces*3 * totalatoms]; //eprintf ("SetupAtomsNoTess 7B"); unsigned short *currenti=tmpi; #endif float *current=tmp; //eprintf ("Before For 1"); for (int p=0;p(atoms[p][4 * a + 3]); const float radius = atomRadius(atomNumber)*atomScaling; for (int i = 0; i < solid->nVerts; i++) { //verts for (int k = 0; k < 3; k++) { *current++ = solid->Verts[3 * i + k]* radius +atoms[p][4 * a + k]; //pos } for (int k = 0; k < 3; k++) { *current++ = solid->Verts[3 * i + k]; //normal } *current++ = static_cast(atomNumber); } //i for (int i = 0; i < solid->nFaces * 3; i++) *currenti++ = solid->Faces[i] + (a+(p==0?0:numAtoms[p-1]))*solid->nVerts; } //a } //p glBufferData(GL_ARRAY_BUFFER, sizeof(float) *totalatoms* 7 * solid->nVerts, tmp, GL_STATIC_DRAW); if ((e = glGetError()) != GL_NO_ERROR) eprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__); glBufferData(GL_ELEMENT_ARRAY_BUFFER, #ifdef INDICESGL32 sizeof(int) #else sizeof(unsigned int) #endif * totalatoms * 3 * solid->nFaces, tmpi, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7*sizeof(float), (const void *)0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (const void *)(3*sizeof(float))); glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (const void *)(6 * sizeof(float))); if (glGetError() != GL_NO_ERROR) eprintf("opengl error attrib pointer 0\n"); //glBindVertexArray(0); //glDisableVertexAttribArray(0); delete[] tmp; delete[] tmpi; if ((e = glGetError()) != GL_NO_ERROR) eprintf("opengl error %d, end of SetupAtoms, l %d\n", e, __LINE__); //FIXME TODO: cloned atoms tmp = new float[solid->nVerts * 7 * numClonedAtoms]; current=tmp; //eprintf ("SetupAtomsNoTess 6"); #ifdef INDICESGL32 tmpi = new int[solid->nFaces*3 * numClonedAtoms]; //eprintf ("SetupAtomsNoTess 7"); currenti=tmpi; #else tmpi = new unsigned short[solid->nFaces*3 * numClonedAtoms]; //eprintf ("SetupAtomsNoTess 7B"); currenti=tmpi; #endif //eprintf ("Before For 2"); for (int a = 0; a < numClonedAtoms; a++) { const int atomNumber = static_cast(clonedAtoms[0][4 * a + 3]); const float radius = atomRadius(atomNumber)*atomScaling; for (int i = 0; i < solid->nVerts; i++) { //verts for (int k = 0; k < 3; k++) { *current++ = solid->Verts[3 * i + k]* radius +clonedAtoms[0][4 * a + k]; //pos } for (int k = 0; k < 3; k++) { *current++ = solid->Verts[3 * i + k]; //normal } *current++ = static_cast(atomNumber); } //i for (int i = 0; i < solid->nFaces * 3; i++) *currenti++ = solid->Faces[i] + a*solid->nVerts; } //a //eprintf ("After For 2"); glBindVertexArray((*AtomVAO)[1]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (*AtomIndexBuffer)[1]); glBindBuffer(GL_ARRAY_BUFFER, (*AtomVertBuffer)[1]); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glDisableVertexAttribArray(3); glBufferData(GL_ARRAY_BUFFER, sizeof(float) *numClonedAtoms* 7 * solid->nVerts, tmp, GL_STATIC_DRAW); if ((e = glGetError()) != GL_NO_ERROR) eprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__); //eprintf ("After bufferdata, array buffer"); glBufferData(GL_ELEMENT_ARRAY_BUFFER, #ifdef INDICESGL32 sizeof(int) #else sizeof(unsigned int) #endif * numClonedAtoms * 3 * solid->nFaces, tmpi, GL_STATIC_DRAW); //eprintf ("After bufferdata, element array buffer"); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7*sizeof(float), (const void *)0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (const void *)(3*sizeof(float))); glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (const void *)(6 * sizeof(float))); if ((e = glGetError()) != GL_NO_ERROR) eprintf("opengl error %d, glVertexAttribPointer, l %d\n", e, __LINE__); delete[] tmp; delete[] tmpi; glBindVertexArray(0); return e; } //SetupAtomsNoTess GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLuint *BondIndices) { if (!numAtoms) return glGetError(); //rgh FIXME: put this all in the same vao //http://prideout.net/blog/?p=48 //public domain code //xyz u=atom type ; 4 floats int e; int totalatoms=0; for (int i=0;i(atoms[p][4 * a1 + 3]))+ atomRadius(static_cast(atoms[p][4 * a2 + 3])); if (d*bondscalingatoms[p][4*a+k]) m[k]=atoms[p][4*a+k]; if (M[k] found=g.find(atoms[p]+4*a); for (int b=0;b()); atomtrajectoryrestarts[t].push_back(0); for (int p=1;pmax) atomtrajectoryrestarts[t].push_back(p); } atomtrajectoryrestarts[t].push_back(getAtomTimesteps() ); } //need to setup a specific buffer because of GL_MAX_VERTEX_ATTRIB_STRIDE //only need xyz, not atom size //rgh FIXME: If we use index buffer instead, GPU storage is 1/3 of this float *traj = new float[atomtrajectories.size()*TIMESTEPS*3]; for (unsigned int t = 0; t < atomtrajectories.size(); t++) { for (int i=0;i(p[ss])*abc[ss][i]; for (int i=0;i<3;i++) f[i]=0; for (int ss=0;ss<3;ss++) for (int i=0;i<3;i++) f[i]+=delta[ss][i]; }