some work on skeleton; fixed mesh bug

This commit is contained in:
aap 2017-10-20 22:38:28 +02:00
parent 2ba2258b06
commit 7273afb9a3
6 changed files with 111 additions and 0 deletions

View File

@ -31,6 +31,21 @@ TerminateRW(void)
rw::Engine::term(); rw::Engine::term();
} }
void
CameraSize(Camera *cam, Rect *r)
{
if(cam->frameBuffer){
cam->frameBuffer->destroy();
cam->frameBuffer = nil;
}
if(cam->zBuffer){
cam->zBuffer->destroy();
cam->zBuffer = nil;
}
cam->frameBuffer = Raster::create(r->w, r->h, 0, Raster::CAMERA);
cam->zBuffer = Raster::create(r->w, r->h, 0, Raster::ZBUFFER);
}
EventStatus EventStatus
EventHandler(Event e, void *param) EventHandler(Event e, void *param)
{ {

View File

@ -69,6 +69,7 @@ enum Event
PLUGINATTACH, PLUGINATTACH,
KEYDOWN, KEYDOWN,
KEYUP, KEYUP,
RESIZE,
IDLE, IDLE,
QUIT QUIT
}; };
@ -91,6 +92,7 @@ extern Args args;
bool InitRW(void); bool InitRW(void);
void TerminateRW(void); void TerminateRW(void);
void CameraSize(Camera *cam, Rect *r);
EventStatus EventHandler(Event e, void *param); EventStatus EventHandler(Event e, void *param);
} }

View File

