Exemplo n.º 1
0
void recursion( float startX,
				float startY,
				float startZ,
				float startW)
{
	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,streamoutBufffer[0]);

	glBeginTransformFeedback(GL_POINTS);
	glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, outputQuery);
	glPointSize(1);
	glBegin(GL_POINTS);
	glVertex4f(startX, startY, startZ, startW);
	glEnd();
	glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);

	glEndTransformFeedback();

	GLint outPointCount = 0;
	GLint succ = 0;

	while(!succ)
		glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT_AVAILABLE, &succ);
	glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT, &outPointCount);
	//std::cout << "points written: " << outPointCount << std::endl;
	succ = 0;

	glEnableClientState(GL_VERTEX_ARRAY);
	int bb = 0;
	while(outPointCount > 0)
	{
		glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,streamoutBufffer[(bb+1)%2]);
		glBeginTransformFeedback(GL_POINTS);

		glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, outputQuery);

		glBindBufferARB(GL_ARRAY_BUFFER_ARB, streamoutBufffer[bb]);
		glVertexPointer(4,GL_FLOAT,0,NULL);
		glDrawArrays(GL_POINTS, 0, outPointCount);

		glEndTransformFeedback();

		glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
		while(!succ)
			glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT_AVAILABLE, &succ);
		glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT, &outPointCount);
		succ = 0;

		bb = (bb + 1) % 2;
	}
	glDisableClientState(GL_VERTEX_ARRAY);
}
Exemplo n.º 2
0
float stop_timing()
{
	glEndQuery(GL_TIME_ELAPSED);

	GLint available = GL_FALSE;
	while (available == GL_FALSE)
		glGetQueryObjectiv(gTimer, GL_QUERY_RESULT_AVAILABLE, &available);

	GLint result;
	glGetQueryObjectiv(gTimer, GL_QUERY_RESULT, &result);

	float timeElapsed = result / (1000.0f * 1000.0f * 1000.0f);
	return timeElapsed;
}
Exemplo n.º 3
0
float CoronaVisibility (int nQuery)
{
	GLuint	nSamples = 0;
	GLint		bAvailable = 0;
	int		nAttempts = 2;
	float		fIntensity;
#if DBG
	GLint		nError;
#endif

if (! (ogl.m_states.bOcclusionQuery && nQuery) || (CoronaStyle () != 1))
	return 1;
if (! (gameStates.render.bQueryCoronas || gameData.render.lights.coronaSamples [nQuery - 1]))
	return 0;
for (;;) {
	glGetQueryObjectiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_AVAILABLE_ARB, &bAvailable);
	if (glGetError ()) {
#if DBG
		glGetQueryObjectiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_AVAILABLE_ARB, &bAvailable);
		if ((nError = glGetError ()))
#endif
			return 0;
		}
	if (bAvailable)
		break;
	if (!--nAttempts)
		return 0;
	G3_SLEEP (1);
	};
glGetQueryObjectuiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_ARB, &nSamples);
if (glGetError ())
	return 0;
if (gameStates.render.bQueryCoronas == 1) {
#if DBG
	if (!nSamples) {
		GLint nBits;
		glGetQueryiv (GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &nBits);
		glGetQueryObjectuiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_ARB, &nSamples);
		}
#endif
	return (float) (gameData.render.lights.coronaSamples [nQuery - 1] = nSamples);
	}
fIntensity = (float) nSamples / (float) gameData.render.lights.coronaSamples [nQuery - 1];
#if DBG
if (fIntensity > 1)
	fIntensity = 1;
