1

GLES 2.0 を使用する Android アプリにフラグメント シェーダーがありますが、エミュレーターでは正常に動作しますが、シェーダー プログラムをリンクしようとすると、Nexus 4 で「Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1)」でクラッシュします。

私は基本的に Google のチュートリアル ( http://developer.android.com/training/graphics/opengl/draw.html ) から始めて、そこから取りました。

これは頂点シェーダーです。

uniform mat4 uMVPMatrix;
varying vec2 vTexcoord;
attribute vec4 vPosition;
void main() {
  gl_Position = uMVPMatrix * vPosition;
  vTexcoord = vPosition.xy * vec2(0.5) + vec2(0.5);
}

これはフラグメント シェーダーです。

precision mediump float;
uniform sampler2D uTexture1;
uniform sampler2D uTexture2;
uniform float pointX;
uniform float pointY;
uniform float opening;
uniform float openingBufferZone;
uniform vec4 aColor;
varying vec2 vTexcoord;
float sizeX = 2048.0;
float sizeY = 512.0;
void main() {
  float x = (vTexcoord.x * sizeX) - pointX;
  float y = (vTexcoord.y * sizeY) - pointY;
  float distance = x * x + y * y;
  if (distance < opening) {
    gl_FragColor = texture2D(uTexture2, vTexcoord) * aColor;
  } else {
    if (distance >= opening && distance < opening + openingBufferZone) {
      float inner = (distance-opening)/openingBufferZone;
      vec4 c1 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture1, vTexcoord) * aColor);
      vec4 c2 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture2, vTexcoord) * aColor);
      gl_FragColor = c1 + c2;
    } else {
      gl_FragColor = texture2D(uTexture1, vTexcoord) * aColor;
    }
  }
}

これは私がシェーダーをロードする方法です:

int vertexShader = GLActivity.loadShader(GLES20.GL_VERTEX_SHADER,
                                                   vertexShaderCode);
int fragmentShader = GLActivity.loadShader(GLES20.GL_FRAGMENT_SHADER,
                                                     fragmentShaderCode);
mProgram = GLES20.glCreateProgram();             
GLES20.glAttachShader(mProgram, vertexShader);   
GLES20.glAttachShader(mProgram, fragmentShader); 
GLES20.glLinkProgram(mProgram);                  

その最後の行を実行しようとすると、エラーが発生しますGLES20.glLinkProgram(mProgram);

何らかの理由で、頂点シェーダーの次の 2 行が問題を引き起こしているようです。

vec4 c1 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture1, vTexcoord) * aColor);
vec4 c2 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture2, vTexcoord) * aColor);

単純に変更すると

vec4 c1 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture1, vTexcoord) * aColor);
vec4 c2 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture1, vTexcoord) * aColor);

また

vec4 c1 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture2, vTexcoord) * aColor);
vec4 c2 = (vec4(inner,inner,inner,1.0) * texture2D(uTexture2, vTexcoord) * aColor);

他のすべてをそのままにしておくと、プログラムは正常に実行されます (ただし、明らかに意図したとおりではありません)。

4

3 に答える 3

1

この行を使用して同じ効果がありました。

gl_FragColor = vec4(float(i) / 100.0,0.0,0.0,1.0);

関数内に操作を埋め込むと、 openglesはそれを好まないようです。

于 2014-04-10T03:18:55.823 に答える