@ -63,6 +63,8 @@ static void KeyDown(int key) { EventHandler(KEYDOWN, &key); }
LRESULT CALLBACK LRESULT CALLBACK
WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
static int resizing = 0;
switch(msg){ switch(msg){
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
@ -98,6 +100,15 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
KeyUp(keymap[wParam]); KeyUp(keymap[wParam]);
break; break;
case WM_SIZE:
rw::Rect r;
r.x = 0;
r.y = 0;
r.w = LOWORD(lParam);
r.h = HIWORD(lParam);
EventHandler(RESIZE, &r);
break;
case WM_CLOSE: case WM_CLOSE:
DestroyWindow(hwnd); DestroyWindow(hwnd);
break; break;

View File

@ -20,6 +20,13 @@ namespace d3d {
#ifdef RW_D3D9 #ifdef RW_D3D9
struct D3d9Globals
{
HWND window;
bool windowed;
int presentWidth, presentHeight;
} d3d9Globals;
// cached RW render states // cached RW render states
static bool32 vertexAlpha; static bool32 vertexAlpha;
static bool32 textureAlpha; static bool32 textureAlpha;
@ -128,6 +135,27 @@ setSamplerState(uint32 stage, uint32 type, uint32 value)
} }
} }
// Bring D3D device in accordance with saved render states (after a reset)
static void
resetD3d9Device(void)
{
int32 i;
uint32 s, t;
for(i = 0; i < MAXNUMSTAGES; i++){
d3dRaster[i] = nil;
d3ddevice->SetTexture(i, nil);
}
for(s = 0; s < MAXNUMSTATES; s++)
d3ddevice->SetRenderState((D3DRENDERSTATETYPE)s, d3dStates[s]);
for(t = 0; t < MAXNUMSTATES; t++)
for(s = 0; s < MAXNUMSTAGES; s++)
d3ddevice->SetTextureStageState(s, (D3DTEXTURESTAGESTATETYPE)t, d3dTextureStageStates[t][s]);
for(t = 0; t < MAXNUMSAMPLERSTATES; t++)
for(s = 0; s < MAXNUMSTAGES; s++)
d3ddevice->SetSamplerState(s, (D3DSAMPLERSTATETYPE)t, d3dSamplerStates[t][s]);
d3ddevice->SetMaterial(&d3dmaterial);
}
// RW render state // RW render state
static void static void
@ -416,6 +444,35 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
if(mode & Camera::CLEARZ) if(mode & Camera::CLEARZ)
mode |= D3DCLEAR_ZBUFFER; mode |= D3DCLEAR_ZBUFFER;
D3DCOLOR c = D3DCOLOR_RGBA(col->red, col->green, col->blue, col->alpha); D3DCOLOR c = D3DCOLOR_RGBA(col->red, col->green, col->blue, col->alpha);
RECT r;
GetClientRect(d3d9Globals.window, &r);
BOOL icon = IsIconic(d3d9Globals.window);
Raster *ras = cam->frameBuffer;
if(!icon &&
(r.right != d3d9Globals.presentWidth || r.bottom != d3d9Globals.presentHeight)){
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = r.right;
d3dpp.BackBufferHeight = r.bottom;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = d3d9Globals.window;
d3dpp.Windowed = d3d9Globals.windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
// TODO: check result
d3d::d3ddevice->Reset(&d3dpp);
d3d9Globals.presentWidth = r.right;
d3d9Globals.presentHeight = r.bottom;
resetD3d9Device();
}
d3ddevice->Clear(0, 0, mode, c, 1.0f, 0); d3ddevice->Clear(0, 0, mode, c, 1.0f, 0);
} }
@ -433,6 +490,9 @@ openD3D(EngineStartParams *params)
HWND win = params->window; HWND win = params->window;
bool windowed = true; bool windowed = true;
d3d9Globals.window = win;
d3d9Globals.windowed = windowed;
HRESULT hr = 0; HRESULT hr = 0;
IDirect3D9 *d3d9 = 0; IDirect3D9 *d3d9 = 0;
d3d9 = Direct3DCreate9(D3D_SDK_VERSION); d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
@ -454,6 +514,8 @@ openD3D(EngineStartParams *params)
int width = rect.right - rect.left; int width = rect.right - rect.left;
int height = rect.bottom - rect.top; int height = rect.bottom - rect.top;
d3d9Globals.presentWidth = width;
d3d9Globals.presentHeight = height;
D3DPRESENT_PARAMETERS d3dpp; D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = width; d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height; d3dpp.BackBufferHeight = height;
@ -502,6 +564,8 @@ closeD3D(void)
static int static int
initD3D(void) initD3D(void)
{ {
int32 s, t;
// TODO: do some real stuff here // TODO: do some real stuff here
d3ddevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); d3ddevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
@ -531,6 +595,16 @@ initD3D(void)
// setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT); // setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
// setTextureStageState(0, D3DTSS_COLOROP, D3DTA_CONSTANT); // setTextureStageState(0, D3DTSS_COLOROP, D3DTA_CONSTANT);
// Save the current states
for(s = 0; s < MAXNUMSTATES; s++)
d3ddevice->GetRenderState((D3DRENDERSTATETYPE)s, (DWORD*)&d3dStates[s]);
for(t = 0; t < MAXNUMSTATES; t++)
for(s = 0; s < MAXNUMSTAGES; s++)
d3ddevice->GetTextureStageState(s, (D3DTEXTURESTAGESTATETYPE)t, (DWORD*)&d3dTextureStageStates[t][s]);
for(t = 0; t < MAXNUMSAMPLERSTATES; t++)
for(s = 0; s < MAXNUMSTAGES; s++)
d3ddevice->GetSamplerState(s, (D3DSAMPLERSTATETYPE)t, (DWORD*)&d3dSamplerStates[t][s]);
openIm2D(); openIm2D();
openIm3D(); openIm3D();

View File

@ -121,6 +121,7 @@ readMesh(Stream *stream, int32 len, void *object, int32, int32)
geo->meshHeader = nil; geo->meshHeader = nil;
mh = geo->allocateMeshes(mhs.numMeshes, mhs.totalIndices, mh = geo->allocateMeshes(mhs.numMeshes, mhs.totalIndices,
geo->flags & Geometry::NATIVE && !hasData); geo->flags & Geometry::NATIVE && !hasData);
mh->flags = mhs.flags;
mesh = mh->getMeshes(); mesh = mh->getMeshes();
indices = mesh->indices; indices = mesh->indices;

View File

@ -382,6 +382,7 @@ sk::EventStatus
AppEventHandler(sk::Event e, void *param) AppEventHandler(sk::Event e, void *param)
{ {
using namespace sk; using namespace sk;
Rect *r;
switch(e){ switch(e){
case INITIALIZE: case INITIALIZE:
Init(); Init();
@ -396,6 +397,13 @@ AppEventHandler(sk::Event e, void *param)
case KEYUP: case KEYUP:
KeyUp(*(int*)param); KeyUp(*(int*)param);
return EVENTPROCESSED; return EVENTPROCESSED;
case RESIZE:
r = (Rect*)param;
sk::globals.width = r->w;
sk::globals.height = r->h;
if(Scene.camera)
sk::CameraSize(Scene.camera, r);
break;
case IDLE: case IDLE:
Draw(*(float*)param); Draw(*(float*)param);
return EVENTPROCESSED; return EVENTPROCESSED;