#endif
return (fIntensity > 1) ? 1 : (float) sqrt (fIntensity);
}
Exemplo n.º 4
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLuint ids[10];
	GLint param;

	/* Throw some invalid inputs at glCreateQueries */

	/* n is negative */
	glCreateQueries(GL_SAMPLES_PASSED, -1, ids);
	SUBTEST(GL_INVALID_VALUE, pass, "n < 0");

	/* invalid target */
	glCreateQueries(GL_RGBA, 0, ids);
	SUBTEST(GL_INVALID_ENUM, pass, "invalid target");

	/* Throw some valid inputs at glCreateQueries. */

	/* n is zero */
	glCreateQueries(GL_SAMPLES_PASSED, 0, NULL);
	SUBTEST(GL_NO_ERROR, pass, "n == 0");

	/* n is more than 1 */
	glCreateQueries(GL_SAMPLES_PASSED, 10, ids);
	SUBTEST(GL_NO_ERROR, pass, "n > 1");

	/* test the default state of dsa-created query objects */
	SUBTESTCONDITION(glIsQuery(ids[2]), pass, "IsQuery()");
	glGetQueryObjectiv(ids[2], GL_QUERY_RESULT_AVAILABLE, &param);
	piglit_check_gl_error(GL_NO_ERROR);
	SUBTESTCONDITION(param == GL_TRUE, pass,
			 "default AVAILABLE state(%d) == TRUE", param);
	glGetQueryObjectiv(ids[2], GL_QUERY_RESULT, &param);
	piglit_check_gl_error(GL_NO_ERROR);
	SUBTESTCONDITION(param == 0, pass, "default RESULT(%d) == 0", param);

	/* test the target */
	glGetQueryObjectiv(ids[2], GL_QUERY_TARGET, &param);
	piglit_check_gl_error(GL_NO_ERROR);
	SUBTESTCONDITION(param == GL_SAMPLES_PASSED, pass, "TARGET(%s) == "
			 "GL_SAMPLES_PASSED", piglit_get_gl_enum_name(param));

	/* clean up */
	glDeleteQueries(10, ids);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemplo n.º 5
0
int stopGPUTimer(GPUtimer* timer, float* times, int maxTimes)
{
//	NVG_NOTUSED(times);
//	NVG_NOTUSED(maxTimes);
	GLint available = 1;
	int n = 0;
	if (!timer->supported)
		return 0;
    
	glEndQuery(GL_TIME_ELAPSED);
	while (available && timer->ret <= timer->cur) {
		// check for results if there are any
		glGetQueryObjectiv(timer->queries[timer->ret % GPU_QUERY_COUNT], GL_QUERY_RESULT_AVAILABLE, &available);
		if (available) {
            GLuint64 timeElapsed = 0;
            glGetQueryObjectui64v(timer->queries[timer->ret % GPU_QUERY_COUNT], GL_QUERY_RESULT, &timeElapsed);
            timer->ret++;
            if (n < maxTimes) {
                times[n] = (float)((double)timeElapsed * 1e-9);
                n++;
            }
		}
	}
	return n;
}
	GLint GL3OcclusionQueryProvider::get_result() const
	{
		OpenGL::set_active(gc_provider);
		GLint result;
		glGetQueryObjectiv(handle, GL_QUERY_RESULT, &result);
		return result;
	}
Exemplo n.º 7
0
enum piglit_result
piglit_display(void)
{
	int test_pass = 1;
	GLuint query;
	GLint result;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* Guaranteed to be random, see: http://xkcd.com/221
	 */
	query = 3243;
	test_pass &= is_query_matches(query, 0, "with un-generated name");

	glGenQueries(1, &query);
	test_pass &= is_query_matches(query, 0, "after glGenQueries");

	glQueryCounter(query, GL_TIMESTAMP);
	test_pass &= is_query_matches(query, 1, "after glQueryCounter");

	/* Do a little drawing at least */
	glColor3ub(0x00, 0xff, 0x00);
	piglit_draw_rect(0, 0, piglit_width, piglit_height);

	glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);
	test_pass &= is_query_matches(query, 1, "after glGetQueryObjectiv");

	glDeleteQueries(1, &query);
	test_pass &= is_query_matches(query, 0, "after glDeleteQueries");

	piglit_present_results();

	return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemplo n.º 8
