wined3d: GLSL shader cleanup patch.

- Based on comments from H. Verbeet
- Changed the distinction from .rgba & .xyzw masks to only use .xyzw
  in GLSL shaders.  They are interchangeable, and only served to make
  the trace look more intuitive, but they don't always apply as-is, so
  we'll just leave everything to .xyzw.
- Got rid of the "UseProgramObjectARB(0)" call in drawprim.  If there
  is no shader set on the next primitive, then that primitive will
  call UseProgramObjectARB(0) when it begins to draw.
This commit is contained in:
Jason Green 2006-06-09 12:28:51 -04:00 committed by Alexandre Julliard
parent deab874424
commit 08295f4cfc
2 changed files with 15 additions and 35 deletions

View File

@ -1922,17 +1922,14 @@ UINT numberOfvertices, UINT numberOfIndicies, GLenum glPrimType, const void *idx
/* Bind the correct GLSL shader program based on the currently set vertex & pixel shaders. */
if (wined3d_settings.shader_mode == SHADER_GLSL) {
GLhandleARB programId;
set_glsl_shader_program(iface);
programId = This->stateBlock->shaderPrgId;
if (programId != 0) {
/* Start using this program ID */
TRACE_(d3d_shader)("Using GLSL program %u\n", programId);
GL_EXTCALL(glUseProgramObjectARB(programId));
checkGLcall("glUseProgramObjectARB");
}
/* Start using this program ID (if it's 0, there is no shader program to use, so
* glUseProgramObjectARB(0) will disable the use of any shaders) */
if (This->stateBlock->shaderPrgId) {
TRACE_(d3d_shader)("Using GLSL program %u\n", This->stateBlock->shaderPrgId);
}
GL_EXTCALL(glUseProgramObjectARB(This->stateBlock->shaderPrgId));
checkGLcall("glUseProgramObjectARB");
}
if (useVertexShaderFunction) {
@ -2017,12 +2014,6 @@ UINT numberOfvertices, UINT numberOfIndicies, GLenum glPrimType, const void *idx
if (usePixelShaderFunction && wined3d_settings.shader_mode == SHADER_ARB) {
glDisable(GL_FRAGMENT_PROGRAM_ARB);
}
/* Cleanup GLSL program */
if (wined3d_settings.shader_mode == SHADER_GLSL
&& (useVertexShaderFunction || usePixelShaderFunction)) {
GL_EXTCALL(glUseProgramObjectARB(0));
}
}
}

View File

@ -271,34 +271,26 @@ void shader_glsl_get_register_name(
/* Writes the GLSL writemask for the destination register */
void shader_glsl_get_output_register_swizzle(
IWineD3DBaseShader *shader,
const DWORD param,
char *write_mask) {
IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl*) shader;
BOOL pshader = shader_is_pshader_version(This->baseShader.hex_version);
*write_mask = 0;
if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
strcat(write_mask, ".");
if (param & D3DSP_WRITEMASK_0) strcat(write_mask, pshader ? "r" : "x");
if (param & D3DSP_WRITEMASK_1) strcat(write_mask, pshader ? "g" : "y");
if (param & D3DSP_WRITEMASK_2) strcat(write_mask, pshader ? "b" : "z");
if (param & D3DSP_WRITEMASK_3) strcat(write_mask, pshader ? "a" : "w");
if (param & D3DSP_WRITEMASK_0) strcat(write_mask, "x");
if (param & D3DSP_WRITEMASK_1) strcat(write_mask, "y");
if (param & D3DSP_WRITEMASK_2) strcat(write_mask, "z");
if (param & D3DSP_WRITEMASK_3) strcat(write_mask, "w");
}
}
void shader_glsl_get_input_register_swizzle(
IWineD3DBaseShader *shader,
const DWORD param,
BOOL is_color,
char *reg_mask) {
IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl*) shader;
BOOL pshader = shader_is_pshader_version(This->baseShader.hex_version);
char swizzle_reg_chars_color_fix[5];
char swizzle_reg_chars[5];
const char swizzle_reg_chars_color_fix[] = "zyxw";
const char swizzle_reg_chars[] = "xyzw";
const char* swizzle_regs = NULL;
/** operand input */
@ -308,9 +300,6 @@ void shader_glsl_get_input_register_swizzle(
DWORD swizzle_z = (swizzle >> 4) & 0x03;
DWORD swizzle_w = (swizzle >> 6) & 0x03;
strcpy(swizzle_reg_chars_color_fix, pshader ? "bgra" : "zyxw");
strcpy(swizzle_reg_chars, pshader ? "rgba" : "xyzw");
if (is_color) {
swizzle_regs = swizzle_reg_chars_color_fix;
} else {
@ -363,10 +352,10 @@ void shader_glsl_add_param(
shader_glsl_get_register_name(param, addr_token, reg_name, &is_color, arg);
if (is_input) {
shader_glsl_get_input_register_swizzle(arg->shader, param, is_color, reg_mask);
shader_glsl_get_input_register_swizzle(param, is_color, reg_mask);
shader_glsl_gen_modifier(param, reg_name, reg_mask, out_str);
} else {
shader_glsl_get_output_register_swizzle(arg->shader, param, reg_mask);
shader_glsl_get_output_register_swizzle(param, reg_mask);
sprintf(out_str, "%s%s", reg_name, reg_mask);
}
}