Mrkebubun / o3d

Automatically exported from code.google.com/p/o3d
0 stars 0 forks source link

Mipmap generator does not generate 1x1 texture #216

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Create a "large" plane surface. 
var verts = o3djs.primitives.createPlaneVertices(100000, 100000, 10, 10);

2. Apply a texture to it with a large multiple.
var texCoordStream = verts.findStream(that.m_o3d.Stream.TEXCOORD, 0);

for(var v = 0; v < texCoordStream.elements.length; ++v)
{
    texCoordStream.elements[v] *= 5000;
}

3. Enable mipmapping (I believe it's enabled by default) and position 
camera to look toward horizon.

What is the expected output? What do you see instead?
I expect to see the texture applying fading off in the distance. Instead, 
I see the texture fading to black in the distance.

What version of the product are you using? On what operating system?
Latest released version (0.1.42.3 - I believe) on Windows (XP/7)

What hardware are you using:  graphics card type?  motherboard type?
Multiple graphics cards (NVidia, ATI).

Please provide any additional information below.
The problem is that Bitmap::GenerateMipmaps in o3d/core/cross/bitmap.cc 
does not generate the 1x1 mipmap. There's an off-by-one error that causes 
it to stop at 2x2. So, at the horizon when the 1x1 texture would be used, 
it uses uninitialized memory instead (or more correctly, memory 
initialized to 0).

Original code:
  for (unsigned int level = 1; level < num_mipmaps; ++level) {

Corrected code:
  for (unsigned int level = 1; level <= num_mipmaps; ++level) {

I've attached a patch for this file.

This issue was also posted on the O3D blog:
http://groups.google.com/group/o3d-
discuss/browse_thread/thread/79ced45b1d78f26e#

A sample that demonstrates the issue is at:
http://www.eoir.com/samples/texture_demo/

Original issue reported on code.google.com by chris.bu...@gmail.com on 8 Mar 2010 at 7:39

Attachments: