Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
VR-demos
Commits
8873015b
Commit
8873015b
authored
Sep 08, 2017
by
Ruben Jesus Garcia Hernandez
Browse files
Fix screenshot saving bug
Fix display of trajectories of atoms in large systems.
parent
85c755ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
NOMADVRLib/atomsGL.cpp
View file @
8873015b
...
...
@@ -49,7 +49,7 @@ GLenum atomTexture(GLuint t)
//WARNING: This should be called after SetupAtoms
//This means that numAtoms now has the cummulative distribution!
//This should be called after the atom texture is prepared, and therefore has the atomscaling pre-multiplied
GLenum
SetupAtomsNoTess
(
GLuint
**
AtomVAO
/*[
3
]*/
,
GLuint
**
AtomVertBuffer
/*[
2
]*/
,
GLuint
**
AtomIndexBuffer
/*[
3
]*/
)
GLenum
SetupAtomsNoTess
(
GLuint
**
AtomVAO
/*[
4
]*/
,
GLuint
**
AtomVertBuffer
/*[
3
]*/
,
GLuint
**
AtomIndexBuffer
/*[
2
]*/
)
//atoms, cloned atoms
//rgh: FIXME: add AtomVAO[2] for atom trajectories
{
...
...
@@ -71,13 +71,13 @@ if (!solid) {
int
totalatoms
=
numAtoms
[
getAtomTimesteps
()
-
1
];
//eprintf ("SetupAtomsNoTess 2");
*
AtomVAO
=
new
GLuint
[
3
];
//atoms, cloned atoms, unused (bonds use Tess atom positions)
*
AtomVAO
=
new
GLuint
[
4
];
//atoms, cloned atoms, unused (bonds use Tess atom positions)
, trajectories
*
AtomIndexBuffer
=
new
GLuint
[
3
];
//atoms, cloned atoms, bonds
*
AtomVertBuffer
=
new
GLuint
[
2
];
//atoms, cloned atoms
*
AtomVertBuffer
=
new
GLuint
[
3
];
//atoms, cloned atoms
, trajectories
glGenVertexArrays
(
3
,
*
AtomVAO
);
glGenVertexArrays
(
4
,
*
AtomVAO
);
glGenBuffers
(
2
,
*
AtomIndexBuffer
);
glGenBuffers
(
2
,
*
AtomVertBuffer
);
glGenBuffers
(
3
,
*
AtomVertBuffer
);
//eprintf ("SetupAtomsNoTess 3");
glBindVertexArray
((
*
AtomVAO
)[
0
]);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
(
*
AtomIndexBuffer
)[
0
]);
...
...
@@ -218,7 +218,7 @@ if (!solid) {
}
//SetupAtomsNoTess
GLenum
SetupAtoms
(
GLuint
**
AtomVAO
/*[
3
]*/
,
GLuint
**
AtomVertBuffer
/*[
2
]*/
,
GLuint
*
BondIndices
)
GLenum
SetupAtoms
(
GLuint
**
AtomVAO
/*[
4
]*/
,
GLuint
**
AtomVertBuffer
/*[
3
]*/
,
GLuint
*
BondIndices
)
{
if
(
!
numAtoms
)
return
glGetError
();
...
...
@@ -234,11 +234,11 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
}
eprintf
(
"SetupAtoms: totalatoms=%d"
,
totalatoms
);
*
AtomVAO
=
new
GLuint
[
3
];
//atoms, cloned atoms, bonds
//rgh fixme: for trajectories, we want to create another vao
*
AtomVertBuffer
=
new
GLuint
[
2
];
*
AtomVAO
=
new
GLuint
[
4
];
//atoms, cloned atoms, bonds
, trajectories
*
AtomVertBuffer
=
new
GLuint
[
3
];
//atoms, cloned atoms, trajectories
glGenVertexArrays
(
3
,
*
AtomVAO
);
glGenBuffers
(
2
,
*
AtomVertBuffer
);
glGenVertexArrays
(
4
,
*
AtomVAO
);
glGenBuffers
(
3
,
*
AtomVertBuffer
);
glGenBuffers
(
1
,
BondIndices
);
glBindVertexArray
((
*
AtomVAO
)[
0
]);
...
...
@@ -355,6 +355,29 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
}
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
<
TIMESTEPS
;
i
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
traj
[
t
*
TIMESTEPS
*
3
+
i
*
3
+
j
]
=
tmp
[
i
*
numAtoms
[
0
]
*
4
+
+
atomtrajectories
[
t
]
*
4
+
j
];
}
}
glBindVertexArray
((
*
AtomVAO
)[
3
]);
glBindBuffer
(
GL_ARRAY_BUFFER
,
(
*
AtomVertBuffer
)[
2
]);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
float
)
*
atomtrajectories
.
size
()
*
TIMESTEPS
*
3
,
traj
,
GL_STATIC_DRAW
);
glVertexAttribPointer
(
0
,
3
,
GL_FLOAT
,
GL_FALSE
,
3
*
sizeof
(
float
),
(
const
void
*
)(
0
));
glEnableVertexAttribArray
(
0
);
e
=
glGetError
();
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
eprintf
(
"opengl error %d, creating atom trajectories, l %d
\n
"
,
e
,
__LINE__
);
delete
[]
traj
;
}
delete
[]
tmp
;
//bonds
...
...
OpenVR/TimestepData/hellovr_opengl_main.cpp
View file @
8873015b
//========= Copyright Valve Corpora
t
ion ============//
//========= Copyright Valve Corporaion ============//
#define NOMINMAX
#define _CRTDBG_MAP_ALLOC
...
...
@@ -1928,7 +1928,7 @@ glReadPixels(0, 0, m_nRenderWidth, m_nRenderHeight, GL_RGB, GL_UNSIGNED_BYTE, pi
//little endian machine, R and B are flipped
if
(
screenshotdownscaling
==
1
)
{
s
=
SDL_CreateRGBSurfaceFrom
(
pixels
,
x
,
y
,
24
,
3
*
y
,
0xff
,
0xff00
,
0xff0000
,
0
);
s
=
SDL_CreateRGBSurfaceFrom
(
pixels
,
x
,
y
,
24
,
3
*
x
,
0xff
,
0xff00
,
0xff0000
,
0
);
}
else
{
for
(
int
i
=
0
;
i
<
x
;
i
++
)
for
(
int
j
=
0
;
j
<
y
;
j
++
)
{
...
...
@@ -1940,9 +1940,9 @@ glReadPixels(0, 0, m_nRenderWidth, m_nRenderHeight, GL_RGB, GL_UNSIGNED_BYTE, pi
for
(
int
m
=
0
;
m
<
3
;
m
++
)
pixels2
[
i
*
3
+
j
*
3
*
m_nRenderWidth
/
screenshotdownscaling
+
m
]
=
rgb
[
m
]
/
screenshotdownscaling
/
screenshotdownscaling
;
}
s
=
SDL_CreateRGBSurfaceFrom
(
pixels2
,
x
,
y
,
24
,
3
*
y
,
0xff
,
0xff00
,
0xff0000
,
0
);
s
=
SDL_CreateRGBSurfaceFrom
(
pixels2
,
x
,
y
,
24
,
3
*
x
,
0xff
,
0xff00
,
0xff0000
,
0
);
}
SDL_SaveBMP
(
s
,
name
);
SDL_SaveBMP
(
s
,
name
);
}
...
...
@@ -2181,7 +2181,18 @@ if (markers && p[0]==0 &&p[1]==0 &&p[2]==0) {
if
(
!
showTrajectories
)
return
;
glBindVertexArray
(
m_unAtomVAO
[
0
]);
/* //rgh: old rendering method using one buffer with all atoms
int maxstride;
glGetIntegerv(GL_MAX_VERTEX_ATTRIB_STRIDE, &maxstride);
for (int i = 0; i < atomtrajectories.size(); i++) {
if (maxstride<4 * sizeof(float)*numAtoms[0]) {
showTrajectories = false;
dprintf("OpenGL does not allow rendering of trajectories with currently implemented method (MAX_VERTEX_ATTRIB_STRIDE), disabling");
return;
}
}*/
glBindVertexArray
(
m_unAtomVAO
[
3
]);
glUseProgram
(
m_unUnitCellProgramID
);
glUniformMatrix4fv
(
m_nUnitCellMatrixLocation
,
1
,
GL_FALSE
,
transform
.
get
());
float
color2
[
4
]
=
{
1
,
0
,
0
,
1
};
...
...
@@ -2192,13 +2203,18 @@ if ((e = glGetError()) != GL_NO_ERROR)
glEnableVertexAttribArray
(
0
);
glDisableVertexAttribArray
(
1
);
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
dprintf
(
"Gl error after Render Atom trajectories timestep =%d: %d, %s
\n
"
,
currentset
,
e
,
gluErrorString
(
e
));
dprintf
(
"Gl error before Render Atom trajectories timestep =%d: %d, %s
\n
"
,
currentset
,
e
,
gluErrorString
(
e
));
for
(
int
i
=
0
;
i
<
atomtrajectories
.
size
();
i
++
)
{
glVertexAttribPointer
(
0
,
3
,
GL_FLOAT
,
GL_FALSE
,
4
*
sizeof
(
float
)
*
numAtoms
[
0
],
(
const
void
*
)(
0
+
4
*
sizeof
(
float
)
*
atomtrajectories
[
i
]));
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float)*numAtoms[0], (const void *)(0+4*sizeof(float)*atomtrajectories[i]));
//if ((e = glGetError()) != GL_NO_ERROR)
// dprintf("Gl error after Render Atom trajectories vertexAttribPointer timestep =%d: %d, %s\n", currentset, e, gluErrorString(e));
for
(
int
j
=
1
;
j
<
atomtrajectoryrestarts
[
i
].
size
();
j
++
)
{
int
orig
=
atomtrajectoryrestarts
[
i
][
j
-
1
];
int
orig
=
atomtrajectoryrestarts
[
i
][
j
-
1
]
+
TIMESTEPS
*
i
;
int
count
=
atomtrajectoryrestarts
[
i
][
j
]
-
atomtrajectoryrestarts
[
i
][
j
-
1
];
glDrawArrays
(
GL_LINE_STRIP
,
orig
,
count
);
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
dprintf
(
"Gl error after Render Atom trajectories DrawArrays timestep =%d: %d, %s
\n
"
,
currentset
,
e
,
gluErrorString
(
e
));
}
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
dprintf
(
"Gl error after Render Atom trajectories timestep =%d: %d, %s
\n
"
,
currentset
,
e
,
gluErrorString
(
e
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment