📄 directx.c
字号:
}
*ppobj = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
IWineD3DImpl *This = (IWineD3DImpl *)iface;
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
return refCount;
}
static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
IWineD3DImpl *This = (IWineD3DImpl *)iface;
ULONG ref;
TRACE("(%p) : Releasing from %d\n", This, This->ref);
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
/* Set the shader type for this device, depending on the given capabilities,
* the device type, and the user preferences in wined3d_settings */
static void select_shader_mode(
WineD3D_GL_Info *gl_info,
WINED3DDEVTYPE DeviceType,
int* ps_selected,
int* vs_selected) {
if (wined3d_settings.vs_mode == VS_NONE) {
*vs_selected = SHADER_NONE;
} else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
*vs_selected = SHADER_GLSL;
} else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
*vs_selected = SHADER_ARB;
} else {
*vs_selected = SHADER_NONE;
}
if (wined3d_settings.ps_mode == PS_NONE) {
*ps_selected = SHADER_NONE;
} else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
*ps_selected = SHADER_GLSL;
} else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
*ps_selected = SHADER_ARB;
} else {
*ps_selected = SHADER_NONE;
}
}
/** Select the number of report maximum shader constants based on the selected shader modes */
static void select_shader_max_constants(
int ps_selected_mode,
int vs_selected_mode,
WineD3D_GL_Info *gl_info) {
switch (vs_selected_mode) {
case SHADER_GLSL:
/* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
break;
case SHADER_ARB:
/* We have to subtract any other PARAMs that we might use in our shader programs.
* ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
* and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
break;
default:
gl_info->max_vshader_constantsF = 0;
break;
}
switch (ps_selected_mode) {
case SHADER_GLSL:
/* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
* In theory the texbem instruction may need one more shader constant too. But lets assume
* that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
* and lets not take away a uniform needlessly from all other shaders.
*/
gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
break;
case SHADER_ARB:
/* The arb shader only loads the bump mapping environment matrix into the shader if it finds
* a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
*/
gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
break;
default:
gl_info->max_pshader_constantsF = 0;
break;
}
}
/**********************************************************
* IWineD3D parts follows
**********************************************************/
#define GLINFO_LOCATION (*gl_info)
BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
const char *GL_Extensions = NULL;
const char *WGL_Extensions = NULL;
const char *gl_string = NULL;
const char *gl_string_cursor = NULL;
GLint gl_max;
GLfloat gl_floatv[2];
int major = 1, minor = 0;
BOOL return_value = TRUE;
int i;
HDC hdc;
HMODULE mod_gl;
#ifdef USE_WIN32_OPENGL
#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
mod_gl = LoadLibraryA("opengl32.dll");
if(!mod_gl) {
ERR("Can't load opengl32.dll!\n");
return FALSE;
}
#else
#define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
/* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
mod_gl = GetModuleHandleA("gdi32.dll");
#endif
/* Load WGL core functions from opengl32.dll */
#define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
WGL_FUNCS_GEN;
#undef USE_WGL_FUNC
if(!pwglGetProcAddress) {
ERR("Unable to load wglGetProcAddress!\n");
return FALSE;
}
/* Dynamicly load all GL core functions */
GL_FUNCS_GEN;
#undef USE_GL_FUNC
/* Make sure that we've got a context */
/* TODO: CreateFakeGLContext should really take a display as a parameter */
/* Only save the values obtained when a display is provided */
if (!WineD3D_CreateFakeGLContext() || wined3d_fake_gl_context_foreign)
return_value = FALSE;
TRACE_(d3d_caps)("(%p)\n", gl_info);
gl_string = (const char *) glGetString(GL_RENDERER);
if (NULL == gl_string)
gl_string = "None";
strcpy(gl_info->gl_renderer, gl_string);
gl_string = (const char *) glGetString(GL_VENDOR);
TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
if (gl_string != NULL) {
/* Fill in the GL vendor */
if (strstr(gl_string, "NVIDIA")) {
gl_info->gl_vendor = VENDOR_NVIDIA;
} else if (strstr(gl_string, "ATI")) {
gl_info->gl_vendor = VENDOR_ATI;
} else if (strstr(gl_string, "Intel(R)") ||
strstr(gl_info->gl_renderer, "Intel(R)")) {
gl_info->gl_vendor = VENDOR_INTEL;
} else if (strstr(gl_string, "Mesa")) {
gl_info->gl_vendor = VENDOR_MESA;
} else {
gl_info->gl_vendor = VENDOR_WINE;
}
} else {
gl_info->gl_vendor = VENDOR_WINE;
}
TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
/* Parse the GL_VERSION field into major and minor information */
gl_string = (const char *) glGetString(GL_VERSION);
if (gl_string != NULL) {
switch (gl_info->gl_vendor) {
case VENDOR_NVIDIA:
gl_string_cursor = strstr(gl_string, "NVIDIA");
if (!gl_string_cursor) {
ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
break;
}
gl_string_cursor = strstr(gl_string_cursor, " ");
if (!gl_string_cursor) {
ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
break;
}
while (*gl_string_cursor == ' ') {
++gl_string_cursor;
}
if (!*gl_string_cursor) {
ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
break;
}
major = atoi(gl_string_cursor);
while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
++gl_string_cursor;
}
if (*gl_string_cursor++ != '.') {
ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
break;
}
minor = atoi(gl_string_cursor);
minor = major*100+minor;
major = 10;
break;
case VENDOR_ATI:
major = minor = 0;
gl_string_cursor = strchr(gl_string, '-');
if (gl_string_cursor) {
int error = 0;
gl_string_cursor++;
/* Check if version number is of the form x.y.z */
if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
error = 1;
if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
error = 1;
if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
error = 1;
if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
error = 1;
/* Mark version number as malformed */
if (error)
gl_string_cursor = 0;
}
if (!gl_string_cursor)
WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
else {
major = *gl_string_cursor - '0';
minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
}
break;
case VENDOR_INTEL:
case VENDOR_MESA:
gl_string_cursor = strstr(gl_string, "Mesa");
gl_string_cursor = strstr(gl_string_cursor, " ");
while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
if (*gl_string_cursor) {
char tmp[16];
int cursor = 0;
while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
tmp[cursor++] = *gl_string_cursor;
++gl_string_cursor;
}
tmp[cursor] = 0;
major = atoi(tmp);
if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
++gl_string_cursor;
cursor = 0;
while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
tmp[cursor++] = *gl_string_cursor;
++gl_string_cursor;
}
tmp[cursor] = 0;
minor = atoi(tmp);
}
break;
default:
major = 0;
minor = 9;
}
gl_info->gl_driver_version = MAKEDWORD_VERSION(major, minor);
TRACE_(d3d_caps)("found GL_VERSION (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->gl_driver_version);
}
TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -