Skip to content

Instantly share code, notes, and snippets.

@tgsstdio
Last active May 23, 2019 17:46
Show Gist options
  • Save tgsstdio/28b9e5c898d2b1b64423ab942ebb48c4 to your computer and use it in GitHub Desktop.
Save tgsstdio/28b9e5c898d2b1b64423ab942ebb48c4 to your computer and use it in GitHub Desktop.
vkInvalidateMappedBufferRange => glFlushMappedBuffer
if function.name == 'glFlushMappedBufferRange':
print ' GLvoid *map = NULL;'
print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
print ' if (map && length > 0) {'
self.emit_memcpy('(const char *)map + offset', 'length')
print ' }'
if function.name == 'glFlushMappedBufferRangeAPPLE':
print ' GLvoid *map = NULL;'
print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
print ' if (map && size > 0) {'
self.emit_memcpy('(const char *)map + offset', 'size')
print ' }'
if function.name == 'glFlushMappedNamedBufferRangeEXT':
print ' GLvoid *map = NULL;'
print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
print ' if (map && length > 0) {'
self.emit_memcpy('(const char *)map + offset', 'length')
print ' }'
/*
* Copyright 2010 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*
* GL support. See http://kripken.github.io/emscripten-site/docs/porting/multimedia_and_graphics/OpenGL-support.html
* for current status.
*/
$emscriptenWebGLValidateMapBufferTarget: function(target) {
switch (target) {
case 0x8892: // GL_ARRAY_BUFFER
case 0x8893: // GL_ELEMENT_ARRAY_BUFFER
case 0x8F36: // GL_COPY_READ_BUFFER
case 0x8F37: // GL_COPY_WRITE_BUFFER
case 0x88EB: // GL_PIXEL_PACK_BUFFER
case 0x88EC: // GL_PIXEL_UNPACK_BUFFER
case 0x8C2A: // GL_TEXTURE_BUFFER
case 0x8C8E: // GL_TRANSFORM_FEEDBACK_BUFFER
case 0x8A11: // GL_UNIFORM_BUFFER
return true;
default:
return false;
}
},
glFlushMappedBufferRange: function(target, offset, length) {
if (!emscriptenWebGLValidateMapBufferTarget(target)) {
GL.recordError(0x0500/*GL_INVALID_ENUM*/);
err('GL_INVALID_ENUM in glFlushMappedBufferRange');
return;
}
var mapping = GL.mappedBuffers[emscriptenWebGLGetBufferBinding(target)];
if (!mapping) {
GL.recordError(0x0502 /* GL_INVALID_OPERATION */);
Module.printError('buffer was never mapped in glFlushMappedBufferRange');
return;
}
if (!(mapping.access & 0x10)) {
GL.recordError(0x0502 /* GL_INVALID_OPERATION */);
Module.printError('buffer was not mapped with GL_MAP_FLUSH_EXPLICIT_BIT in glFlushMappedBufferRange');
return;
}
if (offset < 0 || length < 0 || offset + length > mapping.length) {
GL.recordError(0x0501 /* GL_INVALID_VALUE */);
Module.printError('invalid range in glFlushMappedBufferRange');
return;
}
GLctx.bufferSubData(
target,
mapping.offset,
HEAPU8.subarray(mapping.mem + offset, mapping.mem + offset + length));
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment