projects
/
clouds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
efac65a
)
Read whole buffer to get it proper asynchronous
author
Luke Lau
<luke_lau@icloud.com>
Mon, 13 Apr 2020 23:23:40 +0000
(
00:23
+0100)
committer
Luke Lau
<luke_lau@icloud.com>
Mon, 13 Apr 2020 23:23:40 +0000
(
00:23
+0100)
clouds.cpp
patch
|
blob
|
history
diff --git
a/clouds.cpp
b/clouds.cpp
index f0f3a957576d17da6fdf5b60c521174e060eaeec..ff6e59d8faca801d28a5638897a28e115ffb0b37 100644
(file)
--- a/
clouds.cpp
+++ b/
clouds.cpp
@@
-63,7
+63,8
@@
void precalculateBillboardTextures() {
float r = distance(vec2(i, j), vec2(16, 16)) / 16;
float density = (float)d / NQ;
data[i + j * 32] =
float r = distance(vec2(i, j), vec2(16, 16)) / 16;
float density = (float)d / NQ;
data[i + j * 32] =
- 1 - fmin(1, (3 * density * (metaballField(r) / normalizationFactor)));
+ 1 -
+ fmin(1, (3 * density * (metaballField(r) / normalizationFactor)));
}
}
}
}
@@
-168,12
+169,15
@@
const int shadeWidth = 256, shadeHeight = 256;
#ifdef PBO
const int numPbos = 64;
GLuint pboBufs[numPbos];
#ifdef PBO
const int numPbos = 64;
GLuint pboBufs[numPbos];
+GLuint pboOffsets[numPbos]; // offsets into GL_PIXEL_PACK_BUFFER that
+ // mapPixelRead should read from
GLbyte sink[shadeWidth * shadeHeight * 4];
void inline mapPixelRead(int pboBuf, int metaball) {
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboBufs[pboBuf]);
GLbyte sink[shadeWidth * shadeHeight * 4];
void inline mapPixelRead(int pboBuf, int metaball) {
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboBufs[pboBuf]);
- GLubyte *src = (GLubyte *)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 4 * sizeof(GLubyte),
- GL_MAP_READ_BIT);
+ GLubyte *src =
+ (GLubyte *)glMapBufferRange(GL_PIXEL_PACK_BUFFER, pboOffsets[pboBuf],
+ 4 * sizeof(GLubyte), GL_MAP_READ_BIT);
vec4 pixel = vec4(src[0], src[1], src[2], src[3]) / vec4(255.f);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
vec4 pixel = vec4(src[0], src[1], src[2], src[3]) / vec4(255.f);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
@@
-263,11
+267,14
@@
void shadeClouds() {
#else
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboBufs[pboIdx]);
#else
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboBufs[pboIdx]);
- glReadPixels(screenPos.x, screenPos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
- NULL);
- /
/ TODO: use this
-
/* glReadPixels(0, 0, shadeWidth, shadeHeight, GL_RGBA, GL_UNSIGNED_BYTE,
*/
+ // It would be nice if this worked. But it doesn't
+ // macOS driver does this synchronously
+ /
* glReadPixels(screenPos.x, screenPos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
+ */
/* NULL); */
/* NULL); */
+ glReadPixels(0, 0, shadeWidth, shadeHeight, GL_RGBA, GL_UNSIGNED_BYTE,
+ NULL);
+ pboOffsets[pboIdx] = screenPos.x * 4 + screenPos.y * shadeWidth * 4;
int nextPbo = (pboIdx + 1) % numPbos;
if (i >= numPbos - 1) {
int nextPbo = (pboIdx + 1) % numPbos;
if (i >= numPbos - 1) {