开发者

Using mipmaps results in garbage textures

开发者 https://www.devze.com 2023-02-11 22:49 出处:网络
I\'m creating my own mipmaps when creating textures, and as soon as I enable mipmaps via GL_LINEAR_MIPMAP_NEAREST (or anything MIPMAP), the textures are just a very dark, blurry mess. If I switch to G

I'm creating my own mipmaps when creating textures, and as soon as I enable mipmaps via GL_LINEAR_MIPMAP_NEAREST (or anything MIPMAP), the textures are just a very dark, blurry mess. If I switch to GL_LINEAR, they're fine.

Here's how I'm creating the texture:

glGenTextures(1, &m_TextureId);
glBindTexture( GL_TEXTURE_2D, id );
int level = 0;

jobject mippedBitmap = srcBitmap;

while (width >= 2 && height >= 2) {
    jniEnv->CallStaticVoidMeth开发者_开发问答od(s_GLUtilsClass, s_texImage2DMethodID,
                     GL_TEXTURE_2D, level, mippedBitmap, 0);

    width >>= 1;
    height >>= 1;
    level++;

    mippedBitmap = createScaledBitmap(jniEnv, srcBitmap, width, height, true);
}

I've omitted all Bitmap.recycle()/NewGlobalRef() calls for brevity. createScaledBitmap is obviously a JNI call to Bitmap.createScaledBitmap().

I also tried the other version of texImage2D that takes the format and type of the bitmap. I've verified that it's always RGBA.

EDIT: To elaborate on the textures - they're really almost black. I tried eraseColor() on the mips with bright colors, and they're still extremely dark.


glGenerateMipmap will do this task faster and much more convenient for you.


The code you're showing will not generate the lower mip levels (1x1 will be missing, e.g.), so your texture will be incomplete. That should make the rendering as if the texturing was not present at all. It's unclear from your description if this is what you're observing.

In all cases, you should provide the mipmaps all the way down to the 1x1 (and for non square textures, this requires some changes in the computation of the new texture size to keep passing 1, as in 4x1 -> 2x1 -> 1x1)


It may be the case that Bitmap.createScaledBitmap does not correct the gamma. Have a look at this thread for code to create gamma-corrected mipmaps

0

精彩评论

暂无评论...
验证码 换一张
取 消