0
bool GPUTimer::updateResults()
{
	if( !glExt::ARB_timer_query ) return false;
	
	if( _numQueries == 0 )
	{
		_time = 0;
		return true;
	}
	
	// Make sure that last query is available
	GLint available;
	glGetQueryObjectiv( _queryPool[_numQueries * 2 - 1], GL_QUERY_RESULT_AVAILABLE, &available );
	if( !available ) return false;
	
	//  Accumulate time
	GLuint64 timeStart = 0, timeEnd = 0, timeAccum = 0;
	for( uint32 i = 0; i < _numQueries; ++i )
	{
		glGetQueryObjectui64v( _queryPool[i * 2], GL_QUERY_RESULT, &timeStart );
		glGetQueryObjectui64v( _queryPool[i * 2 + 1], GL_QUERY_RESULT, &timeEnd );
		timeAccum += timeEnd - timeStart;
	}
	
	_time = (float)((double)timeAccum / 1000000.0);
	return true;
}
	bool GL3OcclusionQueryProvider::is_result_ready() const
	{
		OpenGL::set_active(gc_provider);
		int available;
		glGetQueryObjectiv(handle, GL_QUERY_RESULT_AVAILABLE, &available);
		return (available != 0);
	}
Exemplo n.º 10
0
	bool GLEventQuery::isReady() const
	{
		GLint done = 0;
		glGetQueryObjectiv(mQueryObj, GL_QUERY_RESULT_AVAILABLE, &done);

		return done == GL_TRUE;
	}
Exemplo n.º 11
0
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
	GLuint oq[3];
	GLint result[3] = {2, 2, 2};
	bool pass = true;
	int i;

	glEnable(GL_DEPTH_TEST);

	glClearDepth(1.0);
	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glGenQueries(3, oq);
	glDeleteQueries(3, oq);

	glColor4f(0.0, 1.0, 0.0, 0.0);
	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]);
	piglit_draw_rect_z(0.5, -1, -1, 2, 2);
	glEndQuery(GL_ANY_SAMPLES_PASSED);

	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]);
	glEndQuery(GL_ANY_SAMPLES_PASSED);

	glColor4f(1.0, 0.0, 0.0, 0.0);
	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[2]);
	piglit_draw_rect_z(0.75, -0.5, -0.5, 1.0, 1.0);
	glEndQuery(GL_ANY_SAMPLES_PASSED);

	piglit_present_results();

	for (i = 0; i < 3; i++) {
		glGetQueryObjectiv(oq[i], GL_QUERY_RESULT, &result[i]);
	}

	if (result[0] != GL_TRUE) {
		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with passed fragments returned %d\n",
			result[0]);
		pass = false;
	}

	if (result[1] != GL_FALSE) {
		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with no rendering returned %d\n",
			result[1]);
		pass = false;
	}

	if (result[2] != GL_FALSE) {
		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with occluded rendering returned %d\n",
			result[2]);
		pass = false;
	}

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemplo n.º 12
0
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
    GLuint active, inactive;
    GLint elapsed;

    /* Generate and start a query. */
    glGenQueries(1, &active);

    glBeginQuery(GL_SAMPLES_PASSED, active);

    printf ("Testing Gen/Delete of query while another query is active.\n");
    {
        /* While first query is active, gen a new one. */
        glGenQueries(1, &inactive);

        if (!piglit_check_gl_error(GL_NO_ERROR))
            return PIGLIT_FAIL;

        /* Delete the inactive query. */
        glDeleteQueries(1, &inactive);

        if (!piglit_check_gl_error(GL_NO_ERROR))
            return PIGLIT_FAIL;

        /* Finish and get result from active query. */
        glEndQuery(GL_SAMPLES_PASSED);

        glGetQueryObjectiv(active, GL_QUERY_RESULT, &elapsed);
    }

    printf ("Testing Delete of currently-active query.\n");
    {
        /* Finally, ensure that an active query can be deleted. */
        glGenQueries(1, &active);

        glBeginQuery(GL_SAMPLES_PASSED, active);

        glDeleteQueries(1, &active);

        if (!piglit_check_gl_error(GL_NO_ERROR))
            return PIGLIT_FAIL;
    }

    printf ("Testing that glEndQuery on deleted query (expecting error).\n");
    {
        /* And ensure that we get an error if we try to end a deleted
         * query. */
        glEndQuery(GL_SAMPLES_PASSED);

        if (!piglit_check_gl_error(GL_INVALID_OPERATION))
            return PIGLIT_FAIL;
    }

    return PIGLIT_PASS;
}
Exemplo n.º 13
0
static void SCE_ROcclusionQueryCallback (int begin)
{
    if (begin)
        glBeginQuery (GL_SAMPLES_PASSED, queryid);
    else {
        glEndQuery (GL_SAMPLES_PASSED);
        glGetQueryObjectiv (queryid, GL_QUERY_RESULT, &drawpixels);
    }
}
Exemplo n.º 14
0
std::vector<int> CDecalsDrawerGL4::UpdateOverlap_CheckQueries()
{
	// query the results of the last issued test (if any pixels were rendered for the decal)
	std::vector<int> candidatesForRemoval;
	candidatesForRemoval.reserve(waitingOverlapGlQueries.size());
	for (auto& p: waitingOverlapGlQueries) {
		GLint rendered = GL_FALSE;
		glGetQueryObjectiv(p.second, GL_QUERY_RESULT, &rendered);
		glDeleteQueries(1, &p.second);
		if (rendered == GL_FALSE) {
			candidatesForRemoval.push_back(p.first);
		}
	}
	waitingOverlapGlQueries.clear();

	// no candidates left, restart with stage 0
	if (candidatesForRemoval.empty()) {
		overlapStage = 0;
		return candidatesForRemoval;
	}

	//FIXME comment
	auto sortBeginIt = candidatesForRemoval.begin();
	auto sortEndIt = candidatesForRemoval.end();
	while (sortBeginIt != sortEndIt) {
		std::sort(sortBeginIt, sortEndIt, [&](const int& idx1, const int& idx2){
			return decals[idx1].generation < decals[idx2].generation;
		});
		sortEndIt = std::partition(sortBeginIt+1, sortEndIt, [&](const int& idx){
			return !Overlap(decals[*sortBeginIt], decals[idx]);
		});
		++sortBeginIt;
	}
	auto eraseIt = sortEndIt;

	// free one decal (+ remove it from the overlap texture)
	int freed = 0;
	CVertexArray* va = GetVertexArray();
	glStencilFunc(GL_ALWAYS, 0, 0xFF);
	glStencilOp(GL_DECR_WRAP, GL_DECR_WRAP, GL_DECR_WRAP);
	va->Initialize();
	for (auto it = candidatesForRemoval.begin(); it != eraseIt; ++it) {
		const int curIndex = *it;
		const Decal& d = decals[curIndex];
		DRAW_DECAL(va, &d);
		FreeDecal(curIndex);
		freed++;
	}
	va->DrawArray2dT(GL_QUADS);
	candidatesForRemoval.erase(candidatesForRemoval.begin(), eraseIt);

	//FIXME
	LOG_L(L_ERROR, "Query freed: %i of %i (decals:%i groups:%i)", freed, int(candidatesForRemoval.size()), int(decals.size() - freeIds.size()), int(groups.size()));

	// overlap texture changed, so need to retest the others
	return candidatesForRemoval;
}
Exemplo n.º 15
0
	bool GpuQuery::IsResultAvailable() const
	{
		Context::EnsureContext();

		GLint available;
		glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available);

		return available == GL_TRUE;
	}
