Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2594 closed defect (fixed)

Misaligned LOS texture

Reported by: Philip Taylor Owned by: philip
Priority: Should Have Milestone: Alpha 17
Component: Core engine Keywords:
Cc: Patch:

Description

See video from http://www.wildfiregames.com/forum/index.php?showtopic=18713

The LOS texture (as rendered onto both the minimap and the main view) appears to be skewed by 45 degrees - see in particular the angled ovals on the minimap, which should be circles.

Exactly the same effect can be reproduced if Renderer.cpp's glPixelStorei(GL_UNPACK_ALIGNMENT,1); is changed to 2. We pass an odd-sized array of bytes into glTexSubImage2D, but it's being interpreted as if it was 1 byte wider (making it a multiple of 2), leading to that skewed pattern. But that shouldn't be happening when we set it to 1.

I don't know whether there's a bug in the graphics drivers, or FRAPS, or some other process that wants to render some overlay inside GL applications, or possibly in the game itself (which seems unlikely since we only call glPixelStorei in one place). I've not seen anyone else report the same problem before.

We should be able to avoid this problem by only attempting to pass nicely-aligned arrays into glTexSubImage2D. That's possibly helpful for performance too, since drivers may prefer aligned copies. It would be nice to understand exactly what conditions cause this failure, though.

Change History (3)

comment:1 by Philip Taylor, 10 years ago

I think the LOS texture should be the only one affected.

glTexSubImage2D is also used by TerrainTextureOverlay (which is not actually used by anything except the WIP pathfinder rewrite, and anyway the texture is usually 0.25/0.5/1/4 times the size of the map in tiles (which is a multiple of 16)); and by CMiniMap (multiple of 16) and CTerritoryTexture (multiple of 16).

glTexImage2D is only called with power-of-two sized textures, so anything >=4x4 is fine. Stride doesn't matter for 1x1 or 2x1. Hopefully we don't have any other 1xN or 2xN textures (though I haven't checked carefully). Compressed textures aren't affected by this.

comment:2 by philip, 10 years ago

Owner: set to philip
Resolution: fixed
Status: newclosed

In 15216:

Attempt to work around LOS texture alignment bug.

For unknown reasons, sometimes glTexSubImage2D acts as if GL_UNPACK_ALIGNMENT = 2 or 4, instead of 1. This causes the odd-sized array uploaded for the LOS texture to be interpreted incorrectly, and the LOS texture gets rendered very incorrectly.

Pad the array to a multiple of 4 in all cases, so that GL_UNPACK_ALIGNMENT shouldn't affect it.

Hopefully fixes #2594.

comment:3 by sanderd17, 10 years ago

Milestone: BacklogAlpha 17
Note: See TracTickets for help on using tickets.