Commit 3795a081 authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard

Fixed some strict aliasing issues in dlls/d3d8.

Incorporated bugfix from Christian Costa in vshader_expp.
parent 593e5374
......@@ -2184,6 +2184,10 @@ HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWOR
return D3D_OK;
}
HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
union {
DWORD d;
float f;
} tmpvalue;
ICOM_THIS(IDirect3DDevice8Impl,iface);
DWORD OldValue = This->StateBlock->renderstate[State];
......@@ -2752,26 +2756,26 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
case D3DRS_FOGSTART :
{
float *f = (float*) &Value;
glFogfv(GL_FOG_START, f);
tmpvalue.d = Value;
glFogfv(GL_FOG_START, &tmpvalue.f);
checkGLcall("glFogf(GL_FOG_START, (float) Value)");
TRACE("Fog Start == %f\n", *f);
TRACE("Fog Start == %f\n", tmpvalue.f);
}
break;
case D3DRS_FOGEND :
{
float *f = (float*) &Value;
glFogfv(GL_FOG_END, f);
tmpvalue.d = Value;
glFogfv(GL_FOG_END, &tmpvalue.f);
checkGLcall("glFogf(GL_FOG_END, (float) Value)");
TRACE("Fog End == %f\n", *f);
TRACE("Fog End == %f\n", tmpvalue.f);
}
break;
case D3DRS_FOGDENSITY :
{
float *f = (float*) &Value;
glFogfv(GL_FOG_DENSITY, f);
tmpvalue.d = Value;
glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
}
break;
......@@ -2785,7 +2789,8 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
case D3DRS_TWEENFACTOR :
{
This->UpdateStateBlock->tween_factor = *((float*) &Value);
tmpvalue.d = Value;
This->UpdateStateBlock->tween_factor = tmpvalue.f;
TRACE("Vertex Blending Tween Factor to %f\n", This->UpdateStateBlock->tween_factor);
}
break;
......@@ -2842,11 +2847,16 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
case D3DRS_LINEPATTERN :
{
D3DLINEPATTERN *pattern = (D3DLINEPATTERN *)&Value;
TRACE("Line pattern: repeat %d bits %x\n", pattern->wRepeatFactor, pattern->wLinePattern);
union {
DWORD d;
D3DLINEPATTERN lp;
} tmppattern;
tmppattern.d = Value;
if (pattern->wRepeatFactor) {
glLineStipple(pattern->wRepeatFactor, pattern->wLinePattern);
TRACE("Line pattern: repeat %d bits %x\n", tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
if (tmppattern.lp.wRepeatFactor) {
glLineStipple(tmppattern.lp.wRepeatFactor, tmppattern.lp.wLinePattern);
checkGLcall("glLineStipple(repeat, linepattern)");
glEnable(GL_LINE_STIPPLE);
checkGLcall("glEnable(GL_LINE_STIPPLE);");
......@@ -2860,8 +2870,9 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
case D3DRS_ZBIAS :
{
if (Value) {
TRACE("ZBias value %f\n", *((float*)&Value));
glPolygonOffset(0, -*((float*)&Value));
tmpvalue.d = Value;
TRACE("ZBias value %f\n", tmpvalue.f);
glPolygonOffset(0, -tmpvalue.f);
checkGLcall("glPolygonOffset(0, -Value)");
glEnable(GL_POLYGON_OFFSET_FILL);
checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL);");
......@@ -2891,14 +2902,16 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
break;
case D3DRS_POINTSIZE :
TRACE("Set point size to %f\n", *((float*)&Value));
glPointSize(*((float*)&Value));
tmpvalue.d = Value;
TRACE("Set point size to %f\n", tmpvalue.f);
glPointSize(tmpvalue.f);
checkGLcall("glPointSize(...);");
break;
case D3DRS_POINTSIZE_MIN :
if (GL_SUPPORT(EXT_POINT_PARAMETERS)) {
GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, *((float*)&Value));
tmpvalue.d = Value;
GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, tmpvalue.f);
checkGLcall("glPointParameterfEXT(...);");
} else {
FIXME("D3DRS_POINTSIZE_MIN not supported on this opengl\n");
......@@ -2907,7 +2920,8 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
case D3DRS_POINTSIZE_MAX :
if (GL_SUPPORT(EXT_POINT_PARAMETERS)) {
GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, *((float*)&Value));
tmpvalue.d = Value;
GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, tmpvalue.f);
checkGLcall("glPointParameterfEXT(...);");
} else {
FIXME("D3DRS_POINTSIZE_MAX not supported on this opengl\n");
......@@ -3211,6 +3225,10 @@ HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 ifa
HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
ICOM_THIS(IDirect3DDevice8Impl,iface);
union {
float f;
DWORD d;
} tmpvalue;
/* FIXME: Handle 3d textures? What if TSS value set before set texture? Need to reapply all values? */
......@@ -3383,10 +3401,10 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 ifa
case D3DTSS_MIPMAPLODBIAS :
{
if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
float f = *(float*) &Value;
tmpvalue.d = Value;
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
GL_TEXTURE_LOD_BIAS_EXT,
f);
tmpvalue.f);
checkGLcall("glTexEnvi GL_TEXTURE_LOD_BIAS_EXT ...");
}
}
......
......@@ -125,14 +125,18 @@ void vshader_dst(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
}
void vshader_expp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
float tmp_f = floorf(s0->w);
DWORD tmp_d = 0;
tmp_f = powf(2.0f, s0->w);
tmp_d = *((DWORD*) &tmp_f) & 0xFFFFFF00;
d->x = powf(2.0f, tmp_f);
d->y = s0->w - tmp_f;
d->z = *((float*) &tmp_d);
union {
float f;
DWORD d;
} tmp;
tmp.f = floorf(s0->w);
d->x = powf(2.0f, tmp.f);
d->y = s0->w - tmp.f;
tmp.f = powf(2.0f, s0->w);
tmp.d &= 0xFFFFFF00U;
d->z = tmp.f;
d->w = 1.0f;
VSTRACE(("executing exp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
......
......@@ -54,10 +54,16 @@ static const float idmatrix[16] = {
};
HRESULT WINAPI IDirect3DDeviceImpl_InitStartupStateBlock(IDirect3DDevice8Impl* This) {
union {
D3DLINEPATTERN lp;
DWORD d;
} lp;
union {
float f;
DWORD d;
} tmpfloat;
int i;
int j;
float tmpfloat = 0.0f;
LPDIRECT3DDEVICE8 iface = (LPDIRECT3DDEVICE8) This;
/* Note this may have a large overhead but it should only be executed
......@@ -81,7 +87,9 @@ HRESULT WINAPI IDirect3DDeviceImpl_InitStartupStateBlock(IDirect3DDevice8Impl* T
}
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FILLMODE, D3DFILL_SOLID);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
lp.wRepeatFactor = 0; lp.wLinePattern = 0; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_LINEPATTERN, *(DWORD *)&lp);
lp.lp.wRepeatFactor = 0; lp.lp.wLinePattern = 0;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_LINEPATTERN, lp.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_ZWRITEENABLE, TRUE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_ALPHATESTENABLE, FALSE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_LASTPIXEL, TRUE);
......@@ -98,9 +106,12 @@ HRESULT WINAPI IDirect3DDeviceImpl_InitStartupStateBlock(IDirect3DDevice8Impl* T
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_ZVISIBLE, 0);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGCOLOR, 0);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
tmpfloat = 0.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGSTART, *((DWORD *)&tmpfloat));
tmpfloat = 1.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGEND, *((DWORD *)&tmpfloat));
tmpfloat = 1.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGDENSITY, *((DWORD *)&tmpfloat));
tmpfloat.f = 0.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGSTART, tmpfloat.d);
tmpfloat.f = 1.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGEND, tmpfloat.d);
tmpfloat.f = 1.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_FOGDENSITY, tmpfloat.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_EDGEANTIALIAS, FALSE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_ZBIAS, 0);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_RANGEFOGENABLE, FALSE);
......@@ -142,8 +153,10 @@ HRESULT WINAPI IDirect3DDeviceImpl_InitStartupStateBlock(IDirect3DDevice8Impl* T
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_CLIPPLANEENABLE, 0);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
tmpfloat = 1.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE, *((DWORD *)&tmpfloat));
tmpfloat = 0.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE_MIN, *((DWORD *)&tmpfloat));
tmpfloat.f = 1.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE, tmpfloat.d);
tmpfloat.f = 0.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE_MIN, tmpfloat.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSPRITEENABLE, FALSE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSCALEENABLE, FALSE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSCALE_A, TRUE);
......@@ -152,12 +165,15 @@ HRESULT WINAPI IDirect3DDeviceImpl_InitStartupStateBlock(IDirect3DDevice8Impl* T
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_MULTISAMPLEANTIALIAS, TRUE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_DISCRETE);
tmpfloat = 1.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_PATCHSEGMENTS, *((DWORD *)&tmpfloat));
tmpfloat.f = 1.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_PATCHSEGMENTS, tmpfloat.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_DEBUGMONITORTOKEN, D3DDMT_DISABLE);
tmpfloat = 64.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE_MAX, (DWORD) *((DWORD *)&tmpfloat));
tmpfloat.f = 64.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POINTSIZE_MAX, tmpfloat.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_COLORWRITEENABLE, 0x0000000F);
tmpfloat = 0.0f; IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_TWEENFACTOR, (DWORD) *((DWORD *)&tmpfloat));
tmpfloat.f = 0.0f;
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_TWEENFACTOR, tmpfloat.d);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_BLENDOP, D3DBLENDOP_ADD);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_POSITIONORDER, D3DORDER_CUBIC);
IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_NORMALORDER, D3DORDER_LINEAR);
......
......@@ -263,7 +263,7 @@ HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKE
/** Dirtify Container if needed */
if (NULL != This->Container) {
IDirect3DBaseTexture8* cont = NULL;
hr = IUnknown_QueryInterface(This->Container, &IID_IDirect3DBaseTexture8, (void**) &cont);
hr = IUnknown_QueryInterface(This->Container, &IID_IDirect3DBaseTexture8, (void**)(char*) &cont);
if (SUCCEEDED(hr) && NULL != cont) {
IDirect3DBaseTexture8Impl_SetDirty(cont, TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment