aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 2ce8d1a70ef535f219a58a6768a1965a321bbce4
parent ad191b93e2413ffdfa2660986302c4336e4cd6de
Author: anon <anon@example.com>
Date:   Thu, 15 Oct 2026 14:36:56 +0000

Combine additive texture RGB and vertex alpha

Diffstat:
Mdecompiled/runtime/gl_renderer.c | 16++++++++--------
Mdecompiled/runtime/gl_renderer.h | 2+-
Mdecompiled/runtime/linux_graphics.c | 13+++++++------
Mdecompiled/tests/devices.c | 6++++--
4 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/decompiled/runtime/gl_renderer.c b/decompiled/runtime/gl_renderer.c @@ -7,7 +7,7 @@ #include <assert.h> static GLuint program, vertex_array, vertex_buffer, index_buffer; -static GLint texture_enabled, texture_alpha, texture_modulate, texture_modulate_alpha; +static GLint texture_enabled, texture_alpha, texture_color_op, texture_alpha_op; static GLint fog_enabled, fog_color; static int depth_write = 1; static uint32_t depth_function = 4; @@ -62,10 +62,10 @@ int gl_renderer_initialize(void) "in vec4 color; in vec2 uv; in float fog_factor; out vec4 pixel;\n" "uniform bool fog_enabled; uniform vec3 fog_color;\n" "uniform sampler2D image;\n" - "uniform bool textured, has_alpha, modulate, modulate_alpha;\n" + "uniform bool textured, has_alpha; uniform int color_op, alpha_op;\n" "void main() { pixel=color; if(textured) { vec4 t=texture(image,uv);" - "pixel.rgb=modulate ? t.rgb*color.rgb : t.rgb;" - "pixel.a=has_alpha ? t.a : 1.0; if(modulate_alpha) pixel.a*=color.a; }" + "pixel.rgb=color_op==4 ? t.rgb*color.rgb : color_op==7 ? min(vec3(1.0),t.rgb+color.rgb) : t.rgb;" + "pixel.a=alpha_op==3 ? color.a : has_alpha ? t.a : 1.0; if(alpha_op==4) pixel.a*=color.a; }" "if(fog_enabled) pixel.rgb=mix(fog_color,pixel.rgb,clamp(fog_factor,0.0,1.0)); }\n" }; program = glCreateProgram(); @@ -99,8 +99,8 @@ int gl_renderer_initialize(void) texture_enabled = glGetUniformLocation(program, "textured"); texture_alpha = glGetUniformLocation(program, "has_alpha"); - texture_modulate = glGetUniformLocation(program, "modulate"); - texture_modulate_alpha = glGetUniformLocation(program, "modulate_alpha"); + texture_color_op = glGetUniformLocation(program, "color_op"); + texture_alpha_op = glGetUniformLocation(program, "alpha_op"); fog_enabled = glGetUniformLocation(program, "fog_enabled"); fog_color = glGetUniformLocation(program, "fog_color"); glUseProgram(program); @@ -383,8 +383,8 @@ void gl_renderer_set_texture(const struct gl_texture_state *state) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, state->clamp_u ? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, state->clamp_v ? GL_CLAMP_TO_EDGE : GL_REPEAT); glUniform1i(texture_alpha, state->alpha); - glUniform1i(texture_modulate, state->modulate); - glUniform1i(texture_modulate_alpha, state->modulate_alpha); + glUniform1i(texture_color_op, state->color_op); + glUniform1i(texture_alpha_op, state->alpha_op); } else glBindTexture(GL_TEXTURE_2D, 0); check_graphics("texture binding"); } diff --git a/decompiled/runtime/gl_renderer.h b/decompiled/runtime/gl_renderer.h @@ -13,7 +13,7 @@ struct gl_vertex { }; struct gl_texture_state { struct gl_target *image; - int min_linear, mag_linear, clamp_u, clamp_v, alpha, modulate, modulate_alpha, mip_point; + int min_linear, mag_linear, clamp_u, clamp_v, alpha, color_op, alpha_op, mip_point; }; int gl_renderer_initialize(void); diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c @@ -53,7 +53,7 @@ static struct device_object { uint32_t interface, references, cull; uint32_t min_filter, mag_filter, mip_filter, address, address_u, address_v, color_op, alpha_op; uint32_t sampler_u, sampler_v, texture_transform; - uint32_t alpha_arg2; + uint32_t color_arg2, alpha_arg2; uint32_t fog_enabled, fog_color, fog_start, fog_end, fog_density, fog_vertex_mode; uint32_t blend, source_blend, destination_blend, depth_write, depth_function, clipping, lighting; uint32_t ambient, normalize_normals, material[17], viewport[6], transforms[4][16]; @@ -1336,7 +1336,7 @@ static void create_device(void) device->mip_filter = 1; device->color_op = 4; device->alpha_op = 2; - device->alpha_arg2 = 1; + device->color_arg2 = device->alpha_arg2 = 1; device->source_blend = 2; device->destination_blend = 1; device->depth_write = 1; @@ -1810,7 +1810,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin struct gl_texture_state state = {device->texture->target, device->min_filter == 2, device->mag_filter == 2, device->sampler_u == 3, device->sampler_v == 3, - device->texture->alpha, device->color_op == 4, device->alpha_op == 4, device->mip_filter == 2}; + device->texture->alpha, device->color_op, device->alpha_op, device->mip_filter == 2}; gl_renderer_set_texture(&state); } else gl_renderer_set_texture(NULL); gl_renderer_set_fog(device->fog_enabled, device->fog_color); @@ -1872,7 +1872,7 @@ static uint32_t texture_stage_state(struct device_object *device, uint32_t state switch (state) { case 1: return device->color_op; case 2: case 5: return 2; /* Texture argument. */ - case 3: return 1; /* Current/diffuse argument. */ + case 3: return device->color_arg2; case 6: return device->alpha_arg2; case 4: return device->alpha_op; case 7: case 8: case 9: case 10: /* Inactive bump matrix. */ @@ -1924,9 +1924,10 @@ static void device_set_texture_state(void) if (device->address_v != value) device->sampler_v = value; device->address_v = value; } - else if (state == 1 && (value == 1 || value == 2 || value == 4)) device->color_op = value; - else if (state == 4 && (value == 2 || value == 4)) device->alpha_op = value; + else if (state == 1 && (value == 1 || value == 2 || value == 4 || value == 7)) device->color_op = value; + else if (state == 4 && (value == 2 || value == 3 || value == 4)) device->alpha_op = value; /* Stage zero's CURRENT and DIFFUSE both select interpolated vertex color. */ + else if (state == 3 && value <= 1) device->color_arg2 = value; else if (state == 6 && value <= 1) device->alpha_arg2 = value; else if (value != texture_stage_state(device, state)) { fprintf(stderr, "Unsupported texture-stage state %u value=%08x\n", state, value); exit(3); diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c @@ -190,8 +190,10 @@ static void textured_triangles(uint32_t draw, uint32_t device, uint32_t target, assert(!invoke(device, 37, 4, 0u, 16u, filter)); assert(!invoke(device, 37, 4, 0u, 17u, filter)); assert(!invoke(device, 37, 4, 0u, 18u, (scenario & 4) ? 2u : 1u)); - assert(!invoke(device, 37, 4, 0u, 1u, (scenario & 3) == 3 ? 2u : 4u)); - assert(!invoke(device, 37, 4, 0u, 4u, scenario & 2 ? 4u : 2u)); + assert(!invoke(device, 37, 4, 0u, 1u, (scenario & 3) == 3 ? 2u : (scenario & 3) == 0 ? 7u : 4u)); + assert(!invoke(device, 37, 4, 0u, 3u, scenario & 4 ? 0u : 1u)); + assert(!invoke(device, 36, 4, 0u, 3u, workspace()) && *memory(workspace()) == (scenario & 4 ? 0u : 1u)); + assert(!invoke(device, 37, 4, 0u, 4u, scenario & 2 ? 4u : scenario & 1 ? 3u : 2u)); assert(!invoke(device, 37, 4, 0u, 6u, scenario & 4 ? 0u : 1u)); assert(!invoke(device, 36, 4, 0u, 6u, workspace()) && *memory(workspace()) == (scenario & 4 ? 0u : 1u)); assert(!invoke(device, 20, 3, 27u, blends[scenario / 8][0]));