Commit 2ec3bbcc authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

glColorMaterial enable/disable setup is only done when really necessary.

If glColorMaterial is set to track current color and none is supplied, it gets disabled. glMaterial is reset when I think it is necessary. Slow mode now has defaults for when fvf parms are not supplied (as per fast mode). Slow mode now sets up the specular color (forgot that bit previously, I think!). Trace now lists the front, back and stencil buffers for ease of debugging.
parent 1d45ab4a
......@@ -330,7 +330,12 @@ struct IDirect3DDevice8Impl
BOOL proj_valid;
BOOL view_ident; /* true iff view matrix is identity */
BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
GLenum tracking_parm; /* Which source is tracking current colour */
LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
#define DISABLED_TRACKING 0 /* Disabled */
#define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
#define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
#define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
/* OpenGL related */
GLXContext glCtx;
......
......@@ -2402,9 +2402,6 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
GLenum Parm = GL_AMBIENT_AND_DIFFUSE;
if (This->StateBlock->renderstate[D3DRS_COLORVERTEX]) {
glEnable(GL_COLOR_MATERIAL);
checkGLcall("glEnable GL_COLOR_MATERIAL");
TRACE("diff %ld, amb %ld, emis %ld, spec %ld\n",
This->StateBlock->renderstate[D3DRS_DIFFUSEMATERIALSOURCE],
This->StateBlock->renderstate[D3DRS_AMBIENTMATERIALSOURCE],
......@@ -2428,17 +2425,14 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3
}
if (Parm == -1) {
glDisable(GL_COLOR_MATERIAL);
checkGLcall("glDisable GL_COLOR_MATERIAL");
if (This->tracking_color != DISABLED_TRACKING) This->tracking_color = NEEDS_DISABLE;
} else {
TRACE("glColorMaterial Parm=%d\n", Parm);
glColorMaterial(GL_FRONT_AND_BACK, Parm);
checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
This->tracking_color = NEEDS_TRACKING;
This->tracking_parm = Parm;
}
} else {
glDisable(GL_COLOR_MATERIAL);
checkGLcall("glDisable GL_COLOR_MATERIAL");
if (This->tracking_color != DISABLED_TRACKING) This->tracking_color = NEEDS_DISABLE;
}
}
break;
......
......@@ -1025,6 +1025,7 @@ HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
} else {
object->depthStencilBuffer = NULL;
}
TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil @ %p\n",object->frontBuffer, object->backBuffer, object->depthStencilBuffer);
/* init the default renderTarget management */
object->drawable = object->win;
......
......@@ -158,6 +158,58 @@ DWORD primitiveToGl(D3DPRIMITIVETYPE PrimitiveType,
return NumVertexes;
}
/* Ensure the appropriate material states are set up - only change
state if really required */
void init_materials(LPDIRECT3DDEVICE8 iface, BOOL isDiffuseSupplied) {
BOOL requires_material_reset = FALSE;
ICOM_THIS(IDirect3DDevice8Impl,iface);
if (This->tracking_color == NEEDS_TRACKING && isDiffuseSupplied == TRUE) {
/* If we have not set up the material color tracking, do it now as required */
glDisable(GL_COLOR_MATERIAL); /* Note: Man pages state must enable AFTER calling glColorMaterial! Required?*/
checkGLcall("glDisable GL_COLOR_MATERIAL");
TRACE("glColorMaterial Parm=%x\n", This->tracking_parm);
glColorMaterial(GL_FRONT_AND_BACK, This->tracking_parm);
checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
glEnable(GL_COLOR_MATERIAL);
checkGLcall("glEnable GL_COLOR_MATERIAL");
This->tracking_color = IS_TRACKING;
requires_material_reset = TRUE; /* Restore material settings as will be used */
} else if ((This->tracking_color == IS_TRACKING && isDiffuseSupplied == FALSE) ||
(This->tracking_color == NEEDS_TRACKING && isDiffuseSupplied == FALSE)) {
/* If we are tracking the current color but one isnt supplied, dont! */
glDisable(GL_COLOR_MATERIAL);
checkGLcall("glDisable GL_COLOR_MATERIAL");
This->tracking_color = NEEDS_TRACKING;
requires_material_reset = TRUE; /* Restore material settings as will be used */
} else if (This->tracking_color == IS_TRACKING && isDiffuseSupplied == TRUE) {
/* No need to reset material colors since no change to gl_color_material */
requires_material_reset = FALSE;
} else if (This->tracking_color == NEEDS_DISABLE) {
glDisable(GL_COLOR_MATERIAL);
checkGLcall("glDisable GL_COLOR_MATERIAL");
This->tracking_color = DISABLED_TRACKING;
requires_material_reset = TRUE; /* Restore material settings as will be used */
}
/* Reset the material colors which may have been tracking the color*/
if (requires_material_reset == TRUE) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*) &This->StateBlock->material.Ambient);
checkGLcall("glMaterialfv");
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*) &This->StateBlock->material.Diffuse);
checkGLcall("glMaterialfv");
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*) &This->StateBlock->material.Specular);
checkGLcall("glMaterialfv");
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float*) &This->StateBlock->material.Emissive);
checkGLcall("glMaterialfv");
}
}
/* Setup views - Transformed & lit if RHW, else untransformed.
Only unlit if Normals are supplied
Returns: Whether to restore lighting afterwards */
......@@ -679,6 +731,8 @@ void drawStridedFast(LPDIRECT3DDEVICE8 iface, Direct3DVertexStridedData *sd,
glDisableClientState(GL_COLOR_ARRAY);
checkGLcall("glDisableClientState(GL_COLOR_ARRAY)");
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
checkGLcall("glColor4f(1, 1, 1, 1)");
}
/* Specular Colour ------------------------------------------*/
......@@ -1062,13 +1116,52 @@ void drawStridedSlow(LPDIRECT3DDEVICE8 iface, Direct3DVertexStridedData *sd,
((diffuseColor >> 8) & 0xFF) / 255.0f,
((diffuseColor >> 0) & 0xFF) / 255.0f,
((diffuseColor >> 24) & 0xFF) / 255.0f));
} else {
if (vx_index == 0) glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
#if 1
/* Specular ------------------------------- */
if (sd->u.s.diffuse.lpData != NULL) {
VTRACE(("glSecondaryColor4ub: r,g,b=%f,%f,%f\n",
((specularColor >> 16) & 0xFF) / 255.0f,
((specularColor >> 8) & 0xFF) / 255.0f,
((specularColor >> 0) & 0xFF) / 255.0f));
#if defined(GL_VERSION_1_4)
glSecondaryColor3ub((specularColor >> 16) & 0xFF,
(specularColor >> 8) & 0xFF,
(specularColor >> 0) & 0xFF);
#elif defined(GL_EXT_secondary_color)
if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
GL_EXTCALL(glSecondaryColor3ubEXT)(
(specularColor >> 16) & 0xFF,
(specularColor >> 8) & 0xFF,
(specularColor >> 0) & 0xFF);
}
#else
/* Do not worry if specular colour missing and disable request */
VTRACE(("Specular color extensions not supplied\n"));
#endif
} else {
#if defined(GL_VERSION_1_4)
if (vx_index == 0) glSecondaryColor3f(0, 0, 0);
#elif defined(GL_EXT_secondary_color)
if (vx_index == 0 && GL_SUPPORT(EXT_SECONDARY_COLOR)) {
GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
}
#else
/* Do not worry if specular colour missing and disable request */
#endif
}
#endif
/* Normal -------------------------------- */
if (sd->u.s.normal.lpData != NULL) {
VTRACE(("glNormal:nx,ny,nz=%f,%f,%f\n", nx,ny,nz));
glNormal3f(nx, ny, nz);
}
} else {
if (vx_index == 0) glNormal3f(0, 0, 1);
}
/* Position -------------------------------- */
if (sd->u.s.position.lpData != NULL) {
......@@ -1295,6 +1388,9 @@ void drawPrimitive(LPDIRECT3DDEVICE8 iface,
TRACE_STRIDED((&dataLocations), texCoords[7]);
}
/* Now initialize the materials state */
init_materials(iface, (dataLocations.u.s.diffuse.lpData != NULL));
/* Now draw the graphics to the screen */
if (useVertexShaderFunction == 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