void GLBufferObject::Clear( GLenum internalformat, GLenum format, GLenum type, const void* data ) { Bind(); glClearBufferData(target, internalformat, format, type, data); Unbind(); }
PIGLIT_GL_TEST_CONFIG_END void piglit_init(int argc, char **argv) { bool pass = true; const int buffer_size = (1<<20) - 4; unsigned int buffer; static const char *const data_zero = "\x00\x00\x00\x00\x00\x00\x00\x00"; piglit_require_extension("GL_ARB_clear_buffer_object"); glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, buffer_size, NULL, GL_STREAM_READ); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glClearBufferData(GL_ARRAY_BUFFER, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT, data_zero); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &buffer); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglClearBufferData(JNIEnv *__env, jclass clazz, jint target, jint internalformat, jint format, jint type, jlong dataAddress, jlong __functionAddress) { const GLvoid *data = (const GLvoid *)(intptr_t)dataAddress; glClearBufferDataPROC glClearBufferData = (glClearBufferDataPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) glClearBufferData(target, internalformat, format, type, data); }
EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglClearBufferData__IIIIJ(JNIEnv *__env, jclass clazz, jint target, jint internalformat, jint format, jint type, jlong dataAddress) { glClearBufferDataPROC glClearBufferData = (glClearBufferDataPROC)tlsGetFunction(870); intptr_t data = (intptr_t)dataAddress; UNUSED_PARAM(clazz) glClearBufferData(target, internalformat, format, type, data); }
void BufferObject::clear(uint32_t bufferTarget, uint32_t internalFormat, uint32_t format, uint32_t type, const uint8_t* data) { #if defined(GL_ARB_clear_buffer_object) bind(bufferTarget); glClearBufferData(bufferTarget, internalFormat, format, type, data); unbind(bufferTarget); //glClearNamedBufferDataEXT(bufferId, internalFormat, format, type, data); #else WARN("BufferObject::clear not supported!"); #endif }
void Buffer::clearData(GLenum internalformat, GLenum format, GLenum type, const void* data) { if (m_directStateAccess) { glClearNamedBufferDataEXT(m_id, internalformat, format, type, data); CheckGLError(); } else { bind(); glClearBufferData(m_target, internalformat, format, type, data); CheckGLError(); } }
PIGLIT_GL_TEST_CONFIG_END void piglit_init(int argc, char **argv) { bool pass = true; const int buffer_size = 1<<20; unsigned int buffer; static const char *const data_zero = "\x00\x00\x00\x00"; static const char *const data_init = "\xff\xff\xff\xff" "\xff\xff\xff\xff" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x55\x55\x55\x55" "\x55\x55\x55\x55" "\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa" "\xff\x00\xff\x00" "\xff\x00\xff\x00" "\x00\xff\x00\xff" "\x00\xff\x00\xff" "\x91\xcc\x45\x36" "\xd3\xe4\xe3\x5b" "\x79\x1e\x21\x39" "\xa8\xfa\x69\x6a"; piglit_require_extension("GL_ARB_clear_buffer_object"); glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, buffer_size, NULL, GL_STREAM_READ); fill_array_buffer(64, data_init); glClearBufferData(GL_ARRAY_BUFFER, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, NULL); pass = check_array_buffer_data(4, data_zero) && pass; glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &buffer); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
PIGLIT_GL_TEST_CONFIG_END void piglit_init(int argc, char **argv) { bool pass = true; static const char *const data_zero = "\x00\x00\x00\x00"; piglit_require_extension("GL_ARB_clear_buffer_object"); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glClearBufferData(GL_ARRAY_BUFFER, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, data_zero); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
static bool test_format(const int i) { static const char *const data_7f = "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f" "\x7f\x7f\x7f\x7f"; static const char *const data_init = "\xff\xff\xff\xff" "\xff\xff\xff\xff" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x55\x55\x55\x55" "\x55\x55\x55\x55" "\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa" "\xff\x00\xff\x00" "\xff\x00\xff\x00" "\x00\xff\x00\xff" "\x00\xff\x00\xff" "\x91\xcc\x45\x36" "\xd3\xe4\xe3\x5b" "\x79\x1e\x21\x39" "\xa8\xfa\x69\x6a"; if (piglit_is_core_profile && !formats[i].core_profile) return true; /* All required extensions are included in GL 3.0. */ if (piglit_get_gl_version() < 30) { int j; for (j = 0; j < 3; ++j) if (formats[i].ext[j]) if (!piglit_is_extension_supported( formats[i].ext[j])) return true; } printf("Testing %s... ", piglit_get_gl_enum_name(formats[i].internal_format)); fill_array_buffer(64, data_init); glClearBufferData(GL_ARRAY_BUFFER, formats[i].internal_format, formats[i].format, formats[i].type, data_7f); if (!piglit_check_gl_error(GL_NO_ERROR) || !check_array_buffer_data(formats[i].size, data_7f)) { printf("Failed!\n"); return false; } printf("Passed.\n"); return true; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglClearBufferData(JNIEnv *env, jclass clazz, jint target, jint internalformat, jint format, jint type, jlong data, jlong function_pointer) { const GLvoid *data_address = (const GLvoid *)(intptr_t)data; glClearBufferDataPROC glClearBufferData = (glClearBufferDataPROC)((intptr_t)function_pointer); glClearBufferData(target, internalformat, format, type, data_address); }
RadixSort::RadixSort (GLuint _blocksize, GLuint _numblocks, const glm::ivec3 &gridsize) : blocksize (_blocksize), numblocks (_numblocks) { std::stringstream stream; stream << "const vec3 GRID_SIZE = vec3 (" << gridsize.x << ", " << gridsize.y << ", " << gridsize.z << ");" << std::endl << "const ivec3 GRID_HASHWEIGHTS = ivec3 (1, " << gridsize.x * gridsize.z << ", " << gridsize.x << ");" << std::endl << "#define BLOCKSIZE " << blocksize << std::endl << "#define HALFBLOCKSIZE " << (blocksize / 2) << std::endl; if (blocksize & 1) throw std::logic_error ("The block size for sorting has to be even."); numbits = count_sortbits (uint64_t (gridsize.x) * uint64_t (gridsize.y) * uint64_t (gridsize.z) - 1); // load shaders counting.CompileShader (GL_COMPUTE_SHADER, "shaders/radixsort/counting.glsl", stream.str ()); counting.Link (); blockscan.CompileShader (GL_COMPUTE_SHADER, "shaders/radixsort/blockscan.glsl", stream.str ()); blockscan.Link (); globalsort.CompileShader (GL_COMPUTE_SHADER, "shaders/radixsort/globalsort.glsl", stream.str ()); globalsort.Link (); addblocksum.CompileShader (GL_COMPUTE_SHADER, "shaders/radixsort/addblocksum.glsl", stream.str ()); addblocksum.Link (); // create buffer objects glGenBuffers (3, buffers); // allocate input buffer glBindBuffer (GL_SHADER_STORAGE_BUFFER, buffer); glBufferData (GL_SHADER_STORAGE_BUFFER, sizeof (glm::vec4) * blocksize * numblocks, NULL, GL_DYNAMIC_COPY); // allocate prefix sum buffer glBindBuffer (GL_SHADER_STORAGE_BUFFER, prefixsums); glBufferData (GL_SHADER_STORAGE_BUFFER, sizeof (uint32_t) * blocksize * numblocks, NULL, GL_DYNAMIC_COPY); // create block sum buffers uint32_t numblocksums = 4 * numblocks; { int n = ceil (log (((numblocksums + blocksize - 1) / blocksize) * blocksize) / log (blocksize)); n++; blocksums.resize (n); glGenBuffers (n, &blocksums[0]); } for (int i = 0; i < blocksums.size (); i++) { GLuint &blocksum = blocksums[i]; // allocate a single block sum buffer glBindBuffer (GL_SHADER_STORAGE_BUFFER, blocksum); numblocksums = ((numblocksums + blocksize - 1) / blocksize) * blocksize; if (numblocksums < 1) numblocksums = 1; glBufferData (GL_SHADER_STORAGE_BUFFER, sizeof (uint32_t) * numblocksums, NULL, GL_DYNAMIC_COPY); numblocksums /= blocksize; } // allocate output buffer glBindBuffer (GL_SHADER_STORAGE_BUFFER, result); glBufferData (GL_SHADER_STORAGE_BUFFER, sizeof (glm::vec4) * blocksize * numblocks, NULL, GL_DYNAMIC_COPY); // pass block sum offsets to the shader programs glm::uvec4 blocksumoffsets (0, numblocks, numblocks * 2, numblocks * 3); glProgramUniform4uiv (counting.get (), counting.GetUniformLocation ("blocksumoffsets"), 1, glm::value_ptr (blocksumoffsets)); glProgramUniform4uiv (globalsort.get (), globalsort.GetUniformLocation ("blocksumoffsets"), 1, glm::value_ptr (blocksumoffsets)); // query uniform locations counting_bitshift = counting.GetUniformLocation ("bitshift"); globalsort_bitshift = globalsort.GetUniformLocation ("bitshift"); // clear block sum buffers for (int i = 0; i < blocksums.size (); i++) { unsigned int &blocksum = blocksums[i]; glBindBuffer (GL_SHADER_STORAGE_BUFFER, blocksum); glClearBufferData (GL_SHADER_STORAGE_BUFFER, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT, NULL); } }