wined3d: Test and fix ddraw and d3d9 GetDC differences.
[wine] / dlls / wined3d / query.c
1 /*
2  * IWineD3DQuery implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22
23 #include "config.h"
24 #include "wined3d_private.h"
25
26 /*
27  * Occlusion Queries:
28  * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
29  * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
30  */
31
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 #define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
34
35 /* *******************************************
36    IWineD3DQuery IUnknown parts follow
37    ******************************************* */
38 static HRESULT  WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
39 {
40     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
41     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
42     if (IsEqualGUID(riid, &IID_IUnknown)
43         || IsEqualGUID(riid, &IID_IWineD3DBase)
44         || IsEqualGUID(riid, &IID_IWineD3DQuery)) {
45         IUnknown_AddRef(iface);
46         *ppobj = This;
47         return S_OK;
48     }
49     *ppobj = NULL;
50     return E_NOINTERFACE;
51 }
52
53 static ULONG  WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
54     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
55     TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
56     return InterlockedIncrement(&This->ref);
57 }
58
59 static ULONG  WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
60     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
61     ULONG ref;
62     TRACE("(%p) : Releasing from %d\n", This, This->ref);
63     ref = InterlockedDecrement(&This->ref);
64     if (ref == 0) {
65         /* Queries are specific to the GL context that created them. Not
66          * deleting the query will obviously leak it, but that's still better
67          * than potentially deleting a different query with the same id in this
68          * context, and (still) leaking the actual query. */
69         if (This->type == WINED3DQUERYTYPE_EVENT)
70         {
71             struct wined3d_event_query *query = This->extendedData;
72
73             if (query->context) context_free_event_query(query);
74         }
75         else if (This->type == WINED3DQUERYTYPE_OCCLUSION)
76         {
77             struct wined3d_occlusion_query *query = This->extendedData;
78
79             if (query->context) context_free_occlusion_query(query);
80         }
81
82         HeapFree(GetProcessHeap(), 0, This->extendedData);
83         HeapFree(GetProcessHeap(), 0, This);
84     }
85     return ref;
86 }
87
88 /* *******************************************
89    IWineD3DQuery IWineD3DQuery parts follow
90    ******************************************* */
91 static HRESULT  WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
92     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
93
94     *parent= (IUnknown*) parent;
95     IUnknown_AddRef(*parent);
96     TRACE("(%p) : returning %p\n", This, *parent);
97     return WINED3D_OK;
98 }
99
100 static HRESULT  WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
101     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
102     IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
103     *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
104     TRACE("(%p) returning %p\n", This, *pDevice);
105     return WINED3D_OK;
106 }
107
108
109 static HRESULT  WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
110     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
111     HRESULT res = S_OK;
112
113     TRACE("(%p) : type %#x, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, This->type, pData, dwSize, dwGetDataFlags);
114
115     switch (This->type){
116
117     case WINED3DQUERYTYPE_VCACHE:
118     {
119
120         WINED3DDEVINFO_VCACHE *data = pData;
121         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VCACHE\n", This);
122         if(pData == NULL || dwSize == 0) break;
123         data->Pattern     = WINEMAKEFOURCC('C','A','C','H');
124         data->OptMethod   = 0; /*0 get longest strips, 1 optimize vertex cache*/
125         data->CacheSize   = 0; /*cache size, only required if OptMethod == 1*/
126         data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
127
128     }
129     break;
130     case WINED3DQUERYTYPE_RESOURCEMANAGER:
131     {
132         WINED3DDEVINFO_RESOURCEMANAGER *data = pData;
133         int i;
134         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_RESOURCEMANAGER\n", This);
135         if(pData == NULL || dwSize == 0) break;
136         for(i = 0; i < WINED3DRTYPECOUNT; i++){
137             /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
138             /*  isTextureResident could be used to get some of this information  */
139             data->stats[i].bThrashing            = FALSE;
140             data->stats[i].ApproxBytesDownloaded = 1;
141             data->stats[i].NumEvicts             = 1;
142             data->stats[i].NumVidCreates         = 1;
143             data->stats[i].LastPri               = 1;
144             data->stats[i].NumUsed               = 1;
145             data->stats[i].NumUsedInVidMem       = 1;
146             data->stats[i].WorkingSet            = 1;
147             data->stats[i].WorkingSetBytes       = 1;
148             data->stats[i].TotalManaged          = 1;
149             data->stats[i].TotalBytes            = 1;
150         }
151
152     }
153     break;
154     case WINED3DQUERYTYPE_VERTEXSTATS:
155     {
156         WINED3DDEVINFO_VERTEXSTATS *data = pData;
157         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXSTATS\n", This);
158         if(pData == NULL || dwSize == 0) break;
159         data->NumRenderedTriangles      = 1;
160         data->NumExtraClippingTriangles = 1;
161
162     }
163     break;
164     case WINED3DQUERYTYPE_TIMESTAMP:
165     {
166         UINT64* data = pData;
167         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMP\n", This);
168         if(pData == NULL || dwSize == 0) break;
169         *data = 1; /*Don't know what this is supposed to be*/
170     }
171     break;
172     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
173     {
174         BOOL* data = pData;
175         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPDISJOINT\n", This);
176         if(pData == NULL || dwSize == 0) break;
177         *data = FALSE; /*Don't know what this is supposed to be*/
178     }
179     break;
180     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
181     {
182         UINT64* data = pData;
183         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPFREQ\n", This);
184         if(pData == NULL || dwSize == 0) break;
185         *data = 1; /*Don't know what this is supposed to be*/
186     }
187     break;
188     case WINED3DQUERYTYPE_PIPELINETIMINGS:
189     {
190         WINED3DDEVINFO_PIPELINETIMINGS *data = pData;
191         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIPELINETIMINGS\n", This);
192         if(pData == NULL || dwSize == 0) break;
193
194         data->VertexProcessingTimePercent    =   1.0f;
195         data->PixelProcessingTimePercent     =   1.0f;
196         data->OtherGPUProcessingTimePercent  =  97.0f;
197         data->GPUIdleTimePercent             =   1.0f;
198     }
199     break;
200     case WINED3DQUERYTYPE_INTERFACETIMINGS:
201     {
202         WINED3DDEVINFO_INTERFACETIMINGS *data = pData;
203         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_INTERFACETIMINGS\n", This);
204
205         if(pData == NULL || dwSize == 0) break;
206         data->WaitingForGPUToUseApplicationResourceTimePercent =   1.0f;
207         data->WaitingForGPUToAcceptMoreCommandsTimePercent     =   1.0f;
208         data->WaitingForGPUToStayWithinLatencyTimePercent      =   1.0f;
209         data->WaitingForGPUExclusiveResourceTimePercent        =   1.0f;
210         data->WaitingForGPUOtherTimePercent                    =  96.0f;
211     }
212
213     break;
214     case WINED3DQUERYTYPE_VERTEXTIMINGS:
215     {
216         WINED3DDEVINFO_STAGETIMINGS *data = pData;
217         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXTIMINGS\n", This);
218
219         if(pData == NULL || dwSize == 0) break;
220         data->MemoryProcessingPercent      = 50.0f;
221         data->ComputationProcessingPercent = 50.0f;
222
223     }
224     break;
225     case WINED3DQUERYTYPE_PIXELTIMINGS:
226     {
227         WINED3DDEVINFO_STAGETIMINGS *data = pData;
228         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIXELTIMINGS\n", This);
229
230         if(pData == NULL || dwSize == 0) break;
231         data->MemoryProcessingPercent      = 50.0f;
232         data->ComputationProcessingPercent = 50.0f;
233     }
234     break;
235     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
236     {
237         WINED3DDEVINFO_BANDWIDTHTIMINGS *data = pData;
238         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_BANDWIDTHTIMINGS\n", This);
239
240         if(pData == NULL || dwSize == 0) break;
241         data->MaxBandwidthUtilized                =  1.0f;
242         data->FrontEndUploadMemoryUtilizedPercent =  1.0f;
243         data->VertexRateUtilizedPercent           =  1.0f;
244         data->TriangleSetupRateUtilizedPercent    =  1.0f;
245         data->FillRateUtilizedPercent             = 97.0f;
246     }
247     break;
248     case WINED3DQUERYTYPE_CACHEUTILIZATION:
249     {
250         WINED3DDEVINFO_CACHEUTILIZATION *data = pData;
251         FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_CACHEUTILIZATION\n", This);
252
253         if(pData == NULL || dwSize == 0) break;
254         data->TextureCacheHitRate             = 1.0f;
255         data->PostTransformVertexCacheHitRate = 1.0f;
256     }
257
258
259     break;
260     default:
261         FIXME("(%p) Unhandled query type %d\n",This , This->type);
262
263     };
264
265     /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
266     D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
267     */
268     return res; /* S_OK if the query data is available*/
269 }
270
271 static HRESULT  WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
272     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
273     struct wined3d_occlusion_query *query = This->extendedData;
274     DWORD* data = pData;
275     GLuint available;
276     GLuint samples;
277     HRESULT res;
278
279     TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
280
281     if (!query->context) This->state = QUERY_CREATED;
282
283     if (This->state == QUERY_CREATED)
284     {
285         /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
286         TRACE("Query wasn't yet started, returning S_OK\n");
287         if(data) *data = 0;
288         return S_OK;
289     }
290
291     if (This->state == QUERY_BUILDING)
292     {
293         /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
294         TRACE("Query is building, returning S_FALSE\n");
295         return S_FALSE;
296     }
297
298     if (!GL_SUPPORT(ARB_OCCLUSION_QUERY))
299     {
300         WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
301         *data = 1;
302         return S_OK;
303     }
304
305     if (query->context->tid != GetCurrentThreadId())
306     {
307         FIXME("%p Wrong thread, returning 1.\n", This);
308         *data = 1;
309         return S_OK;
310     }
311
312     ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
313
314     ENTER_GL();
315
316     GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
317     checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
318     TRACE("(%p) : available %d.\n", This, available);
319
320     if (available)
321     {
322         if (data)
323         {
324             GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_ARB, &samples));
325             checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
326             TRACE("(%p) : Returning %d samples.\n", This, samples);
327             *data = samples;
328         }
329         res = S_OK;
330     }
331     else
332     {
333         res = S_FALSE;
334     }
335
336     LEAVE_GL();
337
338     return res;
339 }
340
341 static HRESULT  WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
342     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
343     struct wined3d_event_query *query = This->extendedData;
344     BOOL* data = pData;
345
346     TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
347
348     if (!pData || !dwSize) return S_OK;
349
350     if (!query->context)
351     {
352         ERR("Query not started, returning TRUE.\n");
353         *data = TRUE;
354
355         return S_OK;
356     }
357
358     if (query->context->tid != GetCurrentThreadId())
359     {
360         /* See comment in IWineD3DQuery::Issue, event query codeblock */
361         FIXME("Wrong thread, reporting GPU idle.\n");
362         *data = TRUE;
363
364         return S_OK;
365     }
366
367     ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
368
369     ENTER_GL();
370
371     if (GL_SUPPORT(APPLE_FENCE))
372     {
373         *data = GL_EXTCALL(glTestFenceAPPLE(query->id));
374         checkGLcall("glTestFenceAPPLE");
375     }
376     else if (GL_SUPPORT(NV_FENCE))
377     {
378         *data = GL_EXTCALL(glTestFenceNV(query->id));
379         checkGLcall("glTestFenceNV");
380     }
381     else
382     {
383         WARN("(%p): reporting GPU idle\n", This);
384         *data = TRUE;
385     }
386
387     LEAVE_GL();
388
389     return S_OK;
390 }
391
392 static DWORD  WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
393     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
394     int dataSize = 0;
395     TRACE("(%p) : type %#x\n", This, This->type);
396     switch(This->type){
397     case WINED3DQUERYTYPE_VCACHE:
398         dataSize = sizeof(WINED3DDEVINFO_VCACHE);
399         break;
400     case WINED3DQUERYTYPE_RESOURCEMANAGER:
401         dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
402         break;
403     case WINED3DQUERYTYPE_VERTEXSTATS:
404         dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
405         break;
406     case WINED3DQUERYTYPE_EVENT:
407         dataSize = sizeof(BOOL);
408         break;
409     case WINED3DQUERYTYPE_TIMESTAMP:
410         dataSize = sizeof(UINT64);
411         break;
412     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
413         dataSize = sizeof(BOOL);
414         break;
415     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
416         dataSize = sizeof(UINT64);
417         break;
418     case WINED3DQUERYTYPE_PIPELINETIMINGS:
419         dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
420         break;
421     case WINED3DQUERYTYPE_INTERFACETIMINGS:
422         dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
423         break;
424     case WINED3DQUERYTYPE_VERTEXTIMINGS:
425         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
426         break;
427     case WINED3DQUERYTYPE_PIXELTIMINGS:
428         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
429         break;
430     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
431         dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
432         break;
433     case WINED3DQUERYTYPE_CACHEUTILIZATION:
434         dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
435         break;
436     default:
437        FIXME("(%p) Unhandled query type %d\n",This , This->type);
438        dataSize = 0;
439     }
440     return dataSize;
441 }
442
443 static DWORD  WINAPI IWineD3DEventQueryImpl_GetDataSize(IWineD3DQuery* iface){
444     TRACE("(%p) : type D3DQUERY_EVENT\n", iface);
445
446     return sizeof(BOOL);
447 }
448
449 static DWORD  WINAPI IWineD3DOcclusionQueryImpl_GetDataSize(IWineD3DQuery* iface){
450     TRACE("(%p) : type D3DQUERY_OCCLUSION\n", iface);
451
452     return sizeof(DWORD);
453 }
454
455 static WINED3DQUERYTYPE  WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
456     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
457     return This->type;
458 }
459
460
461 static HRESULT  WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface,  DWORD dwIssueFlags) {
462     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
463
464     TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
465     if (dwIssueFlags & WINED3DISSUE_END)
466     {
467         struct wined3d_event_query *query = This->extendedData;
468         struct wined3d_context *context;
469
470         if (query->context)
471         {
472             if (query->context->tid != GetCurrentThreadId())
473             {
474                 context_free_event_query(query);
475                 context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
476                 context_alloc_event_query(context, query);
477             }
478             else
479             {
480                 ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
481             }
482         }
483         else
484         {
485             context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
486             context_alloc_event_query(context, query);
487         }
488
489         ENTER_GL();
490
491         if (GL_SUPPORT(APPLE_FENCE))
492         {
493             GL_EXTCALL(glSetFenceAPPLE(query->id));
494             checkGLcall("glSetFenceAPPLE");
495         }
496         else if (GL_SUPPORT(NV_FENCE))
497         {
498             GL_EXTCALL(glSetFenceNV(query->id, GL_ALL_COMPLETED_NV));
499             checkGLcall("glSetFenceNV");
500         }
501
502         LEAVE_GL();
503     }
504     else if(dwIssueFlags & WINED3DISSUE_BEGIN)
505     {
506         /* Started implicitly at device creation */
507         ERR("Event query issued with START flag - what to do?\n");
508     }
509
510     if(dwIssueFlags & WINED3DISSUE_BEGIN) {
511         This->state = QUERY_BUILDING;
512     } else {
513         This->state = QUERY_SIGNALLED;
514     }
515
516     return WINED3D_OK;
517 }
518
519 static HRESULT  WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface,  DWORD dwIssueFlags) {
520     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
521
522     if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
523     {
524         struct wined3d_occlusion_query *query = This->extendedData;
525         struct wined3d_context *context;
526
527         /* This is allowed according to msdn and our tests. Reset the query and restart */
528         if (dwIssueFlags & WINED3DISSUE_BEGIN)
529         {
530             if (This->state == QUERY_BUILDING)
531             {
532                 if (query->context->tid != GetCurrentThreadId())
533                 {
534                     FIXME("Wrong thread, can't restart query.\n");
535
536                     context_free_occlusion_query(query);
537                     context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
538                     context_alloc_occlusion_query(context, query);
539                 }
540                 else
541                 {
542                     ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
543
544                     ENTER_GL();
545                     GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
546                     checkGLcall("glEndQuery()");
547                     LEAVE_GL();
548                 }
549             }
550             else
551             {
552                 if (query->context) context_free_occlusion_query(query);
553                 context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
554                 context_alloc_occlusion_query(context, query);
555             }
556
557             ENTER_GL();
558             GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query->id));
559             checkGLcall("glBeginQuery()");
560             LEAVE_GL();
561         }
562         if (dwIssueFlags & WINED3DISSUE_END) {
563             /* Msdn says _END on a non-building occlusion query returns an error, but
564              * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
565              * generating an error
566              */
567             if (This->state == QUERY_BUILDING)
568             {
569                 if (query->context->tid != GetCurrentThreadId())
570                 {
571                     FIXME("Wrong thread, can't end query.\n");
572                 }
573                 else
574                 {
575                     ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
576
577                     ENTER_GL();
578                     GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
579                     checkGLcall("glEndQuery()");
580                     LEAVE_GL();
581                 }
582             }
583         }
584     } else {
585         FIXME("(%p) : Occlusion queries not supported\n", This);
586     }
587
588     if(dwIssueFlags & WINED3DISSUE_BEGIN) {
589         This->state = QUERY_BUILDING;
590     } else {
591         This->state = QUERY_SIGNALLED;
592     }
593     return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL.    */
594 }
595
596 static HRESULT  WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface,  DWORD dwIssueFlags){
597     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
598
599     TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
600
601     /* The fixme is printed when the app asks for the resulting data */
602     WARN("(%p) : Unhandled query type %#x\n", This, This->type);
603
604     if(dwIssueFlags & WINED3DISSUE_BEGIN) {
605         This->state = QUERY_BUILDING;
606     } else {
607         This->state = QUERY_SIGNALLED;
608     }
609
610     return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL.    */
611 }
612
613
614 /**********************************************************
615  * IWineD3DQuery VTbl follows
616  **********************************************************/
617
618 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
619 {
620     /*** IUnknown methods ***/
621     IWineD3DQueryImpl_QueryInterface,
622     IWineD3DQueryImpl_AddRef,
623     IWineD3DQueryImpl_Release,
624      /*** IWineD3Dquery methods ***/
625     IWineD3DQueryImpl_GetParent,
626     IWineD3DQueryImpl_GetDevice,
627     IWineD3DQueryImpl_GetData,
628     IWineD3DQueryImpl_GetDataSize,
629     IWineD3DQueryImpl_GetType,
630     IWineD3DQueryImpl_Issue
631 };
632
633 const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
634 {
635     /*** IUnknown methods ***/
636     IWineD3DQueryImpl_QueryInterface,
637     IWineD3DQueryImpl_AddRef,
638     IWineD3DQueryImpl_Release,
639     /*** IWineD3Dquery methods ***/
640     IWineD3DQueryImpl_GetParent,
641     IWineD3DQueryImpl_GetDevice,
642     IWineD3DEventQueryImpl_GetData,
643     IWineD3DEventQueryImpl_GetDataSize,
644     IWineD3DQueryImpl_GetType,
645     IWineD3DEventQueryImpl_Issue
646 };
647
648 const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
649 {
650     /*** IUnknown methods ***/
651     IWineD3DQueryImpl_QueryInterface,
652     IWineD3DQueryImpl_AddRef,
653     IWineD3DQueryImpl_Release,
654     /*** IWineD3Dquery methods ***/
655     IWineD3DQueryImpl_GetParent,
656     IWineD3DQueryImpl_GetDevice,
657     IWineD3DOcclusionQueryImpl_GetData,
658     IWineD3DOcclusionQueryImpl_GetDataSize,
659     IWineD3DQueryImpl_GetType,
660     IWineD3DOcclusionQueryImpl_Issue
661 };