Exemplo n.º 16
0
	bool GLTimerQuery::isReady() const
	{
		if (!mEndIssued)
			return false;

		GLint done = 0;
		glGetQueryObjectiv(mQueryEndObj, GL_QUERY_RESULT_AVAILABLE, &done);

		return done == GL_TRUE;
	}
Exemplo n.º 17
0
PIGLIT_GL_TEST_CONFIG_END


static bool
run_test(bool scissor_clear)
{
	GLuint query;
	GLint result = -1;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glGenQueries(1, &query);

	glBeginQuery(GL_SAMPLES_PASSED, query);

	/* Render 64 pixels. This should affect the query */
	piglit_draw_rect(0, 0, 8, 8);

	/* Clear the framebuffer. This shouldn't affect the query */
	glClearColor(0.0, 0.0, 1.0, 0.0);
	if (scissor_clear) {
		glScissor(0, 0, piglit_width / 2, piglit_height / 2);
		glEnable(GL_SCISSOR_TEST);
	}
	glClear(GL_COLOR_BUFFER_BIT);
	if (scissor_clear) {
		glDisable(GL_SCISSOR_TEST);
	}

	/* Render another 64 pixels. This should continue adding to
	 * the query */
	piglit_draw_rect(4, 0, 8, 8);

	glEndQuery(GL_SAMPLES_PASSED);

	glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);

	glDeleteQueries(1, &query);

	piglit_present_results();

	if (result != 128) {
		printf("Failure: \n");
		printf("  Occlusion query resulted in %d samples "
		       "(expected 128)\n",
		       result);
		printf("  Scissor enabled? %s\n", scissor_clear ? "yes" : "no");
		return false;
	} else {
		return true;
	}
}
Exemplo n.º 18
0
Arquivo: glare.c Projeto: paud/d2x-xl
float CoronaVisibility (int nQuery)
{
	GLuint	nSamples = 0;
	GLint		bAvailable = 0;
	float		fIntensity;
#ifdef _DEBUG
	GLint		nError;
#endif

if (!(gameStates.ogl.bOcclusionQuery && nQuery) || (CoronaStyle () != 1))
	return 1;
if (!(gameStates.render.bQueryCoronas || gameData.render.lights.coronaSamples [nQuery - 1]))
	return 1;
do {
	glGetQueryObjectiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_AVAILABLE_ARB, &bAvailable);
	if (glGetError ()) {
#ifdef _DEBUG
		glGetQueryObjectiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_AVAILABLE_ARB, &bAvailable);
		if (nError = glGetError ())
#endif
			return 1;
		}
	} while (!bAvailable);
