在Android上渲染ETC1压缩纹理时出现SIGSEGV错误

时间:2013-02-11 17:44:11

标签: android opengl-es compression textures

在Android上使用ETC1压缩方法绘制对象时出现分段错误。

更具体地说,错误是这样的:

A/libc(27217): Fatal signal 11 (SIGSEGV) at 0x5895c000 (code=1), thread 27231 (Thread-8350)

这是我加载纹理的代码:

private int addTextureCompressed(InputStream input)
{       
    int textureId = 0;

    try 
    {
        int[] textures = new int[1];
        GLES20.glGenTextures(1, textures, 0);

       GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

       textureId = textures[0];
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);

        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

        ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D, 0, 0,GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, input);

    } 
    catch (IOException e) 
    {
        UtilisTSW.printString("Filed");
    } 
    finally 
    {
        try {
            input.close();
            } 
        catch (IOException e) {
                    // ignore exception thrown from close.
            }
    }

    UtilisTSW.printString("Texture id: " + Integer.toString(textureId));

    return textureId;
}

从手机的资源中读取.pkm文件的inputStream并创建纹理;到这里没有问题。

现在来绘画方法:

private void drawGeometry(float[] mvpMatrix, int texHandler, float zoom) {

    GLES20.glUseProgram(SC.getProgram(shaderType));

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                 GLES20.GL_FLOAT, false,
                                 vertexStride, vertexBuffer);

    if (shaderType != SC.COLOR)
    {
        GLES20.glEnableVertexAttribArray(texHandler);
        GLES20.glVertexAttribPointer(texHandler, COORDS_PER_TEX, GLES20.GL_FLOAT, false, textStride, textureBuffer);

        int textSampler = GLES20.glGetUniformLocation(SC.getProgram(shaderType), "s_texture");
        GLES20.glUniform1i(textSampler, 0);
    }

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

    if (shaderType == SC.COLOR)
    {
        // get handle to fragment shader's vColor member
        int mColorHandle = GLES20.glGetUniformLocation(SC.getProgram(shaderType), "vColor");

        // Set color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
    }

    if (shaderType == SC.FADE_WITH_DISTANCE)
    {
        int mAlphaHandle = GLES20.glGetUniformLocation(SC.getProgram(shaderType), "alpha");
        float interpol = 0.0f;

        if (zoom < farCoord)
            interpol = 0.0f;
        else if (zoom >= nearCoord)
            interpol = 1.0f;
        else
            interpol = (zoom - farCoord) / (nearCoord - farCoord);

        GLES20.glUniform1f(mAlphaHandle, interpol);
    }

    // Draw the pannel
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrderLength, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}

它采用模型视图投影矩阵,以及返回的纹理的句柄: gvTexCoordHandle = GLES20.glGetAttribLocation(SC.getProgram(shaderType), "a_texCoord");

执行到达glDrawElements方法时会弹出错误。

使用普通的.png图像作为纹理代码可以正常工作。

如果您需要其他信息,请不要犹豫。

修改

代码在模拟器,Galaxy Ace和Nexus 7上完美运行;但继续撞上我的Galaxy Nexus ......相当愚蠢。 所以我想这是我手机固件的问题?

0 个答案:

没有答案