Changeset 51270 in vbox for trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/glsl_shader.c
- Timestamp:
- May 16, 2014 10:27:20 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 93732
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/glsl_shader.c
r48509 r51270 47 47 #include "wined3d_private.h" 48 48 49 #if defined(VBOX)50 # if defined(RT_ARCH_AMD64)51 # define copysignf _copysignf52 # else53 # define _VBOX_BITVAL_CAST(_t, _f) (*((const _t*)((const void*)(&(_f)))))54 # define _VBOX_BITVAL_TO_FLOATL(_f) _VBOX_BITVAL_CAST(float, _f)55 # define _VBOX_BITVAL_FROM_FLOAT(_f) _VBOX_BITVAL_CAST(uint32_t, _f)56 DECLINLINE(float) copysignf(float val, float sign)57 {58 uint32_t u32Val = ((_VBOX_BITVAL_FROM_FLOAT(val) & 0x7fffffff) | (_VBOX_BITVAL_FROM_FLOAT(sign) & 0x80000000));59 return _VBOX_BITVAL_TO_FLOATL(u32Val);60 }61 # endif62 #endif63 64 49 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader); 65 50 WINE_DECLARE_DEBUG_CHANNEL(d3d_constants); … … 71 56 #define WINED3D_GLSL_SAMPLE_LOD 0x4 72 57 #define WINED3D_GLSL_SAMPLE_GRAD 0x8 73 74 static const float srgb_const0[] = {0.41666f, 1.055f, 0.055f, 12.92f}; /* pow, mul_high, sub_high, mul_low */75 static const float srgb_const1[] = {0.0031308f, 0.0f, 0.0f, 0.0f}; /* cmp */76 58 77 59 struct glsl_dst_param … … 273 255 } 274 256 275 /* This should be equivalent to using the %.8e format specifier, but always276 * using '.' as decimal separator. This doesn't handle +/-INF or NAN, since277 * the GLSL parser wouldn't be able to handle those anyway. */278 static void shader_glsl_ftoa(float value, char *s)279 {280 int x, frac, exponent;281 const char *sign = "";282 double d;283 284 d = value;285 if (copysignf(1.0f, value) < 0.0f)286 {287 d = -d;288 sign = "-";289 }290 291 if (d == 0.0f)292 {293 x = 0;294 frac = 0;295 exponent = 0;296 }297 else298 {299 double t, diff;300 301 exponent = floorf(log10f(d));302 d /= pow(10.0, exponent);303 304 x = d;305 t = (d - x) * 100000000;306 frac = t;307 diff = t - frac;308 309 if ((diff > 0.5) || (diff == 0.5 && (frac & 1)))310 {311 if (++frac >= 100000000)312 {313 frac = 0;314 ++x;315 }316 }317 }318 319 sprintf(s, "%s%d.%08de%+03d", sign, x, frac, exponent);320 }321 322 257 static void shader_glsl_append_imm_vec4(struct wined3d_shader_buffer *buffer, const float *values) 323 258 { 324 259 char str[4][16]; 325 260 326 shader_glsl_ftoa(values[0], str[0]);327 shader_glsl_ftoa(values[1], str[1]);328 shader_glsl_ftoa(values[2], str[2]);329 shader_glsl_ftoa(values[3], str[3]);261 wined3d_ftoa(values[0], str[0]); 262 wined3d_ftoa(values[1], str[1]); 263 wined3d_ftoa(values[2], str[2]); 264 wined3d_ftoa(values[3], str[3]); 330 265 shader_addline(buffer, "vec4(%s, %s, %s, %s)", str[0], str[1], str[2], str[3]); 331 266 } … … 534 469 const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version) 535 470 { 471 unsigned int start = ~0U, end = 0; 536 472 int stack_idx = 0; 537 473 unsigned int heap_idx = 1; … … 541 477 542 478 idx = heap->entries[heap_idx].idx; 543 if (constant_locations[idx] != -1) GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4])); 479 if (constant_locations[idx] != -1) 480 start = end = idx; 544 481 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT; 545 482 … … 557 494 idx = heap->entries[heap_idx].idx; 558 495 if (constant_locations[idx] != -1) 559 GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4])); 496 { 497 if (start > idx) 498 start = idx; 499 if (end < idx) 500 end = idx; 501 } 560 502 561 503 stack[stack_idx++] = HEAP_NODE_TRAVERSE_RIGHT; … … 573 515 idx = heap->entries[heap_idx].idx; 574 516 if (constant_locations[idx] != -1) 575 GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4])); 517 { 518 if (start > idx) 519 start = idx; 520 if (end < idx) 521 end = idx; 522 } 576 523 577 524 stack[stack_idx++] = HEAP_NODE_POP; … … 587 534 } 588 535 } 536 if (start <= end) 537 GL_EXTCALL(glUniform4fvARB(constant_locations[start], end - start + 1, &constants[start * 4])); 589 538 checkGLcall("walk_constant_heap()"); 590 539 } … … 936 885 for (i = 0; i < MAX_TEXTURES; ++i) 937 886 { 887 if (prog->ps.bumpenv_mat_location[i] == -1) 888 continue; 889 938 890 GL_EXTCALL(glUniformMatrix2fvARB(prog->ps.bumpenv_mat_location[i], 1, 0, 939 891 (const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_MAT00])); 940 GL_EXTCALL(glUniform1fARB(prog->ps.bumpenv_lum_scale_location[i], 941 *(const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LSCALE])); 942 GL_EXTCALL(glUniform1fARB(prog->ps.bumpenv_lum_offset_location[i], 943 *(const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LOFFSET])); 944 } 945 892 893 if (prog->ps.bumpenv_lum_scale_location[i] != -1) 894 { 895 GL_EXTCALL(glUniform1fvARB(prog->ps.bumpenv_lum_scale_location[i], 1, 896 (const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LSCALE])); 897 GL_EXTCALL(glUniform1fvARB(prog->ps.bumpenv_lum_offset_location[i], 1, 898 (const float *)&state->texture_states[i][WINED3D_TSS_BUMPENV_LOFFSET])); 899 } 900 } 901 902 if (prog->ps.tex_factor_location != -1) 903 { 946 904 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col); 947 GL_EXTCALL(glUniform4fARB(prog->ps.tex_factor_location, col[0], col[1], col[2], col[3])); 905 GL_EXTCALL(glUniform4fvARB(prog->ps.tex_factor_location, 1, col)); 906 } 948 907 949 908 if (state->render_states[WINED3D_RS_SPECULARENABLE]) … … 1296 1255 { 1297 1256 shader_addline(buffer, "const vec4 srgb_const0 = "); 1298 shader_glsl_append_imm_vec4(buffer, srgb_const0);1257 shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const0); 1299 1258 shader_addline(buffer, ";\n"); 1300 1259 shader_addline(buffer, "const vec4 srgb_const1 = "); 1301 shader_glsl_append_imm_vec4(buffer, srgb_const1);1260 shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const1); 1302 1261 shader_addline(buffer, ";\n"); 1303 1262 } … … 1682 1641 { 1683 1642 case WINED3D_DATA_FLOAT: 1684 shader_glsl_ftoa(*(const float *)reg->immconst_data, register_name);1643 wined3d_ftoa(*(const float *)reg->immconst_data, register_name); 1685 1644 break; 1686 1645 case WINED3D_DATA_INT: … … 1702 1661 { 1703 1662 case WINED3D_DATA_FLOAT: 1704 shader_glsl_ftoa(*(const float *)®->immconst_data[0], imm_str[0]);1705 shader_glsl_ftoa(*(const float *)®->immconst_data[1], imm_str[1]);1706 shader_glsl_ftoa(*(const float *)®->immconst_data[2], imm_str[2]);1707 shader_glsl_ftoa(*(const float *)®->immconst_data[3], imm_str[3]);1663 wined3d_ftoa(*(const float *)®->immconst_data[0], imm_str[0]); 1664 wined3d_ftoa(*(const float *)®->immconst_data[1], imm_str[1]); 1665 wined3d_ftoa(*(const float *)®->immconst_data[2], imm_str[2]); 1666 wined3d_ftoa(*(const float *)®->immconst_data[3], imm_str[3]); 1708 1667 sprintf(register_name, "vec4(%s, %s, %s, %s)", 1709 1668 imm_str[0], imm_str[1], imm_str[2], imm_str[3]); … … 4977 4936 break; 4978 4937 shader_addline(buffer, "dir = normalize(dir);\n"); 4979 shader_addline(buffer, "diffuse += ( max(0.0, dot(dir, normal))"4938 shader_addline(buffer, "diffuse += (clamp(dot(dir, normal), 0.0, 1.0)" 4980 4939 " * gl_LightSource[%u].diffuse.xyz) / att;\n", i); 4981 4940 if (settings->localviewer) … … 5002 4961 if (!settings->normal) 5003 4962 break; 5004 shader_addline(buffer, "diffuse += ( max(0.0, dot(dir, normal))"4963 shader_addline(buffer, "diffuse += (clamp(dot(dir, normal), 0.0, 1.0)" 5005 4964 " * gl_LightSource[%u].diffuse.xyz) * att;\n", i); 5006 4965 if (settings->localviewer) … … 5017 4976 break; 5018 4977 shader_addline(buffer, "dir = normalize(gl_LightSource[%u].position.xyz);\n", i); 5019 shader_addline(buffer, "diffuse += max(0.0, dot(dir, normal)) * gl_LightSource[%u].diffuse.xyz;\n", i); 4978 shader_addline(buffer, "diffuse += clamp(dot(dir, normal), 0.0, 1.0)" 4979 " * gl_LightSource[%u].diffuse.xyz;\n", i); 5020 4980 shader_addline(buffer, "t = dot(normal, gl_LightSource[%u].halfVector.xyz);\n", i); 5021 4981 shader_addline(buffer, "if (t > 0.0) specular += pow(t, gl_FrontMaterial.shininess)" … … 5125 5085 5126 5086 case WINED3D_FFP_VS_FOG_DEPTH: 5087 if (settings->ortho_fog) 5088 /* Need to undo the [0.0 - 1.0] -> [-1.0 - 1.0] transformation from D3D to GL coordinates. */ 5089 shader_addline(buffer, "gl_FogFragCoord = gl_Position.z * 0.5 + 0.5;\n"); 5090 else 5127 5091 shader_addline(buffer, "gl_FogFragCoord = ec_pos.z;\n"); 5128 5092 break; … … 5523 5487 { 5524 5488 shader_addline(buffer, "const vec4 srgb_const0 = "); 5525 shader_glsl_append_imm_vec4(buffer, srgb_const0);5489 shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const0); 5526 5490 shader_addline(buffer, ";\n"); 5527 5491 shader_addline(buffer, "const vec4 srgb_const1 = "); 5528 shader_glsl_append_imm_vec4(buffer, srgb_const1);5492 shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const1); 5529 5493 shader_addline(buffer, ";\n"); 5530 5494 } … … 5540 5504 const char *texture_function, *coord_mask; 5541 5505 char tex_reg_name[8]; 5542 BOOL proj , clamp;5506 BOOL proj; 5543 5507 5544 5508 if (!(tex_map & (1 << stage))) … … 5559 5523 proj = TRUE; 5560 5524 } 5561 5562 if (settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP5563 || settings->op[stage].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE)5564 clamp = FALSE;5565 else5566 clamp = TRUE;5567 5525 5568 5526 switch (settings->op[stage].tex_type) … … 5657 5615 } 5658 5616 5659 if (clamp)5660 shader_addline(buffer, "tex%u = clamp(%s(ps_sampler%u, ret.%s), 0.0, 1.0);\n",5661 stage, texture_function, stage, coord_mask);5662 else5663 5617 shader_addline(buffer, "tex%u = %s(ps_sampler%u, ret.%s);\n", 5664 5618 stage, texture_function, stage, coord_mask); … … 5670 5624 else if (settings->op[stage].projected == proj_count3) 5671 5625 { 5672 if (clamp)5673 shader_addline(buffer, "tex%u = clamp(%s(ps_sampler%u, gl_TexCoord[%u].xyz), 0.0, 1.0);\n",5674 stage, texture_function, stage, stage);5675 else5676 5626 shader_addline(buffer, "tex%u = %s(ps_sampler%u, gl_TexCoord[%u].xyz);\n", 5677 5627 stage, texture_function, stage, stage); … … 5679 5629 else 5680 5630 { 5681 if (clamp)5682 shader_addline(buffer, "tex%u = clamp(%s(ps_sampler%u, gl_TexCoord[%u].%s), 0.0, 1.0);\n",5683 stage, texture_function, stage, stage, coord_mask);5684 else5685 5631 shader_addline(buffer, "tex%u = %s(ps_sampler%u, gl_TexCoord[%u].%s);\n", 5686 5632 stage, texture_function, stage, stage, coord_mask); … … 6800 6746 caps->xyzrhw = TRUE; 6801 6747 caps->max_active_lights = gl_info->limits.lights; 6802 caps->max_vertex_blend_matrices = 0;6748 caps->max_vertex_blend_matrices = 1; 6803 6749 caps->max_vertex_blend_matrix_index = 0; 6804 6750 caps->vertex_processing_caps = WINED3DVTXPCAPS_TEXGEN … … 6874 6820 { 6875 6821 context->select_shader = 1; 6822 } 6823 6824 static void glsl_vertex_pipe_projection(struct wined3d_context *context, 6825 const struct wined3d_state *state, DWORD state_id) 6826 { 6827 /* Table fog behavior depends on the projection matrix. */ 6828 if (state->render_states[WINED3D_RS_FOGENABLE] 6829 && state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE) 6830 context->select_shader = 1; 6831 transform_projection(context, state, state_id); 6876 6832 } 6877 6833 … … 6929 6885 /* Transform states */ 6930 6886 {STATE_TRANSFORM(WINED3D_TS_VIEW), {STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE }, 6931 {STATE_TRANSFORM(WINED3D_TS_PROJECTION), {STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection }, WINED3D_GL_EXT_NONE},6887 {STATE_TRANSFORM(WINED3D_TS_PROJECTION), {STATE_TRANSFORM(WINED3D_TS_PROJECTION), glsl_vertex_pipe_projection}, WINED3D_GL_EXT_NONE }, 6932 6888 {STATE_TRANSFORM(WINED3D_TS_TEXTURE0), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE }, 6933 6889 {STATE_TRANSFORM(WINED3D_TS_TEXTURE1), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
Note:
See TracChangeset
for help on using the changeset viewer.