glGetQueryObjectuiv (gameData.render.lights.coronaQueries [nQuery - 1], GL_QUERY_RESULT_ARB, &nSamples);
if (glGetError ())
	return 1;
if (gameStates.render.bQueryCoronas == 1) {
#ifdef _DEBUG
	if (!nSamples) {
		GLint nBits;
		glGetQueryiv (GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &nBits);
		}
#endif
	return (float) (gameData.render.lights.coronaSamples [nQuery - 1] = nSamples);
	}
fIntensity = (float) nSamples / (float) gameData.render.lights.coronaSamples [nQuery - 1];
#ifdef _DEBUG
if (fIntensity > 1)
	fIntensity = 1;
#endif
return (fIntensity > 1) ? 1 : (float) sqrt (fIntensity);
}
Exemplo n.º 19
0
template<> Int AbstractQuery::result<Int>() {
    Int result;
#ifndef MAGNUM_TARGET_GLES
    glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result);
#elif !defined(CORRADE_TARGET_NACL)
    glGetQueryObjectivEXT(_id, GL_QUERY_RESULT_EXT, &result);
#else
    CORRADE_ASSERT_UNREACHABLE();
#endif
    return result;
}
Exemplo n.º 20
0
	bool GLOcclusionQuery::isReady() const
	{
		if (!mEndIssued)
			return false;

		GLint done = 0;
		glGetQueryObjectiv(mQueryObj, GL_QUERY_RESULT_AVAILABLE, &done);
		BS_CHECK_GL_ERROR();

		return done == GL_TRUE;
	}
