//------------------------------------------------------------------ void GLHardwareOcclusionQuery::beginOcclusionQuery() { if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) { glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryID); } else if (GLEW_NV_occlusion_query) { glBeginOcclusionQueryNV(mQueryID); } }
void CGLMQuery::Start( void ) // "start counting" { m_ctx->MakeCurrent(); // on occlusion query: // glBeginQueryARB on the OQ name. counting starts. // on fence: glSetFence on m_name. // note, fences finish themselves via command progress - OQ's do not. Assert(!m_started); Assert(!m_stopped); Assert(!m_done); m_nullQuery = (gl_nullqueries != 0); // latch value for remainder of query life switch(m_params.m_type) { case EOcclusion: { if (m_nullQuery) { // do nothing.. } else { glBeginQueryARB( GL_SAMPLES_PASSED_ARB, m_name ); GLenum errorcode = GetQueryError(); if (errorcode) { const char *decodedStr = GLMDecode( eGL_ERROR, errorcode ); printf( "\nCGLMQuery::Start(OQ) saw %s error (%d) from glBeginQueryARB (GL_SAMPLES_PASSED_ARB) name=%d", decodedStr, errorcode, m_name ); } } } break; case EFence: glSetFenceAPPLE( m_name ); GLenum errorcode = GetQueryError(); if (errorcode) { const char *decodedStr = GLMDecode( eGL_ERROR, errorcode ); printf( "\nCGLMQuery::Start(fence) saw %s error (%d) from glSetFenceAPPLE name=%d", decodedStr, errorcode, m_name ); } m_stopped = true; // caller should not call Stop on a fence, it self-stops break; } m_started = true; }
/* if EndQueryARB is called while no query with the same target is in progress, * an INVALID_OPERATION error is generated. */ static bool conformOQ_EndAfter(GLuint id) { glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glEndQueryARB(GL_SAMPLES_PASSED_ARB); if (!piglit_check_gl_error(GL_INVALID_OPERATION)) return false; return true; }
/* If <id> is not the name of a query object, then an INVALID_OPERATION error * is generated. */ static bool conformOQ_GetObjivAval(GLuint id) { GLuint id_tmp; GLint param; glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id); glEndQueryARB(GL_SAMPLES_PASSED_ARB); id_tmp = find_unused_id(); if (id_tmp == 0) return false; glGetQueryObjectivARB(id_tmp, GL_QUERY_RESULT_AVAILABLE_ARB, ¶m); if (!piglit_check_gl_error(GL_INVALID_OPERATION)) return false; return true; }
static void Draw(void) { GLuint passed; GLint ready; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); glBegin(GL_TRIANGLES); glColor3f(0,0,.7); glVertex3f( 0.9, -0.9, -30.0); glColor3f(.8,0,0); glVertex3f( 0.9, 0.9, -30.0); glColor3f(0,.9,0); glVertex3f(-0.9, 0.0, -30.0); glEnd(); glEndQueryARB(GL_SAMPLES_PASSED_ARB); do { /* do useful work here, if any */ glGetQueryObjectivARB(OccQuery, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); } while (!ready); glGetQueryObjectuivARB(OccQuery, GL_QUERY_RESULT_ARB, &passed); fprintf(stderr, " %d Fragments Visible\n", passed); glFlush(); if (doubleBuffer) { glutSwapBuffers(); } }
void TextureMain::draw2DCalibrationFull() { ExtractFrustum(); GLuint queries[textureModel->TotalFaces]; GLuint sampleCount; glGenQueriesARB(textureModel->TotalFaces, queries); glDisable(GL_BLEND); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); for (int i = 0; i < textureModel->TotalFaces; i++) { int index = i * 3; if (PointInFrustum(textureModel->Faces_Triangles[index * 3], textureModel->Faces_Triangles[index * 3 + 1], textureModel->Faces_Triangles[index * 3 + 2])) { glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]); draw2DElement(i); glEndQueryARB(GL_SAMPLES_PASSED_ARB); } } glEnable(GL_BLEND); glDepthFunc(GL_EQUAL); glDepthMask(GL_FALSE); for (int i = 0; i < textureModel->TotalFaces; i++) { int index = i * 3; if (PointInFrustum(textureModel->Faces_Triangles[index * 3], textureModel->Faces_Triangles[index * 3 + 1], textureModel->Faces_Triangles[index * 3 + 2])) { glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); if (sampleCount > 0) { if (textureIndex > 0) { faces[textureIndex][i] = sampleCount; } draw2DElement(i); } } } glDisable(GL_BLEND); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBOcclusionQuery_nglBeginQueryARB(JNIEnv *env, jclass clazz, jint target, jint id, jlong function_pointer) { glBeginQueryARBPROC glBeginQueryARB = (glBeginQueryARBPROC)((intptr_t)function_pointer); glBeginQueryARB(target, id); }
/* If mutiple queries are issued on the same target and diff ids prior * to calling GetQueryObject[u]iVARB, the results should be * corresponding to those queries (ids) respectively. */ static bool conformOQ_GetObjivAval_multi2(void) { GLuint passed1 = 0, passed2 = 0, passed3 = 0; GLuint id1, id2, id3; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 25.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(0.0, 0.0, -10.0); /* draw the occluder (red) */ glColorMask(1, 1, 1, 1); glDepthMask(GL_TRUE); glColor3f(1, 0, 0); piglit_draw_rect(-0.5, 0.5, 0.5, -0.5); glPushMatrix(); glTranslatef(0.0, 0.0, -5.0); glColorMask(0, 0, 0, 0); glDepthMask(GL_FALSE); id1 = find_unused_id(); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id1); /* draw green quad, much larger than occluder */ glColor3f(0, 1, 0); piglit_draw_rect(-0.7, 0.7, 0.7, -0.7); glEndQueryARB(GL_SAMPLES_PASSED_ARB); id2 = find_unused_id(); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id2); /* draw blue quad, slightly larger than occluder */ glColor3f(0, 0, 1); piglit_draw_rect(-0.53, 0.53, 0.53, -0.53); glEndQueryARB(GL_SAMPLES_PASSED_ARB); id3 = find_unused_id(); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id3); /* draw white quad, smaller than occluder (should not be visible) */ glColor3f(1, 1, 1); piglit_draw_rect(-0.4, 0.4, 0.4, -0.4); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glPopMatrix(); glGetQueryObjectuivARB(id1, GL_QUERY_RESULT_ARB, &passed1); glGetQueryObjectuivARB(id2, GL_QUERY_RESULT_ARB, &passed2); glGetQueryObjectuivARB(id3, GL_QUERY_RESULT_ARB, &passed3); glDepthMask(GL_TRUE); glDeleteQueriesARB(1, &id1); glDeleteQueriesARB(1, &id2); glDeleteQueriesARB(1, &id3); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); if (passed1 > passed2 && passed2 > passed3 && passed3 == 0) return true; else return false; }
void CRenderCaptureGL::BeginRender() { if (!m_asyncChecked) { #ifndef HAS_GLES bool usePbo = g_guiSettings.GetBool("videoplayer.usepbo"); m_asyncSupported = g_Windowing.IsExtSupported("GL_ARB_occlusion_query") && g_Windowing.IsExtSupported("GL_ARB_pixel_buffer_object") && usePbo; if (m_flags & CAPTUREFLAG_CONTINUOUS) { if (!g_Windowing.IsExtSupported("GL_ARB_occlusion_query")) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_occlusion_query not supported, performance might suffer"); if (!g_Windowing.IsExtSupported("GL_ARB_pixel_buffer_object")) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_pixel_buffer_object not supported, performance might suffer"); if (!usePbo) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_pixel_buffer_object disabled, performance might suffer"); } #endif m_asyncChecked = true; } #ifndef HAS_GLES if (m_asyncSupported) { if (!m_pbo) glGenBuffersARB(1, &m_pbo); //only use a query when not capturing immediately if (!m_query && !(m_flags & CAPTUREFLAG_IMMEDIATELY)) { glGenQueriesARB(1, &m_query); } else if (m_query && (m_flags & CAPTUREFLAG_IMMEDIATELY)) { //clean up any old query if the previous capture was not immediately glDeleteQueriesARB(1, &m_query); m_query = 0; } //start the occlusion query if (m_query) glBeginQueryARB(GL_SAMPLES_PASSED_ARB, m_query); //allocate data on the pbo and pixel buffer glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, m_pbo); if (m_bufferSize != m_width * m_height * 4) { m_bufferSize = m_width * m_height * 4; glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, m_bufferSize, 0, GL_STREAM_READ_ARB); delete[] m_pixels; m_pixels = new uint8_t[m_bufferSize]; } } else #endif { if (m_bufferSize != m_width * m_height * 4) { delete[] m_pixels; m_bufferSize = m_width * m_height * 4; m_pixels = new uint8_t[m_bufferSize]; } } }
void runCollisionDetection () { static Clock ck ; ck.update () ; double tall=ck.getDeltaTime () ; static int firsttime = true ; static unsigned int query = 0 ; FrameBufferObject *tmp ; FrameBufferObject *SCM = old ; FrameBufferObject *DCM = collisions ; unsigned int numHits ; if ( firsttime ) { glGenQueriesARB ( 1, (GLuint*) & query ) ; firsttime = false ; } /* Fill SCM with big numbers */ glClearColor ( 1.0f, 1.0f, 1.0f, 1.0f ) ; SCM -> prepare ( true ) ; glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; force -> prepare ( true ) ; /* Zero out all of the forces. */ int numPasses = 0 ; glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; glClientActiveTexture( GL_TEXTURE1 ) ; glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt1 ) ; glTexCoordPointer ( 2, GL_FLOAT, 0, vbo_collt1 ? NULL : colltexcoords1 ) ; glClientActiveTexture( GL_TEXTURE0 ) ; glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt0 ) ; glTexCoordPointer ( 2, GL_FLOAT, 0, vbo_collt0 ? NULL : colltexcoords0 ) ; glEnableClientState ( GL_VERTEX_ARRAY ) ; glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collvx ) ; glVertexPointer ( 3, GL_FLOAT, 0, vbo_collvx ? NULL : collvertices ) ; while ( true ) { collisionGenerator -> use () ; collisionGenerator -> applyTexture ( "position" , position, 0 ) ; collisionGenerator -> applyTexture ( "old_collisions", SCM , 1 ) ; /* Fill DCM with zeroes */ DCM -> prepare ( true ) ; glBeginQueryARB ( GL_SAMPLES_PASSED_ARB, query ) ; glMultiDrawArraysEXT ( GL_QUADS, (GLint*)& collstart, (GLint*)& colllength, 1 ) ; numPasses++ ; glEndQueryARB ( GL_SAMPLES_PASSED_ARB ) ; forceGenerator -> use () ; forceGenerator -> applyTexture ( "position" , position , 0 ) ; forceGenerator -> applyTexture ( "force" , force , 1 ) ; forceGenerator -> applyTexture ( "collisions", DCM , 2 ) ; GLuint sampleCount ; glGetQueryObjectuivARB ( query, GL_QUERY_RESULT_ARB, &sampleCount ) ; //fprintf ( stderr, "%d ", sampleCount ) ; if ( sampleCount == 0 ) break ; new_force -> paint () ; tmp = new_force ; new_force = force ; force = tmp ; tmp = DCM ; DCM = SCM ; SCM = tmp ; } glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; glPopClientAttrib () ; ck.update () ; double tdone=ck.getDeltaTime () ; static int ii = 0 ; ii++; if (ii%100==0) fprintf ( stderr, "Performance: %d passes %d cubes: other=%fms collisions=%fms\n", numPasses, NUM_CUBES, tall*1000.0, tdone*1000.0 ) ; }
void cOcclusionQueryOGL::Begin() { glBeginQueryARB(GL_SAMPLES_PASSED_ARB,mlQueryId); }
static void Display( void ) { GLuint passed; GLint ready; char s[100]; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -15.0 ); /* draw the occluding polygons */ glColor3f(0, 0.6, 0.8); glBegin(GL_QUADS); glVertex2f(-1.6, -1.5); glVertex2f(-0.4, -1.5); glVertex2f(-0.4, 1.5); glVertex2f(-1.6, 1.5); glVertex2f( 0.4, -1.5); glVertex2f( 1.6, -1.5); glVertex2f( 1.6, 1.5); glVertex2f( 0.4, 1.5); glEnd(); /* draw the test polygon with occlusion testing */ glPushMatrix(); glTranslatef(Xpos, 0, -0.5); glScalef(0.3, 0.3, 1.0); glRotatef(-90.0 * Xpos, 0, 0, 1); #if TEST_DISPLAY_LISTS glNewList(10, GL_COMPILE); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); glEndList(); glCallList(10); #else glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); #endif glColorMask(0, 0, 0, 0); glDepthMask(GL_FALSE); glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f( 1, -1, 0); glVertex3f( 1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); #if TEST_DISPLAY_LISTS glNewList(11, GL_COMPILE); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glEndList(); glCallList(11); #else glEndQueryARB(GL_SAMPLES_PASSED_ARB); #endif do { /* do useful work here, if any */ glGetQueryObjectivARB(OccQuery, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); } while (!ready); glGetQueryObjectuivARB(OccQuery, GL_QUERY_RESULT_ARB, &passed); /* turn off occlusion testing */ glColorMask(1, 1, 1, 1); glDepthMask(GL_TRUE); /* draw the orange rect, so we can see what's going on */ glColor3f(0.8, 0.5, 0); glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f( 1, -1, 0); glVertex3f( 1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); glPopMatrix(); /* Print result message */ glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glColor3f(1, 1, 1); sprintf(s, " %4d Fragments Visible", passed); glRasterPos3f(-0.50, -0.7, 0); PrintString(s); if (!passed) { glRasterPos3f(-0.25, -0.8, 0); PrintString("Fully Occluded"); } glutSwapBuffers(); }
real DrawVoronoi(real* xx) { int i,j; real fEnergy = 1e20; GLfloat *buffer_screen = new GLfloat[screenwidth*screenheight*4]; ////////////////////////////////////////////// // First pass - Render the initial sites // ////////////////////////////////////////////// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FB_objects); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[0], 0); CheckFramebufferStatus(); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); glDrawBuffer(fbo_attachments[0]); cgGLEnableProfile(VertexProfile); cgGLEnableProfile(FragmentProfile); cgGLBindProgram(VP_DrawSites); cgGLBindProgram(FP_DrawSites); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(1, screenwidth+1, 1, screenheight+1); glViewport(1, 1, screenwidth, screenheight); DrawSites(xx, NULL); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); Current_Buffer = 1; ///////////////////////////////////// // Second pass - Flood the sites // ///////////////////////////////////// cgGLBindProgram(VP_Flood); cgGLBindProgram(FP_Flood); if (VP_Flood_Size != NULL) cgSetParameter2f(VP_Flood_Size, screenwidth, screenheight); bool ExitLoop = false; bool SecondExit; int steplength;; SecondExit = (additional_passes==0); bool PassesBeforeJFA; PassesBeforeJFA = (additional_passes_before>0); if (PassesBeforeJFA) steplength = pow(2.0, (additional_passes_before-1)); else steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; while (!ExitLoop) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[Current_Buffer], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[Current_Buffer]); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); if (VP_Flood_Steplength != NULL) cgSetParameter1d(VP_Flood_Steplength, steplength); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(1.0, float(screenheight+1)); glVertex2f(float(screenwidth+1), float(screenheight+1)); glVertex2f(float(screenwidth+1), 1.0); glEnd(); glReadBuffer(fbo_attachments[Current_Buffer]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); if (steplength==1 && PassesBeforeJFA) { steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; PassesBeforeJFA = false; } else if (steplength>1) steplength /= 2; else if (SecondExit) ExitLoop = true; else { steplength = pow(2.0, (additional_passes-1)); SecondExit = true; } Current_Buffer = 1-Current_Buffer; } glReadPixels(1,1,screenwidth,screenheight,GL_RGBA,GL_FLOAT,buffer_screen); /////////////////////////////// // Test pass, Compute energy // /////////////////////////////// int Current_Energy_Buffer = 0; glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Energy_Texture[Current_Energy_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); cgGLBindProgram(VP_ComputeEnergyCentroid); cgGLBindProgram(FP_ComputeEnergyCentroid); if (FP_ComputeEnergyCentroid_Size != NULL) cgSetParameter2f(FP_ComputeEnergyCentroid_Size, screenwidth, screenheight); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, Processed_Texture[1-Current_Buffer]); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(float(screenwidth+1), 1.0); glVertex2f(float(screenwidth+1), float(screenheight+1)); glVertex2f(1.0, float(screenheight+1)); glEnd(); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); Current_Energy_Buffer = 1-Current_Energy_Buffer; ////////////////////// // perform reduction ////////////////////// cgGLBindProgram(VP_Deduction); cgGLBindProgram(FP_Deduction); bool ExitEnergyLoop = false; int quad_size = int((screenwidth>screenheight?screenwidth:screenheight)/2.0+0.5); while (!ExitEnergyLoop) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Energy_Texture[Current_Energy_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, Energy_Texture[1-Current_Energy_Buffer]); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(float(quad_size+1), 1.0); glVertex2f(float(quad_size+1), float(quad_size+1)); glVertex2f(1.0, float(quad_size+1)); glEnd(); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); if (quad_size>1) { int temp = quad_size/2; quad_size = temp*2==quad_size ? temp : temp+1; } else ExitEnergyLoop = true; Current_Energy_Buffer = 1-Current_Energy_Buffer; } float total_sum[4]; // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); glReadPixels(1, 1, 1, 1, GL_RGBA, GL_FLOAT, &total_sum); printf("Energy: %f\n", total_sum[0]); fEnergy = total_sum[0]; ////////////////////////////////////////// // Third pass - Scatter points to sites // ////////////////////////////////////////// cgGLBindProgram(VP_ScatterCentroid); cgGLBindProgram(FP_ScatterCentroid); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Site_Texture, 0); CheckFramebufferStatus(); glDrawBuffer(buffers[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (VP_ScatterCentroid_Size != NULL) cgSetParameter2f(VP_ScatterCentroid_Size, screenwidth, screenheight); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glBegin(GL_POINTS); for (i=0; i<screenwidth; i++) for (j=0; j<screenheight; j++) glVertex2f(i+1.5, j+1.5); glEnd(); glDisable(GL_BLEND); Current_Buffer = 1-Current_Buffer; /////////////////////////////////////// // Fourth pass - Test stop condition // /////////////////////////////////////// cgGLBindProgram(VP_DrawSitesOQ); cgGLBindProgram(FP_DrawSitesOQ); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[2], GL_RENDERBUFFER_EXT, RB_object); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[2]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (VP_DrawSitesOQ_Size != NULL) cgSetParameter2f(VP_DrawSitesOQ_Size, screenwidth, screenheight); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Site_Texture); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer]); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusion_query); glBegin(GL_POINTS); for (i=0; i<point_num; i++) { float xx, yy; xx = i%screenwidth+1.5; yy = i/screenheight+1.5; glTexCoord1f(i); glVertex2f(xx, yy); } glEnd(); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); // glReadBuffer(fbo_attachments[2]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); do{ glGetQueryObjectivARB(occlusion_query, GL_QUERY_RESULT_AVAILABLE_ARB, &oq_available); }while(oq_available); glGetQueryObjectuivARB(occlusion_query, GL_QUERY_RESULT_ARB, &sampleCount); printf("sample count: %d\n", sampleCount); cgGLDisableProfile(VertexProfile); cgGLDisableProfile(FragmentProfile); //////////////////// // compute measures //////////////////// bool *bOnBoundary = new bool[point_num]; bool *bIsHexagon = new bool[point_num]; int *nNeighbors = new int[point_num*7]; real *dDiameter = new real[point_num]; real *dNeighborDist = new real[point_num]; float site_pos[2], x, y, dist, neighbor_pos[2]; int id, drow, dcol, nrow, ncol, neighbor_id, k; real dMaxDiameter, chi_id, chi; int nHex, nVC; for (id=0; id<point_num; id++) { bOnBoundary[id] = false; bIsHexagon[id] = true; nNeighbors[id*7] = 0; for (k=1; k<7; k++) nNeighbors[id*7+k] = -1; dDiameter[id] = -1; dNeighborDist[id] = 2*(screenwidth+screenheight); } dMaxDiameter = -1; chi = -1; nHex = nVC = 0; for (i=0; i<screenheight; i++) { for (j=0; j<screenwidth; j++) { site_pos[0] = buffer_screen[i*screenwidth*4+j*4]; site_pos[1] = buffer_screen[i*screenwidth*4+j*4+1]; id = int(buffer_screen[i*screenwidth*4+j*4+2]); x = j+1.5; y = i+1.5; site_pos[0] = (site_pos[0]-1)/screenwidth*2-1; site_pos[1] = (site_pos[1]-1)/screenheight*2-1; x = (x-1)/screenwidth*2-1; y = (y-1)/screenheight*2-1; dist = (x-site_pos[0])*(x-site_pos[0])+(y-site_pos[1])*(y-site_pos[1]); dist = sqrt(dist); dDiameter[id] = dDiameter[id]<dist ? dist : dDiameter[id]; // traverse 9 neighbors for (drow=-1; drow<=1; drow++) { for (dcol=-1; dcol<=1; dcol++) { if (drow==0 && dcol==0) continue; nrow = i+drow; ncol = j+dcol; if (nrow<0 || nrow>=screenheight || ncol<0 || ncol>=screenwidth) { bOnBoundary[id] = true; continue; } neighbor_pos[0] = buffer_screen[nrow*screenwidth*4+ncol*4]; neighbor_pos[1] = buffer_screen[nrow*screenwidth*4+ncol*4+1]; neighbor_id = int(buffer_screen[nrow*screenwidth*4+ncol*4+2]); neighbor_pos[0] = (neighbor_pos[0]-1)/screenwidth*2-1; neighbor_pos[1] = (neighbor_pos[1]-1)/screenheight*2-1; if (neighbor_id==id) continue; dist = (neighbor_pos[0]-site_pos[0])*(neighbor_pos[0]-site_pos[0]) +(neighbor_pos[1]-site_pos[1])*(neighbor_pos[1]-site_pos[1]); dist = sqrt(dist); dNeighborDist[id] = dNeighborDist[id]>dist ? dist : dNeighborDist[id]; for (k=1; k<7; k++) { if (nNeighbors[id*7+k]<0) { nNeighbors[id*7+k] = neighbor_id; nNeighbors[id*7]++; break; } else if (nNeighbors[id*7+k]==neighbor_id) break; } if (k==7) bIsHexagon[id] = false; } } } } for (id=0; id<point_num; id++) { if (nNeighbors[id*7]!=6) bIsHexagon[id] = false; } for (id=0; id<point_num; id++) { dMaxDiameter = dMaxDiameter<dDiameter[id] ? dDiameter[id] : dMaxDiameter; chi_id = 2*dDiameter[id]/dNeighborDist[id]; chi = chi<chi_id ? chi_id : chi; if (!bOnBoundary[id]) { nVC++; } if (bIsHexagon[id]) { nHex++; } } printf("\n==== measures ====\n"); printf("Number of VC in the middle: %d\n", nVC); printf("Number of hexagons: %d\n", nHex); printf("h: %f\n", dMaxDiameter); printf("chi: %f\n", chi); printf("==== measures ====\n\n"); //////////////////// // Fill Octagon & another //////////////////// GLubyte *ColorTexImage = new GLubyte[screenwidth*screenheight*4]; for (i=0; i<screenheight; i++) { for (j=0; j<screenwidth; j++) { int id = i*screenwidth+j; if (id<point_num) { if (bIsHexagon[id]) { ColorTexImage[id*4] = 255; ColorTexImage[id*4+1] = 255; ColorTexImage[id*4+2] = 255; ColorTexImage[id*4+3] = 255; } else { ColorTexImage[id*4] = 192; ColorTexImage[id*4+1] = 192; ColorTexImage[id*4+2] = 192; ColorTexImage[id*4+3] = 255; } } else { ColorTexImage[id*4] = ColorTexImage[id*4+1] = ColorTexImage[id*4+2] = ColorTexImage[id*4+3] = 0.0; } } } glActiveTextureARB(GL_TEXTURE2_ARB); glGenTextures(1, &Color_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Color_Texture); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, screenwidth, screenheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, ColorTexImage); delete ColorTexImage; delete [] buffer_screen; delete [] bOnBoundary; delete [] bIsHexagon; delete [] nNeighbors; delete [] dDiameter; delete [] dNeighborDist; /////////////////////////////////// // Last pass, Display the result // /////////////////////////////////// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, screenwidth-1, 0, screenheight-1); glViewport(0, 0, screenwidth, screenheight); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer]); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Site_Texture); cgGLEnableProfile(VertexProfile); cgGLEnableProfile(FragmentProfile); cgGLBindProgram(VP_FinalRender); cgGLBindProgram(FP_FinalRender); if (FP_FinalRender_Size != NULL) cgSetParameter2f(FP_FinalRender_Size, screenwidth, screenheight); // Set parameters of fragment program glBegin(GL_QUADS); glVertex2f(0.0, 0.0); glVertex2f(0.0, float(screenheight)); glVertex2f(float(screenwidth), float(screenheight)); glVertex2f(float(screenwidth), 0.0); glEnd(); cgGLDisableProfile(VertexProfile); cgGLDisableProfile(FragmentProfile); DrawSites(xx, NULL); return fEnergy; }
void Sector::draw(Renderer *renderer, ShaderID shader, TextureID *base, TextureID *bump, vec3 &position, vec3 &dx, vec3 &dy, bool useOcclusionQueries){ unsigned int i, j; glEnable(GL_CULL_FACE); for (j = 0; j < lights.getCount(); j++){ float t = time - 0.1f; mousehorizontal = mousehorizontal + 200 * mousexxxxxx; mousevericle = mousevericle - 200 * mouseyyyyyy; vec3 p = vec3(0, 500 - mouseY, mouseX); /* XWarpPointer(display, None, window, 0,0,0,0, middleX, middleY); static bool changeMouse; float mouseSensibility = 0.0005f * mouseSpeed; //app->rotateView(mouseSensibility * (middleY - event.xmotion.y) * (invertMouse? 1 : -1), // mouseSensibility * (middleX - event.xmotion.x)); if (changeMouse = !changeMouse) XWarpPointer(display, None, window, 0,0,0,0, middleX, middleY); vec3 p = vec3(mouseSensibility * (middleY - event.xmotion.y) * (invertMouse? 1 : -1), mouseSensibility * (middleX - event.xmotion.x), lights[j].zs * sinf(3.12f * t + j)); */ /* XEvent event; Display *display; display = XOpenDisplay(0); XNextEvent(display, &event); float mouseSensibility = 0.0005f * mouseSpeed; //vec3 p = vec3(mouseSensibility * (- event.xmotion.y) * (1),mouseSensibility * (- event.xmotion.x), 0; */ for (i = 0; i < room->getBatchCount(); i++){ renderer->setShader(shader); renderer->setTexture("Base", base[i]); renderer->setTexture("Bump", bump[i]); if (j > 0) renderer->setBlending(ONE, ONE); renderer->apply(); renderer->changeShaderConstant3f("lightPos", lights[j].position + p); renderer->changeShaderConstant3f("camPos", position); renderer->changeShaderConstant1f("invRadius", 1.0f / lights[j].radius); renderer->changeShaderConstant1f("ambient", (j > 0)? 0 : 0.07f); ((OpenGLBatch *) room->getBatch(i))->draw(); } } hasBeenDrawn = true; if (useOcclusionQueries){ glDisable(GL_CULL_FACE); renderer->setMask(NONE); renderer->apply(); for (i = 0; i < portals.getCount(); i++){ if (portals[i].sector->hasBeenDrawn) continue; glBeginQueryARB(GL_SAMPLES_PASSED_ARB, portals[i].query); glBegin(GL_QUADS); glVertex3fv(portals[i].v0); glVertex3fv(portals[i].v1); glVertex3fv(portals[i].v2); glVertex3fv(portals[i].v3); glEnd(); glEndQueryARB(GL_SAMPLES_PASSED_ARB); } glFlush(); } // Do something useful while waiting for portals rendering to complete for (j = 0; j < lights.getCount(); j++){ //vec3 p = vec3(lights[j].xs * cosf(4.23f * time + j), lights[j].ys * sinf(2.37f * time) * cosf(1.39f * time), lights[j].zs * sinf(3.12f * time + j)); //######################################################## float a = 200, b= 200; //vec3 p = vec3(a,b,200); int aaa = 0; //mousehorizontal = mousehorizontal + 200 * mousexxxxxx; //mousevericle = mousevericle - 200 * mouseyyyyyy; aaa++; /* if (aaa == 2000){ aaa = 0; mousehorizontal = 200; mousevericle = 200; } */ vec3 p = vec3(0, 500 - mouseY, mouseX); printf("%f, %f, %f, %f\n", mouseY, mousehorizontal, mouseX, mousevericle); lights[j].particles->setPosition(p); //lights[j].particles->setPosition(lights[j].position + p); lights[j].particles->update(time); lights[j].vertexArray = lights[j].particles->getVertexArray(dx, dy); } if (useOcclusionQueries){ for (i = 0; i < portals.getCount(); i++){ if (portals[i].sector->hasBeenDrawn) continue; GLuint samples = 0; glGetQueryObjectuivARB(portals[i].query, GL_QUERY_RESULT_ARB, &samples); if (samples > 100){ portals[i].sector->draw(renderer, shader, base, bump, position, dx, dy, useOcclusionQueries); } } } else { for (i = 0; i < portals.getCount(); i++){ if (!portals[i].sector->hasBeenDrawn){ portals[i].sector->draw(renderer, shader, base, bump, position, dx, dy, useOcclusionQueries); } } } }
static HRESULT wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DWORD flags) { struct wined3d_device *device = query->device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; TRACE("query %p, flags %#x.\n", query, flags); if (gl_info->supported[ARB_OCCLUSION_QUERY]) { struct wined3d_occlusion_query *oq = query->extendedData; struct wined3d_context *context; /* This is allowed according to msdn and our tests. Reset the query and restart */ if (flags & WINED3DISSUE_BEGIN) { if (query->state == QUERY_BUILDING) { if (oq->context->tid != GetCurrentThreadId()) { FIXME("Wrong thread, can't restart query.\n"); context_free_occlusion_query(oq); context = context_acquire(query->device, NULL); context_alloc_occlusion_query(context, oq); } else { context = context_acquire(query->device, oq->context->current_rt); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); checkGLcall("glEndQuery()"); } } else { if (oq->context) context_free_occlusion_query(oq); context = context_acquire(query->device, NULL); context_alloc_occlusion_query(context, oq); } GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, oq->id)); checkGLcall("glBeginQuery()"); context_release(context); } if (flags & WINED3DISSUE_END) { /* Msdn says _END on a non-building occlusion query returns an error, but * our tests show that it returns OK. But OpenGL doesn't like it, so avoid * generating an error */ if (query->state == QUERY_BUILDING) { if (oq->context->tid != GetCurrentThreadId()) { FIXME("Wrong thread, can't end query.\n"); } else { context = context_acquire(query->device, oq->context->current_rt); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); checkGLcall("glEndQuery()"); context_release(context); } } } } else { FIXME("%p Occlusion queries not supported.\n", query); } if (flags & WINED3DISSUE_BEGIN) query->state = QUERY_BUILDING; else query->state = QUERY_SIGNALLED; return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */ }
static void Display( void ) { int i; glClearColor(0.25, 0.25, 0.25, 0.0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -15.0 ); /* draw the occluding polygons */ glColor3f(0, 0.4, 0.6); glBegin(GL_QUADS); glVertex2f(-1.6, -2.5); glVertex2f(-0.4, -2.5); glVertex2f(-0.4, 2.5); glVertex2f(-1.6, 2.5); glVertex2f( 0.4, -2.5); glVertex2f( 1.6, -2.5); glVertex2f( 1.6, 2.5); glVertex2f( 0.4, 2.5); glEnd(); glColorMask(0, 0, 0, 0); glDepthMask(GL_FALSE); /* draw the test polygons with occlusion testing */ for (i = 0; i < NUM_OCC; i++) { glPushMatrix(); glTranslatef(Xpos[i], Ypos[i], -0.5); glScalef(0.2, 0.2, 1.0); glRotatef(-90.0 * Xpos[i], 0, 0, 1); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery[i]); glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f( 1, -1, 0); glVertex3f( 1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glPopMatrix(); } glColorMask(1, 1, 1, 1); glDepthMask(GL_TRUE); /* Draw the rectangles now. * Draw orange if result was ready * Draw red if result was not ready. */ for (i = 0; i < NUM_OCC; i++) { GLuint passed; GLint ready; glGetQueryObjectivARB(OccQuery[i], GL_QUERY_RESULT_AVAILABLE_ARB, &ready); glGetQueryObjectuivARB(OccQuery[i], GL_QUERY_RESULT_ARB, &passed); if (!ready) glColor3f(1, 0, 0); else glColor3f(0.8, 0.5, 0); if (!ready || passed) { glPushMatrix(); glTranslatef(Xpos[i], Ypos[i], -0.5); glScalef(0.2, 0.2, 1.0); glRotatef(-90.0 * Xpos[i], 0, 0, 1); glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f( 1, -1, 0); glVertex3f( 1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); glPopMatrix(); } { char s[10]; glRasterPos3f(0.45, Ypos[i], 1.0); sprintf(s, "%4d", passed); PrintString(s); } } glutSwapBuffers(); }
void LLOcclusionCullingGroup::doOcclusion(LLCamera* camera, const LLVector4a* shift) { LLGLDisable stencil(GL_STENCIL_TEST); if (mSpatialPartition->isOcclusionEnabled() && LLPipeline::sUseOcclusion > 1) { //move mBounds to the agent space if necessary LLVector4a bounds[2]; bounds[0] = mBounds[0]; bounds[1] = mBounds[1]; if(shift != NULL) { bounds[0].add(*shift); } // Don't cull hole/edge water, unless we have the GL_ARB_depth_clamp extension if (earlyFail(camera, bounds)) { LLFastTimer t(FTM_OCCLUSION_EARLY_FAIL); setOcclusionState(LLOcclusionCullingGroup::DISCARD_QUERY); assert_states_valid(this); clearOcclusionState(LLOcclusionCullingGroup::OCCLUDED, LLOcclusionCullingGroup::STATE_MODE_DIFF); assert_states_valid(this); } else { if (!isOcclusionState(QUERY_PENDING) || isOcclusionState(DISCARD_QUERY)) { { //no query pending, or previous query to be discarded LLFastTimer t(FTM_RENDER_OCCLUSION); if (!mOcclusionQuery[LLViewerCamera::sCurCameraID]) { LLFastTimer t(FTM_OCCLUSION_ALLOCATE); mOcclusionQuery[LLViewerCamera::sCurCameraID] = getNewOcclusionQueryObjectName(); } // Depth clamp all water to avoid it being culled as a result of being // behind the far clip plane, and in the case of edge water to avoid // it being culled while still visible. bool const use_depth_clamp = gGLManager.mHasDepthClamp && (mSpatialPartition->mDrawableType == LLDrawPool::POOL_WATER || mSpatialPartition->mDrawableType == LLDrawPool::POOL_VOIDWATER); LLGLEnable clamp(use_depth_clamp ? GL_DEPTH_CLAMP : 0); #if !LL_DARWIN U32 mode = gGLManager.mHasOcclusionQuery2 ? GL_ANY_SAMPLES_PASSED : GL_SAMPLES_PASSED_ARB; #else U32 mode = GL_SAMPLES_PASSED_ARB; #endif #if LL_TRACK_PENDING_OCCLUSION_QUERIES sPendingQueries.insert(mOcclusionQuery[LLViewerCamera::sCurCameraID]); #endif { LLFastTimer t(FTM_PUSH_OCCLUSION_VERTS); //store which frame this query was issued on mOcclusionIssued[LLViewerCamera::sCurCameraID] = gFrameCount; { LLFastTimer t(FTM_OCCLUSION_BEGIN_QUERY); glBeginQueryARB(mode, mOcclusionQuery[LLViewerCamera::sCurCameraID]); } LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; llassert(shader); shader->uniform3fv(LLShaderMgr::BOX_CENTER, 1, bounds[0].getF32ptr()); //static LLVector4a fudge(SG_OCCLUSION_FUDGE); static LLCachedControl<F32> vel("SHOcclusionFudge",SG_OCCLUSION_FUDGE); LLVector4a fudge(SG_OCCLUSION_FUDGE); static LLVector4a fudged_bounds; fudged_bounds.setAdd(fudge, bounds[1]); shader->uniform3fv(LLShaderMgr::BOX_SIZE, 1, fudged_bounds.getF32ptr()); if (!use_depth_clamp && mSpatialPartition->mDrawableType == LLDrawPool::POOL_VOIDWATER) { LLFastTimer t(FTM_OCCLUSION_DRAW_WATER); LLGLSquashToFarClip squash(glh_get_current_projection(), 1); if (camera->getOrigin().isExactlyZero()) { //origin is invalid, draw entire box gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, 0); gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, b111*8); } else { gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, bounds[0])); } } else { LLFastTimer t(FTM_OCCLUSION_DRAW); if (camera->getOrigin().isExactlyZero()) { //origin is invalid, draw entire box gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, 0); gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, b111*8); } else { gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, bounds[0])); } } { LLFastTimer t(FTM_OCCLUSION_END_QUERY); glEndQueryARB(mode); } } } { LLFastTimer t(FTM_SET_OCCLUSION_STATE); setOcclusionState(LLOcclusionCullingGroup::QUERY_PENDING); clearOcclusionState(LLOcclusionCullingGroup::DISCARD_QUERY); } } } } }
void MGLContext::beginQuery(unsigned int queryId){ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queryId); }
void CRenderCaptureGL::BeginRender() { if (!m_asyncChecked) { #ifndef HAS_GLES m_asyncSupported = CServiceBroker::GetRenderSystem().IsExtSupported("GL_ARB_pixel_buffer_object"); m_occlusionQuerySupported = CServiceBroker::GetRenderSystem().IsExtSupported("GL_ARB_occlusion_query"); if (m_flags & CAPTUREFLAG_CONTINUOUS) { if (!m_occlusionQuerySupported) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_occlusion_query not supported, performance might suffer"); if (!CServiceBroker::GetRenderSystem().IsExtSupported("GL_ARB_pixel_buffer_object")) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_pixel_buffer_object not supported, performance might suffer"); if (UseOcclusionQuery()) CLog::Log(LOGWARNING, "CRenderCaptureGL: GL_ARB_occlusion_query disabled, performance might suffer"); } #endif m_asyncChecked = true; } #ifndef HAS_GLES if (m_asyncSupported) { if (!m_pbo) glGenBuffersARB(1, &m_pbo); if (UseOcclusionQuery() && m_occlusionQuerySupported) { //generate an occlusion query if we don't have one if (!m_query) glGenQueriesARB(1, &m_query); } else { //don't use an occlusion query, clean up any old one if (m_query) { glDeleteQueriesARB(1, &m_query); m_query = 0; } } //start the occlusion query if (m_query) glBeginQueryARB(GL_SAMPLES_PASSED_ARB, m_query); //allocate data on the pbo and pixel buffer glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, m_pbo); if (m_bufferSize != m_width * m_height * 4) { m_bufferSize = m_width * m_height * 4; glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, m_bufferSize, 0, GL_STREAM_READ_ARB); delete[] m_pixels; m_pixels = new uint8_t[m_bufferSize]; } } else #endif { if (m_bufferSize != m_width * m_height * 4) { delete[] m_pixels; m_bufferSize = m_width * m_height * 4; m_pixels = new uint8_t[m_bufferSize]; } } }
static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) { IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface; IWineD3DDeviceImpl *device = This->device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; if (gl_info->supported[ARB_OCCLUSION_QUERY]) { struct wined3d_occlusion_query *query = This->extendedData; struct wined3d_context *context; /* This is allowed according to msdn and our tests. Reset the query and restart */ if (dwIssueFlags & WINED3DISSUE_BEGIN) { if (This->state == QUERY_BUILDING) { if (query->context->tid != GetCurrentThreadId()) { FIXME("Wrong thread, can't restart query.\n"); context_free_occlusion_query(query); context = context_acquire(This->device, NULL); context_alloc_occlusion_query(context, query); } else { context = context_acquire(This->device, query->context->current_rt); ENTER_GL(); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); checkGLcall("glEndQuery()"); LEAVE_GL(); } } else { if (query->context) context_free_occlusion_query(query); context = context_acquire(This->device, NULL); context_alloc_occlusion_query(context, query); } ENTER_GL(); GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query->id)); checkGLcall("glBeginQuery()"); LEAVE_GL(); context_release(context); } if (dwIssueFlags & WINED3DISSUE_END) { /* Msdn says _END on a non-building occlusion query returns an error, but * our tests show that it returns OK. But OpenGL doesn't like it, so avoid * generating an error */ if (This->state == QUERY_BUILDING) { if (query->context->tid != GetCurrentThreadId()) { FIXME("Wrong thread, can't end query.\n"); } else { context = context_acquire(This->device, query->context->current_rt); ENTER_GL(); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); checkGLcall("glEndQuery()"); LEAVE_GL(); context_release(context); } } } } else { FIXME("(%p) : Occlusion queries not supported\n", This); } if(dwIssueFlags & WINED3DISSUE_BEGIN) { This->state = QUERY_BUILDING; } else { This->state = QUERY_SIGNALLED; } return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */ }