mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Start finishing off porting of Direct3D9Api.
This commit is contained in:
parent
5af72543bf
commit
04c5be2f48
@ -10,9 +10,9 @@ void Block_Reset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Block_Init(void) {
|
void Block_Init(void) {
|
||||||
#define DefinedCustomBlocks_Len (Block_Count >> 5)
|
Int32 count = sizeof(DefinedCustomBlocks) / sizeof(DefinedCustomBlocks[0]);
|
||||||
Int32 i;
|
Int32 i;
|
||||||
for (i = 0; i < DefinedCustomBlocks_Len; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
DefinedCustomBlocks[i] = 0;
|
DefinedCustomBlocks[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "ErrorHandler.h"
|
#include "ErrorHandler.h"
|
||||||
#include "GraphicsEnums.h"
|
#include "GraphicsEnums.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
#ifdef USE_DX
|
#ifdef USE_DX
|
||||||
|
|
||||||
@ -10,7 +11,8 @@ IDirect3D9* d3d;
|
|||||||
IDirect3DDevice9* device;
|
IDirect3DDevice9* device;
|
||||||
MatrixStack* curStack;
|
MatrixStack* curStack;
|
||||||
MatrixStack viewStack, projStack, texStack;
|
MatrixStack viewStack, projStack, texStack;
|
||||||
|
DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||||
|
D3DFORMAT viewFormat, depthFormat;
|
||||||
|
|
||||||
#define D3D9_SetRenderState(raw, state, name) \
|
#define D3D9_SetRenderState(raw, state, name) \
|
||||||
ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \
|
ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \
|
||||||
@ -45,10 +47,34 @@ Int32 d3d9_texturesCapacity = d3d9_texturesExpSize;
|
|||||||
|
|
||||||
|
|
||||||
void Gfx_Init(void) {
|
void Gfx_Init(void) {
|
||||||
/* TODO: EVERYTHING ELSE */
|
Gfx_MinZNear = 0.05f;
|
||||||
|
void* winHandle = Window_GetWindowHandle();
|
||||||
|
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||||
|
|
||||||
|
D3D9_FindCompatibleFormat();
|
||||||
|
D3DPRESENT_PARAMETERS args;
|
||||||
|
D3D9_GetPresentArgs(640, 480, &args);
|
||||||
|
ReturnCode res;
|
||||||
|
|
||||||
|
/* Try to create a device with as much hardware usage as possible. */
|
||||||
|
res = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, createFlags, &args, &device);
|
||||||
|
if (!ErrorHandler_Check(res)) {
|
||||||
|
createFlags = D3DCREATE_MIXED_VERTEXPROCESSING;
|
||||||
|
res = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, createFlags, &args, &device);
|
||||||
|
}
|
||||||
|
if (!ErrorHandler_Check(res)) {
|
||||||
|
createFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
||||||
|
res = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, createFlags, &args, &device);
|
||||||
|
}
|
||||||
|
if (!ErrorHandler_Check(res)) {
|
||||||
|
ErrorHandler_FailWithCode(res, "Failed to create Direct3D9 device");
|
||||||
|
}
|
||||||
|
|
||||||
viewStack.Type = D3DTS_VIEW;
|
viewStack.Type = D3DTS_VIEW;
|
||||||
projStack.Type = D3DTS_PROJECTION;
|
projStack.Type = D3DTS_PROJECTION;
|
||||||
texStack.Type = D3DTS_TEXTURE0;
|
texStack.Type = D3DTS_TEXTURE0;
|
||||||
|
SetDefaultRenderStates();
|
||||||
|
InitDynamicBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Free(void) {
|
void Gfx_Free(void) {
|
||||||
@ -88,6 +114,42 @@ void Gfx_Free(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void D3D9_FindCompatibleFormat(void) {
|
||||||
|
Int32 count = sizeof(d3d9_viewFormats) / sizeof(d3d9_viewFormats[0]);
|
||||||
|
Int32 i;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
viewFormat = d3d9_viewFormats[i];
|
||||||
|
if (IDirect3D9_CheckDeviceType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, viewFormat, viewFormat, true)) break;
|
||||||
|
|
||||||
|
if (i == count - 1) {
|
||||||
|
ErrorHandler_Fail("Unable to create a back buffer with sufficient precision.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count = sizeof(d3d9_depthFormats) / sizeof(d3d9_depthFormats[0]);
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
depthFormat = d3d9_depthFormats[i];
|
||||||
|
if (IDirect3D9_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, viewFormat, viewFormat, depthFormat)) break;
|
||||||
|
|
||||||
|
if (i == count - 1) {
|
||||||
|
ErrorHandler_Fail("Unable to create a depth buffer with sufficient precision.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args) {
|
||||||
|
Platform_MemSet(args, 0, sizeof(D3DPRESENT_PARAMETERS));
|
||||||
|
args->AutoDepthStencilFormat = depthFormat;
|
||||||
|
args->BackBufferWidth = width;
|
||||||
|
args->BackBufferHeight = height;
|
||||||
|
args->BackBufferFormat = viewFormat;
|
||||||
|
args->BackBufferCount = 1;
|
||||||
|
args->EnableAutoDepthStencil = true;
|
||||||
|
args->PresentationInterval = vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||||
|
args->SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||||
|
args->Windowed = true;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool) {
|
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool) {
|
||||||
|
@ -32,6 +32,9 @@ D3DCMPFUNC d3d9_compareFuncs[8] = { D3DCMP_ALWAYS, D3DCMP_NOTEQUAL, D3DCMP_NEVER
|
|||||||
D3DFOGMODE d3d9_modes[3] = { D3DFOG_LINEAR, D3DFOG_EXP, D3DFOG_EXP2 };
|
D3DFOGMODE d3d9_modes[3] = { D3DFOG_LINEAR, D3DFOG_EXP, D3DFOG_EXP2 };
|
||||||
Int32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 };
|
Int32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 };
|
||||||
|
|
||||||
|
static void D3D9_FindCompatibleFormat(void);
|
||||||
|
|
||||||
|
static D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args);
|
||||||
|
|
||||||
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp);
|
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "ErrorHandler.h"
|
#include "ErrorHandler.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
#include "GraphicsAPI.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
ErrorHandler_Init();
|
ErrorHandler_Init();
|
||||||
@ -10,6 +11,7 @@ int main(int argc, char* argv[]) {
|
|||||||
String str = String_FromConstant("TEST");
|
String str = String_FromConstant("TEST");
|
||||||
Window_Create(320, 320, 320, 320, &str, NULL);
|
Window_Create(320, 320, 320, 320, &str, NULL);
|
||||||
Window_SetVisible(true);
|
Window_SetVisible(true);
|
||||||
|
Gfx_Init();
|
||||||
while (true) {
|
while (true) {
|
||||||
Window_ProcessEvents();
|
Window_ProcessEvents();
|
||||||
Platform_ThreadSleep(100);
|
Platform_ThreadSleep(100);
|
||||||
|
@ -570,6 +570,7 @@ API.SendMessage(window.handle, WM_SETICON, (IntPtr)1, icon == null ? IntPtr.Zero
|
|||||||
|
|
||||||
bool Window_GetFocused(void) { return win_Focused; }
|
bool Window_GetFocused(void) { return win_Focused; }
|
||||||
bool Window_GetExists(void) { return win_Exists; }
|
bool Window_GetExists(void) { return win_Exists; }
|
||||||
|
void* Window_GetWindowHandle(void) { return win_Handle; }
|
||||||
|
|
||||||
bool Window_GetVisible(void) { return IsWindowVisible(win_Handle); }
|
bool Window_GetVisible(void) { return IsWindowVisible(win_Handle); }
|
||||||
void Window_SetVisible(bool visible) {
|
void Window_SetVisible(bool visible) {
|
||||||
|
@ -69,10 +69,8 @@ void Window_SetVisible(bool visible);
|
|||||||
/* Gets whether this window has been created and has not been destroyed. */
|
/* Gets whether this window has been created and has not been destroyed. */
|
||||||
bool Window_GetExists(void);
|
bool Window_GetExists(void);
|
||||||
|
|
||||||
/* TODO: IMPLEMENT THIS
|
/* TODO: IMPLEMENT THIS */
|
||||||
/// <summary> Gets the <see cref="OpenTK.Platform.IWindowInfo"/> for this window. </summary>
|
void* Window_GetWindowHandle(void);
|
||||||
IWindowInfo WindowInfo{ get; }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Gets the WindowState of this window. */
|
/* Gets the WindowState of this window. */
|
||||||
WindowState Window_GetWindowState(void);
|
WindowState Window_GetWindowState(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user