Exemplo n.º 21
0
enum piglit_result
piglit_display(void)
{
#define NUM_QUERIES 5
	GLuint queries[NUM_QUERIES], available;
	bool test_pass = true;
	GLint result;
	int i;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glGenQueries(NUM_QUERIES, queries);

	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

	/* Queue up a bunch of drawing with several queries. */
	for (i = 0; i < NUM_QUERIES - 1;  i++)
	{
		glBeginQuery(GL_SAMPLES_PASSED, queries[i]);

		draw_some_things((double)i / (NUM_QUERIES - 1));

		glEndQuery(GL_SAMPLES_PASSED);
	}

	/* Now fire off a query with no drawing. */
	glBeginQuery(GL_SAMPLES_PASSED, queries[NUM_QUERIES - 1]);
	glEndQuery(GL_SAMPLES_PASSED);

	/* Get the result for the final query. */
	glGetQueryObjectiv(queries[NUM_QUERIES - 1], GL_QUERY_RESULT, &result);

	/* At this point, the results of all the previous queries
	 * should be available.
	 */
	for (i = 0; i < NUM_QUERIES - 1; i++)
	{
		glGetQueryObjectuiv(queries[i], GL_QUERY_RESULT_AVAILABLE,
				    &available);
		if (available != 1) {
			printf("Query #%d result not available (expected in-order processing)\n", i);
			test_pass = false;
		}
	}

	glDeleteQueries(NUM_QUERIES, queries);

	piglit_present_results();

	return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemplo n.º 22
0
u32 GLGSRender::synchronize_zcull_stats(bool hard_sync)
{
	if (!zcull_rendering_enabled || zcull_task_queue.pending == 0)
		return 0;

	u32 result = UINT16_MAX;
	GLint count, status;

	for (auto &query : zcull_task_queue.task_stack)
	{
		if (query == nullptr || query->active)
			continue;

		glGetQueryObjectiv(query->handle, GL_QUERY_RESULT_AVAILABLE, &status);

		if (status == GL_FALSE && !hard_sync)
			continue;

		glGetQueryObjectiv(query->handle, GL_QUERY_RESULT, &count);
		query->pending = false;
		query = nullptr;

		current_zcull_stats.zpass_pixel_cnt += count;
		zcull_task_queue.pending--;
	}

	for (u32 i = 0; i < occlusion_query_count; ++i)
	{
		auto &query = occlusion_query_data[i];
		if (!query.pending && !query.active)
		{
			result = i;
			break;
		}
	}

	if (result == UINT16_MAX && !hard_sync)
		return synchronize_zcull_stats(true);

	return result;
}
Exemplo n.º 23
0
GLuint64 OpenGLTimer::GetElapsedTime()
{
	GLint stopTimerAvailable = 0;
	while (!stopTimerAvailable)
	{
		glGetQueryObjectiv(endQuery, GL_QUERY_RESULT_AVAILABLE, &stopTimerAvailable);
	}
	glGetQueryObjectui64v(startQuery, GL_QUERY_RESULT, &startTime);
	glGetQueryObjectui64v(endQuery, GL_QUERY_RESULT, &endTime);
	elapsedTime = (endTime - startTime) / 1000000.0;
	return elapsedTime;
}
Exemplo n.º 24
0
	bool render()
	{
		glm::ivec2 WindowSize(this->getWindowSize());

		glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * this->view() * Model;

		glQueryCounter(QueryName[query::BEGIN], GL_TIMESTAMP);

		glViewport(0, 0, WindowSize.x, WindowSize.y);

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

		glUseProgram(ProgramName);
		glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &MVP[0][0]);

		glBindVertexArray(VertexArrayName);
		glDrawArrays(GL_TRIANGLES, 0, VertexCount);

		glQueryCounter(QueryName[query::END], GL_TIMESTAMP);

		GLint AvailableBegin = GL_FALSE;
		glGetQueryObjectiv(QueryName[query::BEGIN], GL_QUERY_RESULT_AVAILABLE, &AvailableBegin);

		GLint AvailableEnd = GL_FALSE;
		glGetQueryObjectiv(QueryName[query::END], GL_QUERY_RESULT_AVAILABLE, &AvailableEnd);

		// The OpenGL implementations will wait for the query if it's not available
		GLint64 TimeBegin = 0, TimeEnd = 0;
		glGetQueryObjecti64v(QueryName[query::BEGIN], GL_QUERY_RESULT, &TimeBegin);
		glGetQueryObjecti64v(QueryName[query::END], GL_QUERY_RESULT, &TimeEnd);

		//glGetInteger64v(GL_TIMESTAMP, &TimeBegin);
		//glGetInteger64v(GL_TIMESTAMP, &TimeEnd);

		fprintf(stdout, "%d, %d / Time stamp: %f ms   \r", AvailableBegin, AvailableEnd, (TimeEnd - TimeBegin) / 1000.f / 1000.f);

		return TimeEnd - TimeBegin > 0;
	}
