Skip to main content
gamedev.net
🔒 Locked

Occlusion Query

Started by FatGarfield 3 replies 2.2k views
Original Post
FatGarfield
FatGarfield
I create a hierarchical scene graph, and bind a IDirect3DQuery9 object to each node 0 |---------| 1 4 |------| |------| 2 3 5 6 I use g_pDevice9->CreateQuery( D3DQUERYTYPE_OCCLUSION, &pquery ); to create each IDirect3DQuery9 object before rendering. In rendering, first block z-buffer and color-buffer writting, then issue query for boundig box of each node, according to the queried result, to draw this node or not. If I query individual node's occlusion information, I can get correct result, but if I query one more node, the query result of some node is zero ( sure it should not be zero!). If there is a maximum number restriction on occlusion query in D3D? thanks!
Here I am.
JasonBlochowiak
JasonBlochowiak
Are you making sure the query finishes? Off the top of my head, I don't remember the specific D3D calls, but IIRC a given query may or may not have actually made it through to the hardware at a given point, which is why quite a lot of occlusion query engines need to have a policy for dealing with incomplete queries.
Mr X
Mr X
Hi,

it's right what JasonBlochowiak said.

Quote:
If there is a maximum number restriction on occlusion query in D3D?


I think not, but i'm not sure.

The following is an inefficient way to wait until the query has been finished, but it works.

DWORD sizePixel = 0;while(d3dQuery->GetData((void*) &sizePixel, sizeof(DWORD), D3DGETDATA_FLUSH) == S_FALSE);


It's better to have a policy for dealing with incomplete queries.

Have fun.


[not forgotten to use the source tags ;-)]

[Edited by - Mr X on March 28, 2007 11:29:30 AM]
FatGarfield
FatGarfield
thank you, JasonBlochowiak and Mr X

I'm sure the query finished.

The scheme of my program is:

1. I define a COcclusionQuery class to wrap the occlusion query

class COcclusionQuery
{
public:
COcclusionQuery(void)
{
g_pDevice9->CreateQuery( D3DQUERYTYPE_OCCLUSION, &m_pquery );
)
~COcclusionQuery(void)
{
RELEASE( m_pquery );
}

public:
void begin()
{
g_pDevice9->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
g_pDevice9->SetRenderState(D3DRS_COLORWRITEENABLE, 0x0 );
m_pquery->Issue( D3DISSUE_BEGIN );
}
void end()
{
g_pDevice9->SetRenderState(D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_ALPHA|
D3DCOLORWRITEENABLE_BLUE|
D3DCOLORWRITEENABLE_GREEN|
D3DCOLORWRITEENABLE_RED );
g_pDevice9->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);

m_pquery->Issue( D3DISSUE_END );
}
void getdata_wait( DWORD& dwdata )
{
while( m_pquery->GetData((void *) &dwdata, sizeof(DWORD),
D3DGETDATA_FLUSH) != S_OK )
{ }
}
public:
IDirect3DQuery9 *m_pquery;
}

2. for each of the scene node, I define a class

class CKDNode
{
...
public:

CKDNode *pleft;
CKDNode *pright;
COcclusionQuery query;
...
}

3. render the scene graph,

render_recur( CKDNode *pKDNode )
{
DWORD dwdata;
pKDNode->query.begin();
*render bounding box of pKDNode*
pKDNode->query.end();
pKDNode->query.getdata_wait(dwdata);
if( dwdata > 0 ){
*render geometry objects in this node*
}
if( pKDNode->pleft != 0 ){
render_recur(pKDNode->pleft);
}
if( pKDNode->pright != 0 ){
render_recur(pKDNode->pright);
}

}

some of the scene graph nodes' query result should not be zero, but I get zero from query interface:(
Here I am.
JasonBlochowiak
JasonBlochowiak
Are you really not checking for any errors on any of the D3D calls? I use a simple macro that maps to Assert() for almost all of my D3D calls.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.