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)));
}
}
#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]);
- 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);
#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); */
+ 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) {