Exemplo n.º 25
0
void Profile::begin()
{
	assert(!CHECKERROR);
	
	if (ready)
	{
		ready = false;
	}

	if (queries.size())
	{
		//if the last query is done, they are all done
		GLint available;
		glGetQueryObjectiv(queryObjs[current-1], GL_QUERY_RESULT_AVAILABLE, &available);
		if (available)
		{
			//get the results
			timeStamps.resize(queryObjs.size());
			for (int i = 0; i < (int)queryObjs.size(); ++i)
			{
				CHECKERROR;
				GLuint64 result;
				glGetQueryObjectui64vEXT(queryObjs[i], GL_QUERY_RESULT, &result);
				timeStamps[i] = result;
				CHECKERROR;
			}
			
			//append the differences to the samples list
			for (QueryMap::iterator it = queries.begin(); it != queries.end(); ++it)
			{
				if (it->second.timeDiff < 1) continue;
				GLuint64 timediff = timeStamps[it->second.timeDiff] - timeStamps[it->second.timeDiff-1];
				it->second.times.push_back(timediff);
				if (it->second.times.size() > PROFILE_SAMPLES)
					it->second.times.pop_front();
				it->second.timeDiff = -1;
			}
			
			//start the next set of samples
			ready = true;
			restartQueries();
		}
	}
	else
		ready = true;
	
	if (ready)
	{
		glQueryCounter(getNextQuery(), GL_TIMESTAMP);
	}
}
Exemplo n.º 26
0
		/**
		 * Method is used to check occlusion query results. Wait for result and if result is 0, set entity state
		 * to invisible.
		 * @param	engineScene is pointer to engine scene.
		 */
		void Occlusion::checkQueriesResults(SceneManager* engineScene)
		{
			vector<SceneEntity*>* entities = &engineScene->getSceneGraph()->sceneEntities;

			for(unsigned int i = 0; i < entities->size(); ++i)
			{
				GLint available;
				do
				{
					glGetQueryObjectiv(queries[i],GL_QUERY_RESULT_AVAILABLE,&available);
				}
				while(!available);
			}

			for(unsigned int i = 0; i < entities->size(); ++i)
			{
				GLint result = 0;
				glGetQueryObjectiv(queries[i],GL_QUERY_RESULT,&result);
     
				if(result == 0)
					entities->at(i)->entityState.isVisible = false;
			}
		}
Exemplo n.º 27
0
template<> Int AbstractQuery::result<Int>() {
    CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});

    /** @todo Re-enable when extension loader is available for ES */
    Int result;
    #ifndef MAGNUM_TARGET_GLES
    glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result);
    #elif defined(CORRADE_TARGET_NACL)
    glGetQueryObjectivEXT(_id, GL_QUERY_RESULT_EXT, &result);
    #else
    CORRADE_INTERNAL_ASSERT(false);
    #endif
    return result;
}
Exemplo n.º 28
0
GFXOcclusionQuery::OcclusionQueryStatus GFXGLOcclusionQuery::getStatus(bool block, U32* data)
{
   // If this ever shows up near the top of a profile 
   // then your system is GPU bound.
   PROFILE_SCOPE(GFXGLOcclusionQuery_getStatus);
   
   GLint numPixels = 0;
   GLint queryDone = false;
   
   if (block)
      queryDone = true;
   else
      glGetQueryObjectiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &queryDone);
   
   if (queryDone)
      glGetQueryObjectiv(mQuery, GL_QUERY_RESULT, &numPixels);
   else
      return Waiting;
   
   if (data)
      *data = numPixels;
   
   return numPixels > 0 ? NotOccluded : Occluded;
}
Exemplo n.º 29
0
bool OcclusionQuery::hasResultAvailable() const
{
  if (m_active)
    return false;

  int available;
  glGetQueryObjectiv(m_queryID, GL_QUERY_RESULT_AVAILABLE, &available);

#if NORI_DEBUG
  if (!checkGL("OpenGL error during occlusion query result availability check"))
    return false;
#endif

  return available ? true : false;
}
Exemplo n.º 30
0
	GLuint64 getResultSync()
	{
		if (thisQueryActive)
			return 0;

		GLuint64 result;
		GLint isReady = GL_FALSE;

		while (isReady == GL_FALSE)
			glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady);

		glGetQueryObjectui64v(query, GL_QUERY_RESULT, &result);

		return result;
	}