Commit 6a97f220 authored by Jason Green's avatar Jason Green Committed by Alexandre Julliard

wined3d: Fix for vertex shaders.

parent d51faa74
......@@ -339,7 +339,7 @@ static void vshader_program_add_param(SHADER_OPCODE_ARG *arg, const DWORD param,
IWineD3DVertexShaderImpl* This = (IWineD3DVertexShaderImpl*) arg->shader;
/* oPos, oFog and oPts in D3D */
static const char* hwrastout_reg_names[] = { "result.position", "result.fogcoord", "result.pointsize" };
static const char* hwrastout_reg_names[] = { "result.position", "TMP_FOG", "result.pointsize" };
DWORD reg = param & D3DSP_REGNUM_MASK;
DWORD regtype = shader_get_regtype(param);
......
......@@ -343,6 +343,9 @@ HRESULT shader_get_registers_used(
else if (D3DSPR_INPUT == regtype && !pshader)
reg_maps->attributes[reg] = 1;
else if (D3DSPR_RASTOUT == regtype && reg == 1)
reg_maps->fog = 1;
}
}
}
......
......@@ -327,8 +327,17 @@ static void primitiveInitState(
}
This->last_was_rhw = FALSE;
/* Restore fogging */
if(This->stateBlock->renderState[WINED3DRS_FOGENABLE] && This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] != D3DFOG_NONE) {
/* Setup fogging */
if (useVS && ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->usesFog) {
/* In D3D vertex shader return the 'final' fog value, while in OpenGL it is the 'input' fog value.
* The code below 'disables' the OpenGL postprocessing by setting the formula to '1'. */
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, 1.0f);
glFogf(GL_FOG_END, 0.0f);
} else if(This->stateBlock->renderState[WINED3DRS_FOGENABLE]
&& This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] != D3DFOG_NONE) {
if(GL_SUPPORT(EXT_FOG_COORD)) {
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)\n");
......
......@@ -712,6 +712,12 @@ static VOID IWineD3DVertexShaderImpl_GenerateShader(
if (This->baseShader.hex_version >= D3DVS_VERSION(3,0))
vshader_glsl_output_unpack(&buffer, This->semantics_out);
/* Clamp the fog from 0 to 1 if it's used */
if (reg_maps->fog) {
This->usesFog = 1;
shader_addline(&buffer, "gl_FogFragCoord = clamp(gl_FogFragCoord, 0.0, 1.0);\n");
}
shader_addline(&buffer, "}\n\0");
TRACE("Compiling shader object %u\n", shader_obj);
......@@ -735,9 +741,18 @@ static VOID IWineD3DVertexShaderImpl_GenerateShader(
/* Base Declarations */
shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, &buffer);
if (reg_maps->fog) {
This->usesFog = 1;
shader_addline(&buffer, "TEMP TMP_FOG;\n");
}
/* Base Shader Body */
shader_generate_main( (IWineD3DBaseShader*) This, &buffer, reg_maps, pFunction);
/* Make sure the fog value is positive - values above 1.0 are ignored */
if (reg_maps->fog)
shader_addline(&buffer, "MAX result.fogcoord, TMP_FOG, 0.0;\n");
shader_addline(&buffer, "END\n\0");
/* TODO: change to resource.glObjectHandle or something like that */
......
......@@ -1314,6 +1314,9 @@ typedef struct shader_reg_maps {
/* Whether or not a loop is used in this shader */
char loop;
/* Whether or not this shader uses fog */
char fog;
} shader_reg_maps;
#define SHADER_PGMSIZE 65535
......@@ -1608,7 +1611,8 @@ typedef struct IWineD3DVertexShaderImpl {
IUnknown *parent;
IWineD3DDeviceImpl *wineD3DDevice;
DWORD usage;
char usesFog;
DWORD usage;
/* Vertex shader input and output semantics */
semantic semantics_in [MAX_ATTRIBS];
......
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