mirrored from git://source.winehq.org/git/wine.git
/
directx.c
6003 lines (5422 loc) · 282 KB
/
directx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2002-2004 Jason Edmeades
* Copyright 2003-2004 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include "wined3d_private.h"
#include "winternl.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
WINE_DECLARE_DEBUG_CHANNEL(winediag);
#define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
#define DEFAULT_REFRESH_RATE 0
/* The driver names reflect the lowest GPU supported
* by a certain driver, so DRIVER_AMD_R300 supports
* R3xx, R4xx and R5xx GPUs. */
enum wined3d_display_driver
{
DRIVER_AMD_RAGE_128PRO,
DRIVER_AMD_R100,
DRIVER_AMD_R300,
DRIVER_AMD_R600,
DRIVER_INTEL_GMA800,
DRIVER_INTEL_GMA900,
DRIVER_INTEL_GMA950,
DRIVER_INTEL_GMA3000,
DRIVER_NVIDIA_TNT,
DRIVER_NVIDIA_GEFORCE2MX,
DRIVER_NVIDIA_GEFORCEFX,
DRIVER_NVIDIA_GEFORCE6,
DRIVER_NVIDIA_GEFORCE8,
DRIVER_VMWARE,
DRIVER_UNKNOWN
};
enum wined3d_driver_model
{
DRIVER_MODEL_WIN9X,
DRIVER_MODEL_NT40,
DRIVER_MODEL_NT5X,
DRIVER_MODEL_NT6X
};
enum wined3d_gl_vendor
{
GL_VENDOR_UNKNOWN,
GL_VENDOR_APPLE,
GL_VENDOR_FGLRX,
GL_VENDOR_MESA,
GL_VENDOR_NVIDIA,
};
enum wined3d_d3d_level
{
WINED3D_D3D_LEVEL_5,
WINED3D_D3D_LEVEL_6,
WINED3D_D3D_LEVEL_7,
WINED3D_D3D_LEVEL_8,
WINED3D_D3D_LEVEL_9_SM2,
WINED3D_D3D_LEVEL_9_SM3,
WINED3D_D3D_LEVEL_10,
WINED3D_D3D_LEVEL_11,
WINED3D_D3D_LEVEL_COUNT
};
/* The d3d device ID */
static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
/* Extension detection */
struct wined3d_extension_map
{
const char *extension_string;
enum wined3d_gl_extension extension;
};
static const struct wined3d_extension_map gl_extension_map[] =
{
/* APPLE */
{"GL_APPLE_fence", APPLE_FENCE },
{"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS },
{"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE },
{"GL_APPLE_ycbcr_422", APPLE_YCBCR_422 },
/* ARB */
{"GL_ARB_blend_func_extended", ARB_BLEND_FUNC_EXTENDED },
{"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT },
{"GL_ARB_debug_output", ARB_DEBUG_OUTPUT },
{"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT },
{"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE },
{"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS },
{"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX },
{"GL_ARB_draw_instanced", ARB_DRAW_INSTANCED },
{"GL_ARB_ES2_compatibility", ARB_ES2_COMPATIBILITY },
{"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM },
{"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER },
{"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT },
{"GL_ARB_framebuffer_sRGB", ARB_FRAMEBUFFER_SRGB },
{"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 },
{"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL },
{"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX },
{"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS, },
{"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2, },
{"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT },
{"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE },
{"GL_ARB_multisample", ARB_MULTISAMPLE },
{"GL_ARB_multitexture", ARB_MULTITEXTURE },
{"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY },
{"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT },
{"GL_ARB_point_parameters", ARB_POINT_PARAMETERS },
{"GL_ARB_point_sprite", ARB_POINT_SPRITE },
{"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX },
{"GL_ARB_sampler_objects", ARB_SAMPLER_OBJECTS },
{"GL_ARB_shader_bit_encoding", ARB_SHADER_BIT_ENCODING },
{"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD },
{"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 },
{"GL_ARB_shadow", ARB_SHADOW },
{"GL_ARB_sync", ARB_SYNC },
{"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP },
{"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION },
{"GL_ARB_texture_compression_rgtc", ARB_TEXTURE_COMPRESSION_RGTC },
{"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP },
{"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE },
{"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3 },
{"GL_ARB_texture_float", ARB_TEXTURE_FLOAT },
{"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
{"GL_ARB_texture_mirror_clamp_to_edge", ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE},
{"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO },
{"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE },
{"GL_ARB_texture_rg", ARB_TEXTURE_RG },
{"GL_ARB_timer_query", ARB_TIMER_QUERY },
{"GL_ARB_uniform_buffer_object", ARB_UNIFORM_BUFFER_OBJECT },
{"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
{"GL_ARB_vertex_blend", ARB_VERTEX_BLEND },
{"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT },
{"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM },
{"GL_ARB_vertex_shader", ARB_VERTEX_SHADER },
/* ATI */
{"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER },
{"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL },
{"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC },
{"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3 },
{"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE },
/* EXT */
{"GL_EXT_blend_color", EXT_BLEND_COLOR },
{"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE },
{"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE },
{"GL_EXT_blend_minmax", EXT_BLEND_MINMAX },
{"GL_EXT_blend_subtract", EXT_BLEND_SUBTRACT },
{"GL_EXT_depth_bounds_test", EXT_DEPTH_BOUNDS_TEST },
{"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2 },
{"GL_EXT_fog_coord", EXT_FOG_COORD },
{"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT },
{"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE },
{"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT },
{"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS },
{"GL_EXT_gpu_shader4", EXT_GPU_SHADER4 },
{"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL },
{"GL_EXT_point_parameters", EXT_POINT_PARAMETERS },
{"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX },
{"GL_EXT_secondary_color", EXT_SECONDARY_COLOR },
{"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE },
{"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP },
{"GL_EXT_texture3D", EXT_TEXTURE3D },
{"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC },
{"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC },
{"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE },
{"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3 },
{"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC},
{"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS },
{"GL_EXT_texture_mirror_clamp", EXT_TEXTURE_MIRROR_CLAMP },
{"GL_EXT_texture_snorm", EXT_TEXTURE_SNORM },
{"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB },
{"GL_EXT_texture_sRGB_decode", EXT_TEXTURE_SRGB_DECODE },
{"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA },
/* NV */
{"GL_NV_fence", NV_FENCE },
{"GL_NV_fog_distance", NV_FOG_DISTANCE },
{"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM },
{"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2 },
{"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION },
{"GL_NV_half_float", NV_HALF_FLOAT },
{"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT },
{"GL_NV_point_sprite", NV_POINT_SPRITE },
{"GL_NV_register_combiners", NV_REGISTER_COMBINERS },
{"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2 },
{"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION },
{"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4 },
{"GL_NV_texture_shader", NV_TEXTURE_SHADER },
{"GL_NV_texture_shader2", NV_TEXTURE_SHADER2 },
{"GL_NV_vertex_program", NV_VERTEX_PROGRAM },
{"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1 },
{"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2 },
{"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION },
{"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3 },
/* SGI */
{"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP },
};
static const struct wined3d_extension_map wgl_extension_map[] =
{
{"WGL_ARB_pixel_format", WGL_ARB_PIXEL_FORMAT },
{"WGL_EXT_swap_control", WGL_EXT_SWAP_CONTROL },
{"WGL_WINE_pixel_format_passthrough", WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
};
/**********************************************************
* Utility functions follow
**********************************************************/
const struct min_lookup minMipLookup[] =
{
/* NONE POINT LINEAR */
{{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
{{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
{{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
};
const GLenum magLookup[] =
{
/* NONE POINT LINEAR */
GL_NEAREST, GL_NEAREST, GL_LINEAR,
};
static void wined3d_caps_gl_ctx_destroy(const struct wined3d_caps_gl_ctx *ctx)
{
const struct wined3d_gl_info *gl_info = ctx->gl_info;
TRACE("Destroying caps GL context.\n");
/* Both glDeleteProgram and glDeleteBuffers silently ignore 0 IDs but
* this function might be called before the relevant function pointers
* in gl_info are initialized. */
if (ctx->test_program_id || ctx->test_vbo)
{
GL_EXTCALL(glDeleteProgram(ctx->test_program_id));
GL_EXTCALL(glDeleteBuffers(1, &ctx->test_vbo));
}
if (!wglMakeCurrent(NULL, NULL))
ERR("Failed to disable caps GL context.\n");
if (!wglDeleteContext(ctx->gl_ctx))
{
DWORD err = GetLastError();
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
}
wined3d_release_dc(ctx->wnd, ctx->dc);
DestroyWindow(ctx->wnd);
if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
ERR("Failed to restore previous GL context.\n");
}
static BOOL wined3d_caps_gl_ctx_create_attribs(struct wined3d_caps_gl_ctx *caps_gl_ctx,
struct wined3d_gl_info *gl_info)
{
HGLRC new_ctx;
if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
return TRUE;
if (!(new_ctx = context_create_wgl_attribs(gl_info, caps_gl_ctx->dc, NULL)))
{
gl_info->p_wglCreateContextAttribsARB = NULL;
return FALSE;
}
if (!wglMakeCurrent(caps_gl_ctx->dc, new_ctx))
{
ERR("Failed to make new context current, last error %#x.\n", GetLastError());
if (!wglDeleteContext(new_ctx))
ERR("Failed to delete new context, last error %#x.\n", GetLastError());
gl_info->p_wglCreateContextAttribsARB = NULL;
return TRUE;
}
if (!wglDeleteContext(caps_gl_ctx->gl_ctx))
ERR("Failed to delete old context, last error %#x.\n", GetLastError());
caps_gl_ctx->gl_ctx = new_ctx;
return TRUE;
}
static BOOL wined3d_caps_gl_ctx_create(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx)
{
PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat;
TRACE("getting context...\n");
ctx->restore_dc = wglGetCurrentDC();
ctx->restore_gl_ctx = wglGetCurrentContext();
/* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
if (!ctx->wnd)
{
ERR("Failed to create a window.\n");
goto fail;
}
ctx->dc = GetDC(ctx->wnd);
if (!ctx->dc)
{
ERR("Failed to get a DC.\n");
goto fail;
}
/* PixelFormat selection */
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
if (!(iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd)))
{
/* If this happens something is very wrong as ChoosePixelFormat barely fails. */
ERR("Failed to find a suitable pixel format.\n");
goto fail;
}
DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
/* Create a GL context. */
if (!(ctx->gl_ctx = wglCreateContext(ctx->dc)))
{
WARN("Failed to create default context for capabilities initialization.\n");
goto fail;
}
/* Make it the current GL context. */
if (!wglMakeCurrent(ctx->dc, ctx->gl_ctx))
{
ERR("Failed to make caps GL context current.\n");
goto fail;
}
ctx->gl_info = &adapter->gl_info;
return TRUE;
fail:
if (ctx->gl_ctx) wglDeleteContext(ctx->gl_ctx);
ctx->gl_ctx = NULL;
if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
ctx->dc = NULL;
if (ctx->wnd) DestroyWindow(ctx->wnd);
ctx->wnd = NULL;
if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
ERR("Failed to restore previous GL context.\n");
return FALSE;
}
/* Adjust the amount of used texture memory */
UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
{
adapter->vram_bytes_used += amount;
TRACE("Adjusted used adapter memory by 0x%s to 0x%s.\n",
wine_dbgstr_longlong(amount),
wine_dbgstr_longlong(adapter->vram_bytes_used));
return adapter->vram_bytes_used;
}
static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
{
HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
HeapFree(GetProcessHeap(), 0, adapter->cfgs);
}
ULONG CDECL wined3d_incref(struct wined3d *wined3d)
{
ULONG refcount = InterlockedIncrement(&wined3d->ref);
TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
return refcount;
}
ULONG CDECL wined3d_decref(struct wined3d *wined3d)
{
ULONG refcount = InterlockedDecrement(&wined3d->ref);
TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
if (!refcount)
{
unsigned int i;
for (i = 0; i < wined3d->adapter_count; ++i)
{
wined3d_adapter_cleanup(&wined3d->adapters[i]);
}
HeapFree(GetProcessHeap(), 0, wined3d);
}
return refcount;
}
/* Context activation is done by the caller. */
static BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
{
GLuint prog;
BOOL ret = FALSE;
static const char testcode[] =
"!!ARBvp1.0\n"
"PARAM C[66] = { program.env[0..65] };\n"
"ADDRESS A0;"
"PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
"ARL A0.x, zero.x;\n"
"MOV result.position, C[A0.x + 65];\n"
"END\n";
while (gl_info->gl_ops.gl.p_glGetError());
GL_EXTCALL(glGenProgramsARB(1, &prog));
if(!prog) {
ERR("Failed to create an ARB offset limit test program\n");
}
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(testcode), testcode));
if (gl_info->gl_ops.gl.p_glGetError())
{
TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
ret = TRUE;
} else TRACE("OpenGL implementation allows offsets > 63\n");
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
GL_EXTCALL(glDeleteProgramsARB(1, &prog));
checkGLcall("ARB vp offset limit test cleanup");
return ret;
}
static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
if (card_vendor != HW_VENDOR_AMD) return FALSE;
if (device == CARD_AMD_RADEON_9500) return TRUE;
if (device == CARD_AMD_RADEON_X700) return TRUE;
if (device == CARD_AMD_RADEON_X1600) return TRUE;
return FALSE;
}
static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
if (card_vendor == HW_VENDOR_NVIDIA)
{
if (device == CARD_NVIDIA_GEFORCEFX_5200 ||
device == CARD_NVIDIA_GEFORCEFX_5600 ||
device == CARD_NVIDIA_GEFORCEFX_5800)
{
return TRUE;
}
}
return FALSE;
}
static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
/* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
* the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
* detect the Apple OpenGL implementation to apply some extension fixups afterwards.
*
* Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
* aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
* So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
* like client storage might be supported on other implementations too, but GL_APPLE_flush_render
* is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
* the chance that other implementations support them is rather small since Win32 QuickTime uses
* DirectDraw, not OpenGL.
*
* This test has been moved into wined3d_guess_gl_vendor()
*/
if (gl_vendor == GL_VENDOR_APPLE)
{
return TRUE;
}
return FALSE;
}
/* Context activation is done by the caller. */
static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
{
/* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
* but glTexSubImage from a PBO fails miserably, with the first line repeated over
* all the texture. This function detects this bug by its symptom and disables PBOs
* if the test fails.
*
* The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
* GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
* for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
* read back is compared to the original. If they are equal PBOs are assumed to work,
* otherwise the PBO extension is disabled. */
GLuint texture, pbo;
static const unsigned int pattern[] =
{
0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
};
unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
/* No PBO -> No point in testing them. */
if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
while (gl_info->gl_ops.gl.p_glGetError());
gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
checkGLcall("Specifying the PBO test texture");
GL_EXTCALL(glGenBuffers(1, &pbo));
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo));
GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(pattern), pattern, GL_STREAM_DRAW));
checkGLcall("Specifying the PBO test pbo");
gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
checkGLcall("Loading the PBO test texture");
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
gl_info->gl_ops.gl.p_glFinish(); /* just to be sure */
memset(check, 0, sizeof(check));
gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
checkGLcall("Reading back the PBO test texture");
gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
GL_EXTCALL(glDeleteBuffers(1, &pbo));
checkGLcall("PBO test cleanup");
if (memcmp(check, pattern, sizeof(check)))
{
WARN_(d3d_perf)("PBO test failed, read back data doesn't match original.\n"
"Disabling PBOs. This may result in slower performance.\n");
gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
}
else
{
TRACE("PBO test successful.\n");
}
}
static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
}
static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
if (card_vendor != HW_VENDOR_AMD) return FALSE;
if (device == CARD_AMD_RADEON_X1600) return FALSE;
return TRUE;
}
static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
/* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
* 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
* This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
* varyings and we subtract one in dx9 shaders it's not going to hurt us because the dx9 limit is
* hardcoded
*
* dx10 cards usually have 64 varyings */
return gl_info->limits.glsl_varyings > 44;
}
static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device);
}
/* A GL context is provided by the caller */
static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
GLenum error;
DWORD data[16];
if (!gl_info->supported[EXT_SECONDARY_COLOR])
return FALSE;
while (gl_info->gl_ops.gl.p_glGetError());
GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
error = gl_info->gl_ops.gl.p_glGetError();
if (error == GL_NO_ERROR)
{
TRACE("GL Implementation accepts 4 component specular color pointers\n");
return TRUE;
}
else
{
TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
debug_glerror(error));
return FALSE;
}
}
/* A GL context is provided by the caller */
static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
GLuint prog;
BOOL ret = FALSE;
GLint pos;
static const char testcode[] =
"!!ARBvp1.0\n"
"OPTION NV_vertex_program2;\n"
"MOV result.clip[0], 0.0;\n"
"MOV result.position, 0.0;\n"
"END\n";
if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
while (gl_info->gl_ops.gl.p_glGetError());
GL_EXTCALL(glGenProgramsARB(1, &prog));
if(!prog)
{
ERR("Failed to create the NVvp clip test program\n");
return FALSE;
}
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(testcode), testcode));
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if(pos != -1)
{
WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
ret = TRUE;
while (gl_info->gl_ops.gl.p_glGetError());
}
else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
GL_EXTCALL(glDeleteProgramsARB(1, &prog));
checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
return ret;
}
/* Context activation is done by the caller. */
static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
char data[4 * 4 * 4];
GLuint tex, fbo;
GLenum status;
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
memset(data, 0xcc, sizeof(data));
gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
checkGLcall("glTexImage2D");
gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
checkGLcall("glFramebufferTexture2D");
status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
checkGLcall("glCheckFramebufferStatus");
memset(data, 0x11, sizeof(data));
gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
checkGLcall("glTexSubImage2D");
gl_info->gl_ops.gl.p_glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
checkGLcall("glClear");
gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
checkGLcall("glGetTexImage");
gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
checkGLcall("glBindTexture");
gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
checkGLcall("glDeleteTextures");
return *(DWORD *)data == 0x11111111;
}
/* Context activation is done by the caller. */
static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
/* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
* This leads to graphical bugs in Half Life 2 and Unreal engine games. */
GLuint tex;
GLint size;
gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
checkGLcall("glTexImage2D");
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
checkGLcall("glGetTexLevelParameteriv");
TRACE("Real color depth is %d\n", size);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
checkGLcall("glBindTexture");
gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
checkGLcall("glDeleteTextures");
return size < 16;
}
static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
return gl_vendor == GL_VENDOR_FGLRX;
}
static BOOL match_r200(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
if (card_vendor != HW_VENDOR_AMD) return FALSE;
if (device == CARD_AMD_RADEON_8500) return TRUE;
return FALSE;
}
static BOOL match_broken_arb_fog(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
{
DWORD data[4];
GLuint tex, fbo;
GLenum status;
float color[4] = {0.0f, 1.0f, 0.0f, 0.0f};
GLuint prog;
GLint err_pos;
static const char program_code[] =
"!!ARBfp1.0\n"
"OPTION ARB_fog_linear;\n"
"MOV result.color, {1.0, 0.0, 0.0, 0.0};\n"
"END\n";
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
return FALSE;
if (!gl_info->supported[ARB_FRAGMENT_PROGRAM])
return FALSE;
gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 1, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
checkGLcall("glTexImage2D");
gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
checkGLcall("glFramebufferTexture2D");
status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
checkGLcall("glCheckFramebufferStatus");
gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
checkGLcall("glClear");
gl_info->gl_ops.gl.p_glViewport(0, 0, 4, 1);
checkGLcall("glViewport");
gl_info->gl_ops.gl.p_glEnable(GL_FOG);
gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, 0.5f);
gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, 0.5f);
gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, color);
checkGLcall("fog setup");
GL_EXTCALL(glGenProgramsARB(1, &prog));
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog));
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(program_code), program_code));
gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_PROGRAM_ARB);
checkGLcall("Test fragment program setup");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos);
if (err_pos != -1)
{
const char *error_str;
error_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB);
FIXME("Fog test program error at position %d: %s\n\n", err_pos, debugstr_a(error_str));
}
gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
gl_info->gl_ops.gl.p_glVertex3f( 1.0f, -1.0f, 1.0f);
gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
gl_info->gl_ops.gl.p_glVertex3f( 1.0f, 1.0f, 1.0f);
gl_info->gl_ops.gl.p_glEnd();
checkGLcall("ARBfp fog test draw");
gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
checkGLcall("glGetTexImage");
data[0] &= 0x00ffffff;
data[1] &= 0x00ffffff;
data[2] &= 0x00ffffff;
data[3] &= 0x00ffffff;
gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
gl_info->gl_ops.gl.p_glDisable(GL_FOG);
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_PROGRAM_ARB);
GL_EXTCALL(glDeleteProgramsARB(1, &prog));
checkGLcall("ARBfp fog test teardown");
TRACE("Fog test data: %08x %08x %08x %08x\n", data[0], data[1], data[2], data[3]);
return data[0] != 0x00ff0000 || data[3] != 0x0000ff00;
}
static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
{
/* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
* Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
* allow 48 different offsets or other helper immediate values. */
TRACE("Reserving 12 GLSL constants for compiler private use.\n");
gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
}
static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
{
/* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
* these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
* If real NP2 textures are used, the driver falls back to software. We could just remove the
* extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient
* due to the non-normalized texture coordinates. Thus set an internal extension flag,
* GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
* as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
*
* fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
* has this extension promoted to core. The extension loading code sets this extension supported
* due to that, so this code works on fglrx as well. */
if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
{
TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
}
}
static void quirk_no_np2(struct wined3d_gl_info *gl_info)
{
/* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
* doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
* This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
* within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
* FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
* We therefore completely remove ARB_tex_npot from the list of supported extensions.
*
* Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
* triggering the software fallback. There is not much we can do here apart from disabling the
* software-emulated extension and re-enable ARB_tex_rect (which was previously disabled
* in wined3d_adapter_init_gl_caps).
* This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
* post-processing effects in the game "Max Payne 2").
* The behaviour can be verified through a simple test app attached in bugreport #14724. */
TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
}
static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
{
/* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
* with fixed function fragment processing. Ideally this flag should be detected with a test shader
* and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
* do not like vertex shaders in feedback mode and return an error, even though it should be valid
* according to the spec.
*
* We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
* makes the shader slower and eats instruction slots which should be available to the d3d app.
*
* ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
* all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
* this workaround is activated on cards that do not need it, it won't break things, just affect
* performance negatively. */
TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
}
static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
}
static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
}
static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
}
static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
}
static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
}
static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
}
static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
{
/* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few
selected texture formats. They are apparently the only DX9 class GPUs
supporting VTF.
Also, DX9-era GPUs are somewhat limited with float textures
filtering and blending. */
gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
}
static void quirk_r200_constants(struct wined3d_gl_info *gl_info)
{
/* The Mesa r200 driver (and there is no other driver for this GPU Wine would run on)
* loads some fog parameters (start, end, exponent, but not the color) into the
* program.
*
* Apparently the fog hardware is only able to handle linear fog with a range of 0.0;1.0,
* and it is the responsibility of the vertex pipeline to handle non-linear fog and
* linear fog with start and end other than 0.0 and 1.0. */
TRACE("Reserving 1 ARB constant for compiler private use.\n");
gl_info->reserved_arb_constants = max(gl_info->reserved_arb_constants, 1);
}
static void quirk_broken_arb_fog(struct wined3d_gl_info *gl_info)
{
gl_info->quirks |= WINED3D_QUIRK_BROKEN_ARB_FOG;