mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
[D3DX9_36_WINETEST] Import from wine 4.0
This commit is contained in:
parent
c530f34e79
commit
e404e9ee2f
18 changed files with 36156 additions and 0 deletions
|
@ -35,6 +35,7 @@ add_subdirectory(cryptnet)
|
|||
add_subdirectory(cryptui)
|
||||
add_subdirectory(d3dcompiler_43)
|
||||
add_subdirectory(d3drm)
|
||||
add_subdirectory(d3dx9_36)
|
||||
add_subdirectory(devenum)
|
||||
add_subdirectory(dinput)
|
||||
add_subdirectory(dinput8)
|
||||
|
|
25
modules/rostests/winetests/d3dx9_36/CMakeLists.txt
Normal file
25
modules/rostests/winetests/d3dx9_36/CMakeLists.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
add_executable(d3dx9_36_winetest
|
||||
asm.c
|
||||
core.c
|
||||
effect.c
|
||||
line.c
|
||||
math.c
|
||||
mesh.c
|
||||
shader.c
|
||||
surface.c
|
||||
texture.c
|
||||
volume.c
|
||||
xfile.c
|
||||
testlist.c
|
||||
rsrc.rc)
|
||||
target_compile_definitions(d3dx9_36_winetest PRIVATE -DUSE_WINE_TODOS -D__WINESRC__ -Disnan=_isnan)
|
||||
if(MSVC)
|
||||
# Disable warning C4477 (printf format warnings)
|
||||
target_compile_options(d3dx9_36_winetest PRIVATE "/wd4477")
|
||||
endif()
|
||||
|
||||
target_link_libraries(d3dx9_36_winetest uuid dxguid)
|
||||
set_module_type(d3dx9_36_winetest win32cui)
|
||||
add_importlibs(d3dx9_36_winetest d3dx9_36 d3d9 user32 gdi32 msvcrt kernel32)
|
||||
add_rostests_file(TARGET d3dx9_36_winetest)
|
583
modules/rostests/winetests/d3dx9_36/asm.c
Normal file
583
modules/rostests/winetests/d3dx9_36/asm.c
Normal file
|
@ -0,0 +1,583 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Stefan Dösinger
|
||||
* Copyright (C) 2009 Matteo Bruni
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
#define COBJMACROS
|
||||
#define CONST_VTABLE
|
||||
#include "wine/test.h"
|
||||
|
||||
#include <d3dx9.h>
|
||||
|
||||
#include "resources.h"
|
||||
|
||||
static char temp_path[MAX_PATH];
|
||||
|
||||
static BOOL create_file(const char *filename, const char *data, const unsigned int size, char *out_path)
|
||||
{
|
||||
DWORD written;
|
||||
HANDLE hfile;
|
||||
char path[MAX_PATH];
|
||||
|
||||
if (!*temp_path)
|
||||
GetTempPathA(sizeof(temp_path), temp_path);
|
||||
|
||||
strcpy(path, temp_path);
|
||||
strcat(path, filename);
|
||||
hfile = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hfile == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
|
||||
if (WriteFile(hfile, data, size, &written, NULL))
|
||||
{
|
||||
CloseHandle(hfile);
|
||||
|
||||
if (out_path)
|
||||
strcpy(out_path, path);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CloseHandle(hfile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void delete_file(const char *filename)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
|
||||
strcpy(path, temp_path);
|
||||
strcat(path, filename);
|
||||
DeleteFileA(path);
|
||||
}
|
||||
|
||||
static BOOL create_directory(const char *name)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
|
||||
strcpy(path, temp_path);
|
||||
strcat(path, name);
|
||||
return CreateDirectoryA(path, NULL);
|
||||
}
|
||||
|
||||
static void delete_directory(const char *name)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
|
||||
strcpy(path, temp_path);
|
||||
strcat(path, name);
|
||||
RemoveDirectoryA(path);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI testD3DXInclude_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE include_type,
|
||||
const char *filename, const void *parent_data, const void **data, UINT *bytes)
|
||||
{
|
||||
char *buffer;
|
||||
static const char shader[] =
|
||||
"#include \"incl.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char include[] = "#define REGISTER r0\nvs.1.1\n";
|
||||
static const char include2[] = "#include \"incl3.vsh\"\n";
|
||||
static const char include3[] = "vs.1.1\n";
|
||||
|
||||
trace("filename %s.\n", filename);
|
||||
trace("parent_data %p: %s.\n", parent_data, parent_data ? (char *)parent_data : "(null)");
|
||||
|
||||
if (!strcmp(filename, "shader.vsh"))
|
||||
{
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(shader));
|
||||
memcpy(buffer, shader, sizeof(shader));
|
||||
*bytes = sizeof(shader);
|
||||
}
|
||||
else if (!strcmp(filename, "incl.vsh"))
|
||||
{
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
|
||||
memcpy(buffer, include, sizeof(include));
|
||||
*bytes = sizeof(include);
|
||||
/* This is included from the first D3DXAssembleShader with non-null ID3DXInclude test
|
||||
* (parent_data == NULL) and from shader.vsh / shader[] (with matching parent_data).
|
||||
* Allow both cases. */
|
||||
ok(parent_data == NULL || !strncmp(shader, parent_data, strlen(shader)), "wrong parent_data value\n");
|
||||
}
|
||||
else if (!strcmp(filename, "incl2.vsh"))
|
||||
{
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include2));
|
||||
memcpy(buffer, include2, sizeof(include2));
|
||||
*bytes = sizeof(include2);
|
||||
}
|
||||
else if (!strcmp(filename, "incl3.vsh"))
|
||||
{
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include3));
|
||||
memcpy(buffer, include3, sizeof(include3));
|
||||
*bytes = sizeof(include3);
|
||||
/* Also check for the correct parent_data content */
|
||||
ok(parent_data != NULL && !strncmp(include2, parent_data, strlen(include2)), "wrong parent_data value\n");
|
||||
}
|
||||
else if (!strcmp(filename, "include/incl3.vsh"))
|
||||
{
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
|
||||
memcpy(buffer, include, sizeof(include));
|
||||
*bytes = sizeof(include);
|
||||
ok(!parent_data, "wrong parent_data value\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ok(0, "Unexpected #include for file %s.\n", filename);
|
||||
return D3DERR_INVALIDCALL;
|
||||
}
|
||||
*data = buffer;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI testD3DXInclude_close(ID3DXInclude *iface, const void *data)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, (void *)data);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl = {
|
||||
testD3DXInclude_open,
|
||||
testD3DXInclude_close
|
||||
};
|
||||
|
||||
struct D3DXIncludeImpl {
|
||||
ID3DXInclude ID3DXInclude_iface;
|
||||
};
|
||||
|
||||
static void assembleshader_test(void)
|
||||
{
|
||||
static const char test1[] =
|
||||
"vs.1.1\n"
|
||||
"mov DEF2, v0\n";
|
||||
static const char testincl[] =
|
||||
"#define REGISTER r0\n"
|
||||
"vs.1.1\n";
|
||||
static const char testshader[] =
|
||||
"#include \"incl.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char testshader2[] =
|
||||
"#include \"incl2.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char testshader3[] =
|
||||
"#include \"include/incl3.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char testincl3[] =
|
||||
"#include \"incl4.vsh\"\n";
|
||||
static const char testincl4_ok[] =
|
||||
"#define REGISTER r0\n"
|
||||
"vs.1.1\n";
|
||||
static const char testincl4_wrong[] =
|
||||
"#error \"wrong include\"\n";
|
||||
HRESULT hr;
|
||||
ID3DXBuffer *shader, *messages;
|
||||
static const D3DXMACRO defines[] = {
|
||||
{
|
||||
"DEF1", "10 + 15"
|
||||
},
|
||||
{
|
||||
"DEF2", "r0"
|
||||
},
|
||||
{
|
||||
NULL, NULL
|
||||
}
|
||||
};
|
||||
struct D3DXIncludeImpl include;
|
||||
char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH];
|
||||
static const WCHAR shader_filename_w[] = {'s','h','a','d','e','r','.','v','s','h',0};
|
||||
|
||||
/* pDefines test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(test1, strlen(test1),
|
||||
defines, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "pDefines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* NULL messages test */
|
||||
shader = NULL;
|
||||
hr = D3DXAssembleShader(test1, strlen(test1),
|
||||
defines, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, NULL);
|
||||
ok(hr == D3D_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* NULL shader test */
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(test1, strlen(test1),
|
||||
defines, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
NULL, &messages);
|
||||
ok(hr == D3D_OK, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
|
||||
/* pInclude test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
include.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
|
||||
hr = D3DXAssembleShader(testshader, strlen(testshader), NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* "unexpected #include file from memory" test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(testshader, strlen(testshader),
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* recursive #include test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(testshader2, strlen(testshader2), NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("recursive D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* #include with a path. */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(testshader3, strlen(testshader3), NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000ffff);
|
||||
if (messages)
|
||||
{
|
||||
trace("Path search D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if (shader)
|
||||
ID3DXBuffer_Release(shader);
|
||||
|
||||
if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path))
|
||||
{
|
||||
create_file("incl.vsh", testincl, sizeof(testincl) - 1, NULL);
|
||||
|
||||
/* D3DXAssembleShaderFromFile + #include test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileA(shader_vsh_path,
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromFile test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXAssembleShaderFromFile + pInclude test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileA("shader.vsh", NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromFile + pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
create_file("shader3.vsh", testshader3, sizeof(testshader3) - 1, shader3_vsh_path);
|
||||
create_file("incl4.vsh", testincl4_wrong, sizeof(testincl4_wrong) - 1, NULL);
|
||||
if (create_directory("include"))
|
||||
{
|
||||
create_file("include\\incl3.vsh", testincl3, sizeof(testincl3) - 1, NULL);
|
||||
create_file("include\\incl4.vsh", testincl4_ok, sizeof(testincl4_ok) - 1, NULL);
|
||||
|
||||
/* path search #include test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileA(shader3_vsh_path, NULL, NULL,
|
||||
D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromFile path search test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShaderFromFile path search messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
} else skip("Couldn't create \"include\" directory\n");
|
||||
|
||||
delete_file("shader.vsh");
|
||||
delete_file("incl.vsh");
|
||||
delete_file("shader3.vsh");
|
||||
delete_file("incl4.vsh");
|
||||
delete_file("include\\incl3.vsh");
|
||||
delete_file("include\\incl4.vsh");
|
||||
delete_directory("include");
|
||||
|
||||
/* The main shader is also to be loaded through the ID3DXInclude object. */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileA("shader.vsh", NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromFile + pInclude main shader test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000ffff);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if (shader)
|
||||
ID3DXBuffer_Release(shader);
|
||||
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileW(shader_filename_w, NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromFile + pInclude main shader test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000ffff);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if (shader)
|
||||
ID3DXBuffer_Release(shader);
|
||||
} else skip("Couldn't create \"shader.vsh\"\n");
|
||||
|
||||
/* NULL shader tests */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShader(NULL, 0,
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromFileA("nonexistent.vsh",
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA || hr == E_FAIL, /* I get this on WinXP */
|
||||
"D3DXAssembleShaderFromFile nonexistent file test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShaderFromFile messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXAssembleShaderFromResource test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromResourceA(NULL, MAKEINTRESOURCEA(IDB_ASMSHADER),
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShaderFromResource test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXAssembleShaderFromResource with missing shader resource test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXAssembleShaderFromResourceA(NULL, "notexisting",
|
||||
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA, "D3DXAssembleShaderFromResource NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXAssembleShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
}
|
||||
|
||||
static void d3dxpreprocess_test(void)
|
||||
{
|
||||
static const char testincl[] =
|
||||
"#define REGISTER r0\n"
|
||||
"vs.1.1\n";
|
||||
static const char testshader[] =
|
||||
"#include \"incl.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char testshader3[] =
|
||||
"#include \"include/incl3.vsh\"\n"
|
||||
"mov REGISTER, v0\n";
|
||||
static const char testincl3[] =
|
||||
"#include \"incl4.vsh\"\n";
|
||||
static const char testincl4_ok[] =
|
||||
"#define REGISTER r0\n"
|
||||
"vs.1.1\n";
|
||||
static const char testincl4_wrong[] =
|
||||
"#error \"wrong include\"\n";
|
||||
HRESULT hr;
|
||||
ID3DXBuffer *shader, *messages;
|
||||
char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH];
|
||||
static struct D3DXIncludeImpl include = {{&D3DXInclude_Vtbl}};
|
||||
static const WCHAR shader_filename_w[] = {'s','h','a','d','e','r','.','v','s','h',0};
|
||||
|
||||
if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path))
|
||||
{
|
||||
create_file("incl.vsh", testincl, sizeof(testincl) - 1, NULL);
|
||||
create_file("shader3.vsh", testshader3, sizeof(testshader3) - 1, shader3_vsh_path);
|
||||
create_file("incl4.vsh", testincl4_wrong, sizeof(testincl4_wrong) - 1, NULL);
|
||||
if (create_directory("include"))
|
||||
{
|
||||
create_file("include\\incl3.vsh", testincl3, sizeof(testincl3) - 1, NULL);
|
||||
create_file("include\\incl4.vsh", testincl4_ok, sizeof(testincl4_ok) - 1, NULL);
|
||||
|
||||
/* path search #include test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileA(shader3_vsh_path, NULL, NULL,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromFile path search test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShaderFromFile path search messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
} else skip("Couldn't create \"include\" directory\n");
|
||||
|
||||
/* D3DXPreprocessShaderFromFile + #include test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileA(shader_vsh_path,
|
||||
NULL, NULL,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromFile test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXPreprocessShaderFromFile + pInclude test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileA("shader.vsh", NULL, &include.ID3DXInclude_iface,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromFile + pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
delete_file("shader.vsh");
|
||||
delete_file("incl.vsh");
|
||||
delete_file("shader3.vsh");
|
||||
delete_file("incl4.vsh");
|
||||
delete_file("include\\incl3.vsh");
|
||||
delete_file("include\\incl4.vsh");
|
||||
delete_directory("include");
|
||||
|
||||
/* The main shader is also to be loaded through the ID3DXInclude object. */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileA("shader.vsh", NULL, &include.ID3DXInclude_iface,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromFile + pInclude main shader test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000ffff);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DXPreprocessShaderFromFile messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if (shader)
|
||||
ID3DXBuffer_Release(shader);
|
||||
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileW(shader_filename_w, NULL, &include.ID3DXInclude_iface,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromFile + pInclude main shader test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000ffff);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DXPreprocessShaderFromFile messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if (shader)
|
||||
ID3DXBuffer_Release(shader);
|
||||
} else skip("Couldn't create \"shader.vsh\"\n");
|
||||
|
||||
/* NULL shader tests */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromFileA("nonexistent.vsh",
|
||||
NULL, NULL,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA || hr == E_FAIL, /* I get this on WinXP */
|
||||
"D3DXPreprocessShaderFromFile nonexistent file test failed with error 0x%x - %d\n",
|
||||
hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShaderFromFile messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXPreprocessShaderFromResource test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromResourceA(NULL, MAKEINTRESOURCEA(IDB_ASMSHADER),
|
||||
NULL, NULL,
|
||||
&shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXPreprocessShaderFromResource test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
|
||||
/* D3DXPreprocessShaderFromResource with missing shader resource test */
|
||||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DXPreprocessShaderFromResourceA(NULL, "notexisting",
|
||||
NULL, NULL,
|
||||
&shader, &messages);
|
||||
ok(hr == D3DXERR_INVALIDDATA, "D3DXPreprocessShaderFromResource NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("D3DXPreprocessShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
}
|
||||
if(shader) ID3DXBuffer_Release(shader);
|
||||
}
|
||||
|
||||
START_TEST(asm)
|
||||
{
|
||||
assembleshader_test();
|
||||
|
||||
d3dxpreprocess_test();
|
||||
}
|
BIN
modules/rostests/winetests/d3dx9_36/bmp1x1.bmp
Normal file
BIN
modules/rostests/winetests/d3dx9_36/bmp1x1.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 58 B |
1310
modules/rostests/winetests/d3dx9_36/core.c
Normal file
1310
modules/rostests/winetests/d3dx9_36/core.c
Normal file
File diff suppressed because it is too large
Load diff
8030
modules/rostests/winetests/d3dx9_36/effect.c
Normal file
8030
modules/rostests/winetests/d3dx9_36/effect.c
Normal file
File diff suppressed because it is too large
Load diff
155
modules/rostests/winetests/d3dx9_36/line.c
Normal file
155
modules/rostests/winetests/d3dx9_36/line.c
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright 2010 Christian Costa
|
||||
*
|
||||
* 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 "wine/test.h"
|
||||
#include "d3dx9.h"
|
||||
|
||||
#define admitted_error 0.0001f
|
||||
|
||||
#define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1.0f - out/ exp) ))
|
||||
|
||||
static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
{
|
||||
for (j = 0; j < 4; ++j)
|
||||
{
|
||||
if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#define expect_mat(expectedmat, gotmat) \
|
||||
do { \
|
||||
const D3DXMATRIX *__m1 = (expectedmat); \
|
||||
const D3DXMATRIX *__m2 = (gotmat); \
|
||||
ok(compare_matrix(__m1, __m2), "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \
|
||||
"Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
|
||||
U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
|
||||
U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
|
||||
U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
|
||||
U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
|
||||
U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
|
||||
U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
|
||||
U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
|
||||
U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
|
||||
} while(0)
|
||||
|
||||
static void test_create_line(IDirect3DDevice9* device)
|
||||
{
|
||||
HRESULT hr;
|
||||
ID3DXLine *line = NULL;
|
||||
struct IDirect3DDevice9 *return_device;
|
||||
D3DXMATRIX world, identity, result;
|
||||
FLOAT r11, r12, r13, r14;
|
||||
ULONG ref;
|
||||
|
||||
/* Arbitrary values for matrix tests. */
|
||||
r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587;
|
||||
|
||||
hr = D3DXCreateLine(NULL, &line);
|
||||
ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXCreateLine(device, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXCreateLine(device, &line);
|
||||
ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hr = ID3DXLine_GetDevice(line, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = ID3DXLine_GetDevice(line, &return_device);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
ok(return_device == device, "Expected line device %p, got %p\n", device, return_device);
|
||||
|
||||
D3DXMatrixIdentity(&world);
|
||||
D3DXMatrixIdentity(&identity);
|
||||
S(U(world))._11 = r11; S(U(world))._12 = r12; S(U(world))._13 = r13; S(U(world))._14 = r14;
|
||||
|
||||
hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
|
||||
hr = ID3DXLine_Begin(line);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
|
||||
hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
expect_mat(&identity, &result);
|
||||
|
||||
hr = ID3DXLine_End(line);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
|
||||
hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
|
||||
ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
|
||||
expect_mat(&world, &result);
|
||||
|
||||
IDirect3DDevice9_Release(return_device);
|
||||
|
||||
ref = ID3DXLine_Release(line);
|
||||
ok(ref == 0, "Got %x references to line %p, expected 0\n", ref, line);
|
||||
}
|
||||
|
||||
START_TEST(line)
|
||||
{
|
||||
HWND wnd;
|
||||
IDirect3D9* d3d;
|
||||
IDirect3DDevice9* device;
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
HRESULT hr;
|
||||
|
||||
if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
|
||||
640, 480, NULL, NULL, NULL, NULL)))
|
||||
{
|
||||
skip("Couldn't create application window\n");
|
||||
return;
|
||||
}
|
||||
if (!(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
|
||||
{
|
||||
skip("Couldn't create IDirect3D9 object\n");
|
||||
DestroyWindow(wnd);
|
||||
return;
|
||||
}
|
||||
|
||||
ZeroMemory(&d3dpp, sizeof(d3dpp));
|
||||
d3dpp.Windowed = TRUE;
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
|
||||
if (FAILED(hr)) {
|
||||
skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
|
||||
IDirect3D9_Release(d3d);
|
||||
DestroyWindow(wnd);
|
||||
return;
|
||||
}
|
||||
|
||||
test_create_line(device);
|
||||
|
||||
IDirect3DDevice9_Release(device);
|
||||
IDirect3D9_Release(d3d);
|
||||
DestroyWindow(wnd);
|
||||
}
|
3687
modules/rostests/winetests/d3dx9_36/math.c
Normal file
3687
modules/rostests/winetests/d3dx9_36/math.c
Normal file
File diff suppressed because it is too large
Load diff
11256
modules/rostests/winetests/d3dx9_36/mesh.c
Normal file
11256
modules/rostests/winetests/d3dx9_36/mesh.c
Normal file
File diff suppressed because it is too large
Load diff
2
modules/rostests/winetests/d3dx9_36/res.vsh
Normal file
2
modules/rostests/winetests/d3dx9_36/res.vsh
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define REGISTER r0
|
||||
vs.1.1
|
28
modules/rostests/winetests/d3dx9_36/resources.h
Normal file
28
modules/rostests/winetests/d3dx9_36/resources.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2009 Tony Wasserka
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __WINE_D3DX9_36_TEST_RESOURCES_H
|
||||
#define __WINE_D3DX9_36_TEST_RESOURCES_H
|
||||
|
||||
#define IDB_BITMAP_1x1 10
|
||||
#define IDD_BITMAPDATA_1x1 11
|
||||
#define IDS_STRING 12
|
||||
|
||||
#define IDB_ASMSHADER 20
|
||||
|
||||
#endif /* __WINE_D3DX9_36_TEST_RESOURCES_H */
|
31
modules/rostests/winetests/d3dx9_36/rsrc.rc
Normal file
31
modules/rostests/winetests/d3dx9_36/rsrc.rc
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright 2009 Tony Wasserka
|
||||
*
|
||||
* 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 "resources.h"
|
||||
|
||||
STRINGTABLE
|
||||
{
|
||||
IDS_STRING "nobitmap"
|
||||
}
|
||||
|
||||
/* @makedep: bmp1x1.bmp */
|
||||
IDB_BITMAP_1x1 BITMAP bmp1x1.bmp
|
||||
IDD_BITMAPDATA_1x1 RCDATA bmp1x1.bmp
|
||||
|
||||
/* @makedep: res.vsh */
|
||||
IDB_ASMSHADER RCDATA res.vsh
|
6592
modules/rostests/winetests/d3dx9_36/shader.c
Normal file
6592
modules/rostests/winetests/d3dx9_36/shader.c
Normal file
File diff suppressed because it is too large
Load diff
1465
modules/rostests/winetests/d3dx9_36/surface.c
Normal file
1465
modules/rostests/winetests/d3dx9_36/surface.c
Normal file
File diff suppressed because it is too large
Load diff
32
modules/rostests/winetests/d3dx9_36/testlist.c
Normal file
32
modules/rostests/winetests/d3dx9_36/testlist.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Automatically generated by make depend; DO NOT EDIT!! */
|
||||
|
||||
#define STANDALONE
|
||||
#include <wine/test.h>
|
||||
|
||||
extern void func_asm(void);
|
||||
extern void func_core(void);
|
||||
extern void func_effect(void);
|
||||
extern void func_line(void);
|
||||
extern void func_math(void);
|
||||
extern void func_mesh(void);
|
||||
extern void func_shader(void);
|
||||
extern void func_surface(void);
|
||||
extern void func_texture(void);
|
||||
extern void func_volume(void);
|
||||
extern void func_xfile(void);
|
||||
|
||||
const struct test winetest_testlist[] =
|
||||
{
|
||||
{ "asm", func_asm },
|
||||
{ "core", func_core },
|
||||
{ "effect", func_effect },
|
||||
{ "line", func_line },
|
||||
{ "math", func_math },
|
||||
{ "mesh", func_mesh },
|
||||
{ "shader", func_shader },
|
||||
{ "surface", func_surface },
|
||||
{ "texture", func_texture },
|
||||
{ "volume", func_volume },
|
||||
{ "xfile", func_xfile },
|
||||
{ 0, 0 }
|
||||
};
|
2264
modules/rostests/winetests/d3dx9_36/texture.c
Normal file
2264
modules/rostests/winetests/d3dx9_36/texture.c
Normal file
File diff suppressed because it is too large
Load diff
306
modules/rostests/winetests/d3dx9_36/volume.c
Normal file
306
modules/rostests/winetests/d3dx9_36/volume.c
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* Tests for the D3DX9 volume functions
|
||||
*
|
||||
* Copyright 2012 Józef Kucia
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define COBJMACROS
|
||||
#include "wine/test.h"
|
||||
#include "d3dx9tex.h"
|
||||
|
||||
/* 4x4x2 volume map dds, 2 mipmaps */
|
||||
static const unsigned char dds_volume_map[] =
|
||||
{
|
||||
0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
|
||||
0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
|
||||
0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
|
||||
0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
|
||||
0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
|
||||
0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
|
||||
};
|
||||
|
||||
#define check_pixel_4bpp(box, x, y, z, color) _check_pixel_4bpp(__LINE__, box, x, y, z, color)
|
||||
static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_BOX *box, int x, int y, int z, DWORD expected_color)
|
||||
{
|
||||
DWORD color = ((DWORD *)box->pBits)[x + (y * box->RowPitch + z * box->SlicePitch) / 4];
|
||||
ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
|
||||
}
|
||||
|
||||
static inline void set_box(D3DBOX *box, UINT left, UINT top, UINT right, UINT bottom, UINT front, UINT back)
|
||||
{
|
||||
box->Left = left;
|
||||
box->Top = top;
|
||||
box->Right = right;
|
||||
box->Bottom = bottom;
|
||||
box->Front = front;
|
||||
box->Back = back;
|
||||
}
|
||||
|
||||
static void test_D3DXLoadVolumeFromMemory(IDirect3DDevice9 *device)
|
||||
{
|
||||
int i, x, y, z;
|
||||
HRESULT hr;
|
||||
D3DBOX src_box, dst_box;
|
||||
D3DLOCKED_BOX locked_box;
|
||||
IDirect3DVolume9 *volume;
|
||||
IDirect3DVolumeTexture9 *volume_texture;
|
||||
const DWORD pixels[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6,
|
||||
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||
0x00000000, 0x00000000, 0x00000000, 0xffffffff,
|
||||
0xffffffff, 0x00000000, 0xffffffff, 0x00000000 };
|
||||
|
||||
hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
|
||||
&volume_texture, NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
skip("Failed to create volume texture.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, 0, &volume);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 1, 0, 4);
|
||||
set_box(&dst_box, 0, 0, 4, 1, 0, 4);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
win_skip("D3DXLoadVolumeFromMemory failed with error %#x, skipping some tests.\n", hr);
|
||||
return;
|
||||
}
|
||||
|
||||
IDirect3DVolume9_LockBox(volume, &locked_box, &dst_box, D3DLOCK_READONLY);
|
||||
for (i = 0; i < 16; i++) check_pixel_4bpp(&locked_box, i % 4, 0, i / 4, pixels[i]);
|
||||
IDirect3DVolume9_UnlockBox(volume);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_UNKNOWN, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == E_FAIL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, NULL, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, NULL, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, NULL, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 4, 0, 1);
|
||||
set_box(&dst_box, 0, 0, 4, 4, 0, 1);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, sizeof(pixels), NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
IDirect3DVolume9_LockBox(volume, &locked_box, &dst_box, D3DLOCK_READONLY);
|
||||
for (i = 0; i < 16; i++) check_pixel_4bpp(&locked_box, i % 4, i / 4, 0, pixels[i]);
|
||||
IDirect3DVolume9_UnlockBox(volume);
|
||||
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, NULL, pixels, D3DFMT_A8R8G8B8, 16, sizeof(pixels), NULL, &src_box, D3DX_FILTER_NONE, 0);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
IDirect3DVolume9_LockBox(volume, &locked_box, NULL, D3DLOCK_READONLY);
|
||||
for (i = 0; i < 16; i++) check_pixel_4bpp(&locked_box, i % 4, i / 4, 0, pixels[i]);
|
||||
for (z = 0; z < 4; z++)
|
||||
{
|
||||
for (y = 0; y < 256; y++)
|
||||
{
|
||||
for (x = 0; x < 256; x++)
|
||||
if (z != 0 || y >= 4 || x >= 4) check_pixel_4bpp(&locked_box, x, y, z, 0);
|
||||
}
|
||||
}
|
||||
IDirect3DVolume9_UnlockBox(volume);
|
||||
|
||||
set_box(&src_box, 0, 0, 2, 2, 1, 2);
|
||||
set_box(&dst_box, 0, 0, 2, 2, 0, 1);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 8, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
IDirect3DVolume9_LockBox(volume, &locked_box, &dst_box, D3DLOCK_READONLY);
|
||||
for (i = 0; i < 4; i++) check_pixel_4bpp(&locked_box, i % 2, i / 2, 0, pixels[i + 4]);
|
||||
IDirect3DVolume9_UnlockBox(volume);
|
||||
|
||||
set_box(&src_box, 0, 0, 2, 2, 2, 3);
|
||||
set_box(&dst_box, 0, 0, 2, 2, 1, 2);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 8, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
IDirect3DVolume9_LockBox(volume, &locked_box, &dst_box, D3DLOCK_READONLY);
|
||||
for (i = 0; i < 4; i++) check_pixel_4bpp(&locked_box, i % 2, i / 2, 0, pixels[i + 8]);
|
||||
IDirect3DVolume9_UnlockBox(volume);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 1, 0, 4);
|
||||
|
||||
set_box(&dst_box, -1, -1, 3, 0, 0, 4);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&dst_box, 254, 254, 258, 255, 0, 4);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&dst_box, 4, 1, 0, 0, 0, 4);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&dst_box, 0, 0, 0, 0, 0, 0);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&dst_box, 0, 0, 0, 0, 0, 1);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&dst_box, 300, 300, 300, 300, 0, 0);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
IDirect3DVolume9_Release(volume);
|
||||
IDirect3DVolumeTexture9_Release(volume_texture);
|
||||
|
||||
hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &volume_texture, NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
skip("Failed to create volume texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, 0, &volume);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 1, 0, 4);
|
||||
set_box(&dst_box, 0, 0, 4, 1, 0, 4);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 16, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
IDirect3DVolume9_Release(volume);
|
||||
IDirect3DVolumeTexture9_Release(volume_texture);
|
||||
|
||||
hr = IDirect3DDevice9_CreateVolumeTexture(device, 8, 8, 1, 1, D3DUSAGE_DYNAMIC, D3DFMT_DXT1, D3DPOOL_DEFAULT, &volume_texture, NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
skip("Failed to create volume texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, 0, &volume);
|
||||
|
||||
set_box(&src_box, 1, 1, 7, 7, 0, 1);
|
||||
set_box(&dst_box, 1, 1, 7, 7, 0, 1);
|
||||
hr = D3DXLoadVolumeFromMemory(volume, NULL, &dst_box, pixels, D3DFMT_A8R8G8B8, 16, 32, NULL, &src_box, D3DX_DEFAULT, 0);
|
||||
todo_wine ok(hr == D3D_OK, "D3DXLoadVolumeFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
IDirect3DVolume9_Release(volume);
|
||||
IDirect3DVolumeTexture9_Release(volume_texture);
|
||||
}
|
||||
|
||||
static void test_D3DXLoadVolumeFromFileInMemory(IDirect3DDevice9 *device)
|
||||
{
|
||||
HRESULT hr;
|
||||
D3DBOX src_box;
|
||||
IDirect3DVolume9 *volume;
|
||||
IDirect3DVolumeTexture9 *volume_texture;
|
||||
|
||||
hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 2, 1, D3DUSAGE_DYNAMIC, D3DFMT_DXT3, D3DPOOL_DEFAULT,
|
||||
&volume_texture, NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
skip("Failed to create volume texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, 0, &volume);
|
||||
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), NULL, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, NULL, sizeof(dds_volume_map), NULL, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, 0, NULL, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
hr = D3DXLoadVolumeFromFileInMemory(NULL, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), NULL, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 4, 0, 2);
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), &src_box, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3D_OK, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
|
||||
|
||||
set_box(&src_box, 0, 0, 0, 0, 0, 0);
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), &src_box, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == E_FAIL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, E_FAIL);
|
||||
|
||||
set_box(&src_box, 0, 0, 5, 4, 0, 2);
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), &src_box, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
set_box(&src_box, 0, 0, 4, 4, 0, 3);
|
||||
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, dds_volume_map, sizeof(dds_volume_map), &src_box, D3DX_DEFAULT, 0, NULL);
|
||||
ok(hr == D3DERR_INVALIDCALL, "D3DXLoadVolumeFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
|
||||
|
||||
IDirect3DVolume9_Release(volume);
|
||||
IDirect3DVolumeTexture9_Release(volume_texture);
|
||||
}
|
||||
|
||||
START_TEST(volume)
|
||||
{
|
||||
HWND wnd;
|
||||
IDirect3D9 *d3d;
|
||||
IDirect3DDevice9 *device;
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
HRESULT hr;
|
||||
|
||||
if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
|
||||
640, 480, NULL, NULL, NULL, NULL)))
|
||||
{
|
||||
skip("Couldn't create application window\n");
|
||||
return;
|
||||
}
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
if (!d3d)
|
||||
{
|
||||
skip("Couldn't create IDirect3D9 object\n");
|
||||
DestroyWindow(wnd);
|
||||
return;
|
||||
}
|
||||
|
||||
ZeroMemory(&d3dpp, sizeof(d3dpp));
|
||||
d3dpp.Windowed = TRUE;
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
|
||||
IDirect3D9_Release(d3d);
|
||||
DestroyWindow(wnd);
|
||||
return;
|
||||
}
|
||||
|
||||
test_D3DXLoadVolumeFromMemory(device);
|
||||
test_D3DXLoadVolumeFromFileInMemory(device);
|
||||
|
||||
IDirect3DDevice9_Release(device);
|
||||
IDirect3D9_Release(d3d);
|
||||
DestroyWindow(wnd);
|
||||
}
|
389
modules/rostests/winetests/d3dx9_36/xfile.c
Normal file
389
modules/rostests/winetests/d3dx9_36/xfile.c
Normal file
|
@ -0,0 +1,389 @@
|
|||
/*
|
||||
* Copyright 2012 Christian Costa
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include "wine/test.h"
|
||||
#include "d3dx9.h"
|
||||
#include "d3dx9xof.h"
|
||||
|
||||
static const char templates_bad_file_type1[] =
|
||||
"xOf 0302txt 0064\n";
|
||||
|
||||
static const char templates_bad_file_version[] =
|
||||
"xof 0102txt 0064\n";
|
||||
|
||||
static const char templates_bad_file_type2[] =
|
||||
"xof 0302foo 0064\n";
|
||||
|
||||
static const char templates_bad_file_float_size[] =
|
||||
"xof 0302txt 0050\n";
|
||||
|
||||
static const char templates_parse_error[] =
|
||||
"xof 0302txt 0064"
|
||||
"foobar;\n";
|
||||
|
||||
static const char templates[] =
|
||||
"xof 0302txt 0064"
|
||||
"template Header"
|
||||
"{"
|
||||
"<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
|
||||
"WORD major;"
|
||||
"WORD minor;"
|
||||
"DWORD flags;"
|
||||
"}\n";
|
||||
|
||||
static char objects[] =
|
||||
"xof 0302txt 0064\n"
|
||||
"Header Object\n"
|
||||
"{\n"
|
||||
"1; 2; 3;\n"
|
||||
"}\n";
|
||||
|
||||
static char object_noname[] =
|
||||
"xof 0302txt 0064\n"
|
||||
"Header\n"
|
||||
"{\n"
|
||||
"1; 2; 3;\n"
|
||||
"}\n";
|
||||
|
||||
static char template_using_index_color_lower[] =
|
||||
"xof 0302txt 0064\n"
|
||||
"template MeshVertexColors\n"
|
||||
"{\n"
|
||||
"<1630B821-7842-11cf-8F52-0040333594A3>\n"
|
||||
"DWORD nVertexColors;\n"
|
||||
"array indexColor vertexColors[nVertexColors];\n"
|
||||
"}\n";
|
||||
|
||||
static char template_using_index_color_upper[] =
|
||||
"xof 0302txt 0064\n"
|
||||
"template MeshVertexColors\n"
|
||||
"{\n"
|
||||
"<1630B821-7842-11cf-8F52-0040333594A3>\n"
|
||||
"DWORD nVertexColors;\n"
|
||||
"array IndexColor vertexColors[nVertexColors];\n"
|
||||
"}\n";
|
||||
|
||||
static void test_templates(void)
|
||||
{
|
||||
ID3DXFile *d3dxfile;
|
||||
HRESULT ret;
|
||||
|
||||
ret = D3DXFileCreate(NULL);
|
||||
ok(ret == E_POINTER, "D3DXCreateFile returned %#x, expected %#x\n", ret, E_POINTER);
|
||||
|
||||
ret = D3DXFileCreate(&d3dxfile);
|
||||
ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_type1, sizeof(templates_bad_file_type1) - 1);
|
||||
ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILETYPE);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_version, sizeof(templates_bad_file_version) - 1);
|
||||
ok(ret == D3DXFERR_BADFILEVERSION, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILEVERSION);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_type2, sizeof(templates_bad_file_type2) - 1);
|
||||
ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILETYPE);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_float_size, sizeof(templates_bad_file_float_size) - 1);
|
||||
ok(ret == D3DXFERR_BADFILEFLOATSIZE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILEFLOATSIZE);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_parse_error, sizeof(templates_parse_error) - 1);
|
||||
ok(ret == D3DXFERR_PARSEERROR, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_PARSEERROR);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
|
||||
ok(ret == S_OK, "RegisterTemplates failed with %#x\n", ret);
|
||||
|
||||
d3dxfile->lpVtbl->Release(d3dxfile);
|
||||
}
|
||||
|
||||
static void test_lock_unlock(void)
|
||||
{
|
||||
ID3DXFile *d3dxfile;
|
||||
D3DXF_FILELOADMEMORY memory;
|
||||
ID3DXFileEnumObject *enum_object;
|
||||
ID3DXFileData *data_object;
|
||||
const void *data;
|
||||
SIZE_T size;
|
||||
HRESULT ret;
|
||||
|
||||
ret = D3DXFileCreate(&d3dxfile);
|
||||
ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
|
||||
ok(ret == S_OK, "RegisterTemplates failed with %#x\n", ret);
|
||||
|
||||
memory.lpMemory = objects;
|
||||
memory.dSize = sizeof(objects) - 1;
|
||||
|
||||
ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
|
||||
ok(ret == S_OK, "CreateEnumObject failed with %#x\n", ret);
|
||||
|
||||
ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
|
||||
ok(ret == S_OK, "GetChild failed with %#x\n", ret);
|
||||
|
||||
ret = data_object->lpVtbl->Unlock(data_object);
|
||||
ok(ret == S_OK, "Unlock failed with %#x\n", ret);
|
||||
ret = data_object->lpVtbl->Lock(data_object, &size, &data);
|
||||
ok(ret == S_OK, "Lock failed with %#x\n", ret);
|
||||
ret = data_object->lpVtbl->Lock(data_object, &size, &data);
|
||||
ok(ret == S_OK, "Lock failed with %#x\n", ret);
|
||||
ret = data_object->lpVtbl->Unlock(data_object);
|
||||
ok(ret == S_OK, "Unlock failed with %#x\n", ret);
|
||||
ret = data_object->lpVtbl->Unlock(data_object);
|
||||
ok(ret == S_OK, "Unlock failed with %#x\n", ret);
|
||||
|
||||
data_object->lpVtbl->Release(data_object);
|
||||
enum_object->lpVtbl->Release(enum_object);
|
||||
d3dxfile->lpVtbl->Release(d3dxfile);
|
||||
}
|
||||
|
||||
static void test_getname(void)
|
||||
{
|
||||
ID3DXFile *d3dxfile;
|
||||
D3DXF_FILELOADMEMORY memory;
|
||||
ID3DXFileEnumObject *enum_object;
|
||||
ID3DXFileData *data_object;
|
||||
SIZE_T length;
|
||||
char name[100];
|
||||
HRESULT ret;
|
||||
|
||||
ret = D3DXFileCreate(&d3dxfile);
|
||||
ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
|
||||
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
|
||||
ok(ret == S_OK, "RegisterTemplates failed with %#x\n", ret);
|
||||
|
||||
/* Check object with name */
|
||||
memory.lpMemory = objects;
|
||||
memory.dSize = sizeof(objects) - 1;
|
||||
ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
|
||||
ok(ret == S_OK, "CreateEnumObject failed with %#x\n", ret);
|
||||
ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
|
||||
ok(ret == S_OK, "GetChild failed with %#x\n", ret);
|
||||
|
||||
ret = data_object->lpVtbl->GetName(data_object, NULL, NULL);
|
||||
ok(ret == D3DXFERR_BADVALUE, "GetName returned %#x, expected %#x\n", ret, D3DXFERR_BADVALUE);
|
||||
ret = data_object->lpVtbl->GetName(data_object, name, NULL);
|
||||
ok(ret == D3DXFERR_BADVALUE, "GetName returned %#x, expected %#x\n", ret, D3DXFERR_BADVALUE);
|
||||
ret = data_object->lpVtbl->GetName(data_object, NULL, &length);
|
||||
ok(ret == S_OK, "GetName failed with %#x\n", ret);
|
||||
ok(length == 7, "Returned length should be 7 instead of %ld\n", length);
|
||||
length = sizeof(name);
|
||||
ret = data_object->lpVtbl->GetName(data_object, name, &length);
|
||||
ok(ret == S_OK, "GetName failed with %#x\n", ret);
|
||||
ok(length == 7, "Returned length should be 7 instead of %ld\n", length);
|
||||
ok(!strcmp(name, "Object"), "Returned string should be 'Object' instead of '%s'\n", name);
|
||||
length = 3;
|
||||
ret = data_object->lpVtbl->GetName(data_object, name, &length);
|
||||
ok(ret== D3DXFERR_BADVALUE, "GetName returned %#x, expected %#x\n", ret, D3DXFERR_BADVALUE);
|
||||
|
||||
data_object->lpVtbl->Release(data_object);
|
||||
enum_object->lpVtbl->Release(enum_object);
|
||||
|
||||
/* Check object without name */
|
||||
memory.lpMemory = object_noname;
|
||||
memory.dSize = sizeof(object_noname) - 1;
|
||||
ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
|
||||
ok(ret == S_OK, "CreateEnumObject failed with %#x\n", ret);
|
||||
ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
|
||||
ok(ret == S_OK, "GetChild failed with %#x\n", ret);
|
||||
|
||||
/* Contrary to d3dxof, d3dx9_36 returns an empty string with a null byte when no name is available.
|
||||
* If the input size is 0, it returns a length of 1 without touching the buffer */
|
||||
ret = data_object->lpVtbl->GetName(data_object, NULL, &length);
|
||||
ok(ret == S_OK, "GetName failed with %#x\n", ret);
|
||||
ok(length == 1, "Returned length should be 1 instead of %ld\n", length);
|
||||
length = 0;
|
||||
name[0] = 0x7f;
|
||||
ret = data_object->lpVtbl->GetName(data_object, name, &length);
|
||||
ok(ret == S_OK, "GetName failed with %#x\n", ret);
|
||||
ok(length == 1, "Returned length should be 1 instead of %ld\n", length);
|
||||
ok(name[0] == 0x7f, "First character is %#x instead of 0x7f\n", name[0]);
|
||||
length = sizeof(name);
|
||||
name[0] = 0x7f;
|
||||
ret = data_object->lpVtbl->GetName(data_object, name, &length);
|
||||
ok(ret == S_OK, "GetName failed with %#x\n", ret);
|
||||
ok(length == 1, "Returned length should be 1 instead of %ld\n", length);
|
||||
ok(name[0] == 0, "First character is %#x instead of 0x00\n", name[0]);
|
||||
|
||||
data_object->lpVtbl->Release(data_object);
|
||||
enum_object->lpVtbl->Release(enum_object);
|
||||
d3dxfile->lpVtbl->Release(d3dxfile);
|
||||
}
|
||||
|
||||
static void test_type_index_color(void)
|
||||
{
|
||||
ID3DXFile *d3dxfile;
|
||||
HRESULT ret;
|
||||
|
||||
ret = D3DXFileCreate(&d3dxfile);
|
||||
ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
|
||||
|
||||
/* Test that 'indexColor' can be used (same as IndexedColor in standard templates) and is case sensitive */
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, template_using_index_color_lower, sizeof(template_using_index_color_lower) - 1);
|
||||
ok(ret == S_OK, "RegisterTemplates failed with %#x\n", ret);
|
||||
ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, template_using_index_color_upper, sizeof(template_using_index_color_upper) - 1);
|
||||
ok(ret == D3DXFERR_PARSEERROR, "RegisterTemplates returned %#x instead of %#x\n", ret, D3DXFERR_PARSEERROR);
|
||||
|
||||
d3dxfile->lpVtbl->Release(d3dxfile);
|
||||
}
|
||||
|
||||
static void process_data(ID3DXFileData *xfile_data, int level)
|
||||
{
|
||||
HRESULT ret;
|
||||
char name[100];
|
||||
GUID clsid;
|
||||
GUID clsid_type;
|
||||
SIZE_T len = sizeof(name);
|
||||
int i;
|
||||
const BYTE *data;
|
||||
SIZE_T size;
|
||||
SIZE_T children;
|
||||
|
||||
ret = xfile_data->lpVtbl->GetId(xfile_data, &clsid);
|
||||
ok(ret == S_OK, "ID3DXFileData_GetId failed with %#x\n", ret);
|
||||
ret = xfile_data->lpVtbl->GetName(xfile_data, name, &len);
|
||||
ok(ret == S_OK, "ID3DXFileData_GetName failed with %#x\n", ret);
|
||||
ret = xfile_data->lpVtbl->GetType(xfile_data, &clsid_type);
|
||||
ok(ret == S_OK, "IDirectXFileData_GetType failed with %#x\n", ret);
|
||||
ret = xfile_data->lpVtbl->Lock(xfile_data, &size, (const void**)&data);
|
||||
ok(ret == S_OK, "IDirectXFileData_Lock failed with %#x\n", ret);
|
||||
|
||||
for (i = 0; i < level; i++)
|
||||
printf(" ");
|
||||
|
||||
printf("Found object '%s' - %s - %s - %lu\n",
|
||||
len ? name : "", wine_dbgstr_guid(&clsid), wine_dbgstr_guid(&clsid_type), size);
|
||||
|
||||
if (size)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < size; j++)
|
||||
{
|
||||
if (j && !(j%16))
|
||||
printf("\n");
|
||||
printf("%02x ", data[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
ret = xfile_data->lpVtbl->Unlock(xfile_data);
|
||||
ok(ret == S_OK, "ID3DXFileData_Unlock failed with %#x\n", ret);
|
||||
|
||||
ret = xfile_data->lpVtbl->GetChildren(xfile_data, &children);
|
||||
ok(ret == S_OK, "ID3DXFileData_GetChildren failed with %#x\n", ret);
|
||||
|
||||
level++;
|
||||
|
||||
for (i = 0; i < children; i++)
|
||||
{
|
||||
ID3DXFileData *child;
|
||||
int j;
|
||||
|
||||
ret = xfile_data->lpVtbl->GetChild(xfile_data, i, &child);
|
||||
ok(ret == S_OK, "ID3DXFileData_GetChild failed with %#x\n", ret);
|
||||
for (j = 0; j < level; j++)
|
||||
printf(" ");
|
||||
if (child->lpVtbl->IsReference(child))
|
||||
printf("Found Data Reference (%d)\n", i + 1);
|
||||
else
|
||||
printf("Found Data (%d)\n", i + 1);
|
||||
|
||||
process_data(child, level);
|
||||
|
||||
child->lpVtbl->Release(child);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump an X file 'objects.x' and its related templates file 'templates.x' if they are both presents
|
||||
* Useful for debug by comparing outputs from native and builtin dlls */
|
||||
static void test_dump(void)
|
||||
{
|
||||
HRESULT ret;
|
||||
ULONG ref;
|
||||
ID3DXFile *xfile = NULL;
|
||||
ID3DXFileEnumObject *xfile_enum_object = NULL;
|
||||
HANDLE file;
|
||||
void *data;
|
||||
DWORD size;
|
||||
SIZE_T children;
|
||||
int i;
|
||||
|
||||
/* Dump data only if there is an object and a template */
|
||||
file = CreateFileA("objects.x", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
CloseHandle(file);
|
||||
|
||||
file = CreateFileA("templates.x", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
|
||||
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 10000);
|
||||
|
||||
if (!ReadFile(file, data, 10000, &size, NULL))
|
||||
{
|
||||
skip("Templates file is too big\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf("Load templates file (%u bytes)\n", size);
|
||||
|
||||
ret = D3DXFileCreate(&xfile);
|
||||
ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
|
||||
|
||||
ret = xfile->lpVtbl->RegisterTemplates(xfile, data, size);
|
||||
ok(ret == S_OK, "ID3DXFileImpl_RegisterTemplates failed with %#x\n", ret);
|
||||
|
||||
ret = xfile->lpVtbl->CreateEnumObject(xfile, (void*)"objects.x", D3DXF_FILELOAD_FROMFILE, &xfile_enum_object);
|
||||
ok(ret == S_OK, "ID3DXFile_CreateEnumObject failed with %#x\n", ret);
|
||||
|
||||
ret = xfile_enum_object->lpVtbl->GetChildren(xfile_enum_object, &children);
|
||||
ok(ret == S_OK, "ID3DXFileEnumObject_GetChildren failed with %#x\n", ret);
|
||||
|
||||
for (i = 0; i < children; i++)
|
||||
{
|
||||
ID3DXFileData *child;
|
||||
ret = xfile_enum_object->lpVtbl->GetChild(xfile_enum_object, i, &child);
|
||||
ok(ret == S_OK, "ID3DXFileEnumObject_GetChild failed with %#x\n", ret);
|
||||
printf("\n");
|
||||
process_data(child, 0);
|
||||
child->lpVtbl->Release(child);
|
||||
}
|
||||
|
||||
ref = xfile_enum_object->lpVtbl->Release(xfile_enum_object);
|
||||
ok(ref == 0, "Got refcount %u, expected 0\n", ref);
|
||||
|
||||
ref = xfile->lpVtbl->Release(xfile);
|
||||
ok(ref == 0, "Got refcount %u, expected 0\n", ref);
|
||||
|
||||
|
||||
exit:
|
||||
CloseHandle(file);
|
||||
HeapFree(GetProcessHeap(), 0, data);
|
||||
}
|
||||
|
||||
START_TEST(xfile)
|
||||
{
|
||||
test_templates();
|
||||
test_lock_unlock();
|
||||
test_getname();
|
||||
test_type_index_color();
|
||||
test_dump();
|
||||
}
|
Loading…
Reference in a new issue