void queryTranfer() { while(!ReadPixelBufferLive.empty()) { transfer* Transfer = ReadPixelBufferLive.front(); GLint Status = 0; GLsizei Length = 0; glGetSynciv(Transfer->Fence, GL_SYNC_STATUS, 4, &Length, &Status); if(Status == GL_SIGNALED) { glBindBuffer(GL_PIXEL_PACK_BUFFER, Transfer->Buffer); void* Data = glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 640 * 480 * 4, GL_MAP_READ_BIT); memcpy(&ReadPixelData[0], Data, 640 * 480 * 4); glUnmapBuffer(GL_PIXEL_PACK_BUFFER); ReadPixelBufferFree.push(Transfer); ReadPixelBufferLive.pop(); } else { break; } } }
static void Screenshot( const ScreenshotCommand &cmd ) { //NOTE: glGetSynciv never returns GL_SIGNALED on Mac // see also: chromium src/ui/gl/gl_fence.cc revision 213908 -> 213907 // https://src.chromium.org/viewvc/chrome/trunk/src/ui/gl/gl_fence.cc?r1=213908&r2=213907 // device details: Yosemite 10.10.3, Intel HD Graphics 5000 #if defined(XS_OS_MAC) GLint res = glClientWaitSync( cmd.sync, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED ); SDL_assert( res != GL_TIMEOUT_EXPIRED ); #else GLint signalled = GL_UNSIGNALED; do { glGetSynciv( cmd.sync, GL_SYNC_STATUS, 1, nullptr, &signalled ); } while ( signalled != GL_SIGNALED ); #endif glDeleteSync( cmd.sync ); glBindBuffer( GL_PIXEL_PACK_BUFFER, cmd.pbo ); void *data = glMapBuffer( GL_PIXEL_PACK_BUFFER, GL_READ_ONLY ); console.Print( PrintLevel::Normal, "Writing screenshot %s (%ix%i)...\n", cmd.name, cmd.width, cmd.height ); //TODO: strip alpha? WritePNG( cmd.name, reinterpret_cast<uint8_t *>( data ), cmd.width, cmd.height, 4 ); glUnmapBuffer( GL_PIXEL_PACK_BUFFER ); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL32C_nglGetSynciv__JIIJJ(JNIEnv *__env, jclass clazz, jlong syncAddress, jint pname, jint bufSize, jlong lengthAddress, jlong valuesAddress) { glGetSyncivPROC glGetSynciv = (glGetSyncivPROC)tlsGetFunction(665); intptr_t sync = (intptr_t)syncAddress; intptr_t length = (intptr_t)lengthAddress; intptr_t values = (intptr_t)valuesAddress; UNUSED_PARAM(clazz) glGetSynciv(sync, pname, bufSize, length, values); }
bool ready() const { if(!sync_) return true; GLsizei length = 0; int values[] = {0}; GL(glGetSynciv(sync_, GL_SYNC_STATUS, 1, &length, values)); return values[0] == GL_SIGNALED; }
GLboolean test_GetSynciv(GLsync sync, GLenum pname, GLint expect) { GLboolean pass = GL_TRUE; GLint val; GLsizei len; glGetSynciv(sync, pname, 1, & len, & val); FAIL_ON_ERROR("glGetSynciv"); if (len != 1) { fprintf(stderr, "glGetSynciv length of 0x%04x was %d\n", pname, len); pass = GL_FALSE; } else if (val != expect) { fprintf(stderr, "glGetSynciv of 0x%04x expected 0x%08x, " "got 0x%08x\n", pname, expect, val); pass = GL_FALSE; } done: return pass; }
void piglit_init(int argc, char **argv) { bool pass = true; GLsizei length = -5; GLint value; GLsync sync; if (piglit_get_gl_version() < 32) { piglit_require_extension("GL_ARB_sync"); } /* Start some rendering that will not end before this test finishes * in order to make sure the fence sync is still set to initial values */ piglit_draw_rect(-1, -1, 2, 2); /* Create a new fence sync */ sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); /* Test initialized as fence type */ glGetSynciv(sync, GL_OBJECT_TYPE, 1, &length, &value); if(length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if(value != GL_SYNC_FENCE) { printf("Expected GL_SYNC_FENCE but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized to given condition */ length = -5; glGetSynciv(sync, GL_SYNC_CONDITION, 1, &length, &value); if(length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if(value != GL_SYNC_GPU_COMMANDS_COMPLETE) { printf("Expected GL_SYNC_GPU_COMMANDS_COMPLETE but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized to unsignaled */ length = -5; glGetSynciv(sync, GL_SYNC_STATUS, 1, &length, &value); if(length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if(value != GL_UNSIGNALED) { printf("Expected GL_UNSIGNALED but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized with given flag */ length = -5; glGetSynciv(sync, GL_SYNC_FLAGS, 1, &length, &value); if(length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if(value != 0) { printf("Expected GL_SYNC_FLAGS == 0 but returned: %d\n", value); pass = false; } glDeleteSync(sync); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
void pmbstreaming_app::render(double currentTime) { static float lastTime = 0.0f; static int frames = 0; float nowTime = float(currentTime); int isSignaled; static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 0.0f }; static const GLfloat one[] = { 1.0f }; vmath::mat4 proj_matrix = vmath::perspective(60.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1800.0f); vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -3.0f) * vmath::rotate((float)currentTime * 43.75f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 17.75f, 0.0f, 0.0f, 1.0f) * vmath::rotate((float)currentTime * 35.3f, 1.0f, 0.0f, 0.0f); glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, black); glClearBufferfv(GL_DEPTH, 0, one); glUseProgram(program); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); if (mode == ONE_SYNC) { if (fence[0] != 0) { glGetSynciv(fence[0], GL_SYNC_STATUS, sizeof(int), nullptr, &isSignaled); stalled = isSignaled == GL_UNSIGNALED; glClientWaitSync(fence[0], 0, GL_TIMEOUT_IGNORED); glDeleteSync(fence[0]); } } else if (mode == RINGED_SYNC) { if (fence[sync_index] != 0) { glGetSynciv(fence[sync_index], GL_SYNC_STATUS, sizeof(int), nullptr, &isSignaled); stalled = isSignaled == GL_UNSIGNALED; glClientWaitSync(fence[sync_index], 0, GL_TIMEOUT_IGNORED); glDeleteSync(fence[sync_index]); } } vs_uniforms[sync_index].modelview = mv_matrix; vs_uniforms[sync_index].projection = proj_matrix; if (mode == RINGED_SYNC) { object.render(1, sync_index); } else { object.render(1, 0); } if (nowTime > (lastTime + 0.25f)) { fps = float(frames) / (nowTime - lastTime); frames = 0; lastTime = nowTime; } updateOverlay(); if (mode == FINISH) { glFinish(); stalled = true; } else if (mode == ONE_SYNC) { fence[0] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } else if (mode == RINGED_SYNC) { fence[sync_index] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } sync_index = (sync_index + 1) % CHUNK_COUNT; frames++; }
void Sync::get(const GLenum pname, const GLsizei bufsize, GLsizei * length, GLint * values) { glGetSynciv(m_sync, pname, bufsize, length, values); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL32_nglGetSynciv(JNIEnv *env, jclass clazz, jlong sync, jint pname, jint bufSize, jlong length, jlong values, jlong function_pointer) { GLsizei *length_address = (GLsizei *)(intptr_t)length; GLint *values_address = (GLint *)(intptr_t)values; glGetSyncivPROC glGetSynciv = (glGetSyncivPROC)((intptr_t)function_pointer); glGetSynciv((GLsync)(intptr_t)sync, pname, bufSize, length_address, values_address); }
void piglit_init(int argc, char **argv) { bool pass = true; GLsizei length = -5; GLint value; GLsync sync; if (piglit_get_gl_version() < 32) { piglit_require_extension("GL_ARB_sync"); } /* Create a new fence sync */ sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); /* Test initialized as fence type */ glGetSynciv(sync, GL_OBJECT_TYPE, 1, &length, &value); if (length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if (value != GL_SYNC_FENCE) { printf("Expected GL_SYNC_FENCE but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized to given condition */ length = -5; glGetSynciv(sync, GL_SYNC_CONDITION, 1, &length, &value); if (length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if (value != GL_SYNC_GPU_COMMANDS_COMPLETE) { printf("Expected GL_SYNC_GPU_COMMANDS_COMPLETE but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized to unsignaled */ length = -5; glGetSynciv(sync, GL_SYNC_STATUS, 1, &length, &value); if (length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } /* We can't test for just GL_UNSIGNALED here, since the driver * may have actually completed any previous rendering (or, in * our case, no rendering at all) already. */ if (value != GL_UNSIGNALED && value != GL_SIGNALED) { printf("Expected GL_UNSIGNALED or GL_SIGNALED but returned: %s\n", piglit_get_gl_enum_name(value)); pass = false; } /* Test initialized with given flag */ length = -5; glGetSynciv(sync, GL_SYNC_FLAGS, 1, &length, &value); if (length != 1) { printf("length should be 1 but incorrectly returned: %d\n", length); pass = false; } if (value != 0) { printf("Expected GL_SYNC_FLAGS == 0 but returned: %d\n", value); pass = false; } glDeleteSync(sync); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }