Commit eb78c2a0 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Const correctness fixes for utils.c.

parent 5118108c
......@@ -3025,7 +3025,7 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
BOOL use_pshader = use_ps(device);
BOOL use_vshader = use_vs(device);
struct ffp_frag_settings settings;
struct arbfp_ffp_desc *desc;
const struct arbfp_ffp_desc *desc;
unsigned int i;
if(isStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE))) {
......@@ -3043,23 +3043,25 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
if(!use_pshader) {
/* Find or create a shader implementing the fixed function pipeline settings, then activate it */
gen_ffp_frag_op(stateblock, &settings, FALSE);
desc = (struct arbfp_ffp_desc *) find_ffp_frag_shader(priv->fragment_shaders, &settings);
desc = (const struct arbfp_ffp_desc *)find_ffp_frag_shader(priv->fragment_shaders, &settings);
if(!desc) {
desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
if(!desc) {
struct arbfp_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc));
if (!new_desc)
{
ERR("Out of memory\n");
return;
}
desc->num_textures_used = 0;
new_desc->num_textures_used = 0;
for(i = 0; i < GL_LIMITS(texture_stages); i++) {
if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
desc->num_textures_used = i;
new_desc->num_textures_used = i;
}
memcpy(&desc->parent.settings, &settings, sizeof(settings));
desc->shader = gen_arbfp_ffp_shader(&settings, stateblock);
add_ffp_frag_shader(priv->fragment_shaders, &desc->parent);
TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
memcpy(&new_desc->parent.settings, &settings, sizeof(settings));
new_desc->shader = gen_arbfp_ffp_shader(&settings, stateblock);
add_ffp_frag_shader(priv->fragment_shaders, &new_desc->parent);
TRACE("Allocated fixed function replacement shader descriptor %p\n", new_desc);
desc = new_desc;
}
/* Now activate the replacement program. GL_FRAGMENT_PROGRAM_ARB is already active(however, note the
......
......@@ -802,30 +802,32 @@ static GLuint gen_ati_shader(struct texture_stage_op op[MAX_TEXTURES], WineD3D_G
#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
IWineD3DDeviceImpl *This = stateblock->wineD3DDevice;
struct atifs_ffp_desc *desc;
const struct atifs_ffp_desc *desc;
struct ffp_frag_settings settings;
struct atifs_private_data *priv = (struct atifs_private_data *) This->fragment_priv;
DWORD mapped_stage;
unsigned int i;
gen_ffp_frag_op(stateblock, &settings, TRUE);
desc = (struct atifs_ffp_desc *) find_ffp_frag_shader(priv->fragment_shaders, &settings);
desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(priv->fragment_shaders, &settings);
if(!desc) {
desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
if(!desc) {
struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc));
if (!new_desc)
{
ERR("Out of memory\n");
return;
}
desc->num_textures_used = 0;
new_desc->num_textures_used = 0;
for(i = 0; i < GL_LIMITS(texture_stages); i++) {
if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
desc->num_textures_used = i;
new_desc->num_textures_used = i;
}
memcpy(&desc->parent.settings, &settings, sizeof(settings));
desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
add_ffp_frag_shader(priv->fragment_shaders, &desc->parent);
TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
memcpy(&new_desc->parent.settings, &settings, sizeof(settings));
new_desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
add_ffp_frag_shader(priv->fragment_shaders, &new_desc->parent);
TRACE("Allocated fixed function replacement shader descriptor %p\n", new_desc);
desc = new_desc;
}
/* GL_ATI_fragment_shader depends on the GL_TEXTURE_xD enable settings. Update the texture stages
......
......@@ -3561,8 +3561,9 @@ static void shader_glsl_destroy(IWineD3DBaseShader *iface) {
}
}
static unsigned int glsl_program_key_hash(void *key) {
glsl_program_key_t *k = (glsl_program_key_t *)key;
static unsigned int glsl_program_key_hash(const void *key)
{
const glsl_program_key_t *k = (const glsl_program_key_t *)key;
unsigned int hash = k->vshader | ((DWORD_PTR) k->pshader) << 16;
hash += ~(hash << 15);
......@@ -3575,9 +3576,10 @@ static unsigned int glsl_program_key_hash(void *key) {
return hash;
}
static BOOL glsl_program_key_compare(void *keya, void *keyb) {
glsl_program_key_t *ka = (glsl_program_key_t *)keya;
glsl_program_key_t *kb = (glsl_program_key_t *)keyb;
static BOOL glsl_program_key_compare(const void *keya, const void *keyb)
{
const glsl_program_key_t *ka = (const glsl_program_key_t *)keya;
const glsl_program_key_t *kb = (const glsl_program_key_t *)keyb;
return ka->vshader == kb->vshader && ka->pshader == kb->pshader &&
(memcmp(&ka->ps_args, &kb->ps_args, sizeof(kb->ps_args)) == 0);
......
......@@ -465,7 +465,8 @@ void init_type_lookup(WineD3D_GL_Info *gl_info) {
#define GLINFO_LOCATION This->adapter->gl_info
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, WineD3D_GL_Info *gl_info, const GlPixelFormatDesc **glDesc)
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const WineD3D_GL_Info *gl_info,
const GlPixelFormatDesc **glDesc)
{
int idx = getFmtIdx(fmt);
......@@ -1622,7 +1623,8 @@ void hash_table_destroy(struct hash_table_t *table, void (*free_value)(void *val
HeapFree(GetProcessHeap(), 0, table);
}
static inline struct hash_table_entry_t *hash_table_get_by_idx(struct hash_table_t *table, void *key, unsigned int idx)
static inline struct hash_table_entry_t *hash_table_get_by_idx(struct hash_table_t *table, const void *key,
unsigned int idx)
{
struct hash_table_entry_t *entry;
......@@ -1770,7 +1772,7 @@ void hash_table_remove(struct hash_table_t *table, void *key)
hash_table_put(table, key, NULL);
}
void *hash_table_get(struct hash_table_t *table, void *key)
void *hash_table_get(struct hash_table_t *table, const void *key)
{
unsigned int idx;
struct hash_table_entry_t *entry;
......@@ -2002,9 +2004,11 @@ void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_setting
}
#undef GLINFO_LOCATION
struct ffp_frag_desc *find_ffp_frag_shader(struct hash_table_t *fragment_shaders, struct ffp_frag_settings *settings)
const struct ffp_frag_desc *find_ffp_frag_shader(struct hash_table_t *fragment_shaders,
const struct ffp_frag_settings *settings)
{
return (struct ffp_frag_desc *)hash_table_get(fragment_shaders, settings);}
return (const struct ffp_frag_desc *)hash_table_get(fragment_shaders, settings);
}
void add_ffp_frag_shader(struct hash_table_t *shaders, struct ffp_frag_desc *desc) {
struct ffp_frag_settings *key = HeapAlloc(GetProcessHeap(), 0, sizeof(*key));
......@@ -2110,10 +2114,11 @@ void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCont
}
#undef GLINFO_LOCATION
unsigned int ffp_frag_program_key_hash(void *key) {
struct ffp_frag_settings *k = (struct ffp_frag_settings *)key;
unsigned int ffp_frag_program_key_hash(const void *key)
{
const struct ffp_frag_settings *k = (const struct ffp_frag_settings *)key;
unsigned int hash = 0, i;
DWORD *blob;
const DWORD *blob;
/* This takes the texture op settings of stage 0 and 1 into account.
* how exactly depends on the memory laybout of the compiler, but it
......@@ -2122,7 +2127,7 @@ unsigned int ffp_frag_program_key_hash(void *key) {
* the ffp setup has distinct stage 0 and 1 settings.
*/
for(i = 0; i < 2; i++) {
blob = (DWORD *) &k->op[i];
blob = (const DWORD *)&k->op[i];
hash ^= blob[0] ^ blob[1];
}
......@@ -2136,9 +2141,10 @@ unsigned int ffp_frag_program_key_hash(void *key) {
return hash;
}
BOOL ffp_frag_program_key_compare(void *keya, void *keyb) {
struct ffp_frag_settings *ka = (struct ffp_frag_settings *)keya;
struct ffp_frag_settings *kb = (struct ffp_frag_settings *)keyb;
BOOL ffp_frag_program_key_compare(const void *keya, const void *keyb)
{
const struct ffp_frag_settings *ka = (const struct ffp_frag_settings *)keya;
const struct ffp_frag_settings *kb = (const struct ffp_frag_settings *)keyb;
return memcmp(ka, kb, sizeof(*ka)) == 0;
}
......@@ -44,8 +44,8 @@
#include "wine/list.h"
/* Hash table functions */
typedef unsigned int (hash_function_t)(void *key);
typedef BOOL (compare_function_t)(void *keya, void *keyb);
typedef unsigned int (hash_function_t)(const void *key);
typedef BOOL (compare_function_t)(const void *keya, const void *keyb);
struct hash_table_entry_t {
void *key;
......@@ -69,7 +69,7 @@ struct hash_table_t {
struct hash_table_t *hash_table_create(hash_function_t *hash_function, compare_function_t *compare_function);
void hash_table_destroy(struct hash_table_t *table, void (*free_value)(void *value, void *cb), void *cb);
void *hash_table_get(struct hash_table_t *table, void *key);
void *hash_table_get(struct hash_table_t *table, const void *key);
void hash_table_put(struct hash_table_t *table, void *key, void *value);
void hash_table_remove(struct hash_table_t *table, void *key);
......@@ -876,10 +876,11 @@ struct ffp_frag_desc
};
void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype);
struct ffp_frag_desc *find_ffp_frag_shader(struct hash_table_t *fragment_shaders, struct ffp_frag_settings *settings);
const struct ffp_frag_desc *find_ffp_frag_shader(struct hash_table_t *fragment_shaders,
const struct ffp_frag_settings *settings);
void add_ffp_frag_shader(struct hash_table_t *shaders, struct ffp_frag_desc *desc);
BOOL ffp_frag_program_key_compare(void *keya, void *keyb);
unsigned int ffp_frag_program_key_hash(void *key);
BOOL ffp_frag_program_key_compare(const void *keya, const void *keyb);
unsigned int ffp_frag_program_key_hash(const void *key);
/*****************************************************************************
* IWineD3D implementation structure
......@@ -2435,8 +2436,7 @@ typedef struct {
} StaticPixelFormatDesc;
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt,
WineD3D_GL_Info *gl_info,
const GlPixelFormatDesc **glDesc);
const WineD3D_GL_Info *gl_info, const GlPixelFormatDesc **glDesc);
static inline BOOL use_vs(IWineD3DDeviceImpl *device) {
return (device->vs_selected_mode != SHADER_NONE
......
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