void GLSink::draw()
{
    unsigned int        uiBufferIdx;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Update stream 
    glBindTexture(GL_TEXTURE_2D, m_uiTexture);

    FrameData* pFrame = NULL;

    // block until new frame is available
    uiBufferIdx = m_pSyncBuffer->getBufferForReading((void*&)pFrame);

    m_pInputBuffer->bindBuffer(pFrame->uiBufferId);

    if (m_bUseP2P)
    {
        // This is a non-blocking call, but the GPU is instructed to wait until
        // the marker value is pFrame->uiTransferId before processing the subsequent
        // instructions
        m_pInputBuffer->waitMarker(pFrame->uiTransferId);
    }

    // Copy bus addressable buffer into texture object
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_uiTextureWidth, m_uiTextureHeight, m_nExtFormat, m_nType, NULL);

    // Insert fence to determine when the buffer was copied into the texture
    // and we can release the buffer
    GLsync Fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

    // Draw quad with mapped texture
    glPushMatrix();
   
    // Scale quad to the AR of the incoming texture
    glScalef(m_fAspectRatio, 1.0f, 1.0f);
   
    // Draw quad with mapped texture
    glBindBuffer(GL_ARRAY_BUFFER, m_uiQuad);
    glDrawArrays(GL_QUADS, 0, 4);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    glPopMatrix();

    glBindTexture(GL_TEXTURE_2D, 0);

    // Wait until buffer is no longer needed and release it
    if (glIsSync(Fence))
    {
        glClientWaitSync(Fence, GL_SYNC_FLUSH_COMMANDS_BIT, OneSecond);
        glDeleteSync(Fence);
    }

    m_pSyncBuffer->releaseReadBuffer();
}
Beispiel #2
0
void GLSink::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Update stream 
    glBindTexture(GL_TEXTURE_2D, m_uiTexture);

    FrameData* pFrame = NULL;

    // block until new frame is available
    m_uiBufferIdx = m_pInputBuffer->getBufferForReading((void*&)pFrame);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pUnPackBuffer[m_uiBufferIdx]);

    glWaitMarkerAMD(m_pUnPackBuffer[m_uiBufferIdx], pFrame->uiTransferId);

    // Copy pinned mem to texture
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_uiTextureWidth, m_uiTextureHeight, m_nExtFormat, m_nType, NULL);

    // Insert fence to determine when we can release the buffer
    GLsync Fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

    glPushMatrix();
   
    // Scale quad to the AR of the incoming texture
    glScalef(m_fAspectRatio, 1.0f, 1.0f);
   
    // Draw quad with mapped texture
    glBindBuffer(GL_ARRAY_BUFFER, m_uiQuad);
    glDrawArrays(GL_QUADS, 0, 4);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    glPopMatrix();

    glBindTexture(GL_TEXTURE_2D, 0);

    if (glIsSync(Fence))
    {
        glClientWaitSync(Fence, GL_SYNC_FLUSH_COMMANDS_BIT, OneSecond);
        glDeleteSync(Fence);
    }

    m_pInputBuffer->releaseReadBuffer();
}
Beispiel #3
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	GLenum wait_val;
	GLsync sync;

	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_TRIANGLES);
	glColor3f(.8,0,0);
	glVertex3f(-0.9, -0.9, -30.0);
	glColor3f(0,.9,0);
	glVertex3f( 0.9, -0.9, -30.0);
	glColor3f(0,0,.7);
	glVertex3f( 0.0,  0.9, -30.0);
	glEnd();

	glGetError();

	sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
	FAIL_ON_ERROR("glFenceSync");

	if (!glIsSync(sync)) {
		fprintf(stderr, "IsSync(%p) failed\n", sync);
		pass = GL_FALSE;
		goto done;
	}
	FAIL_ON_ERROR("glIsSync");

	if (! test_GetSynciv(sync, GL_SYNC_CONDITION,
			     GL_SYNC_GPU_COMMANDS_COMPLETE)) {
		pass = GL_FALSE;
		goto done;
	}

	if (! test_GetSynciv(sync, GL_SYNC_FLAGS, 0)) {
		pass = GL_FALSE;
		goto done;
	}

	glFinish();

	/* After the glFinish, the sync *must* be signaled!
	 */
	if (! test_GetSynciv(sync, GL_SYNC_STATUS, GL_SIGNALED)) {
		pass = GL_FALSE;
		goto done;
	}


	/* Since the sync has already been signaled, the wait should return
	 * GL_ALREADY_SIGNALED.
	 */
	wait_val = glClientWaitSync(sync, 0, 1);
	FAIL_ON_ERROR("glClientWaitSync");

	if (wait_val != GL_ALREADY_SIGNALED) {
		fprintf(stderr, "glClientWaitSync expected 0x%08x, "
			"got 0x%08x\n", GL_ALREADY_SIGNALED, wait_val);
		pass = GL_FALSE;
	}

	glDeleteSync(sync);
	FAIL_ON_ERROR("glDeleteSync");

done:
	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL32_nglIsSync(JNIEnv *env, jclass clazz, jlong sync, jlong function_pointer) {
	glIsSyncPROC glIsSync = (glIsSyncPROC)((intptr_t)function_pointer);
	GLboolean __result = glIsSync((GLsync)(intptr_t)sync);
	return __result;
}
Beispiel #5
0
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL32C_nglIsSync(JNIEnv *__env, jclass clazz, jlong syncAddress) {
    glIsSyncPROC glIsSync = (glIsSyncPROC)tlsGetFunction(659);
    intptr_t sync = (intptr_t)syncAddress;
    UNUSED_PARAM(clazz)
    return (jboolean)glIsSync(sync);
}