16
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GLSLのエラーハンドリング

Last updated at Posted at 2013-06-05

便利コード

public void GetProgramInfo(int _param){
	int[] ok = new int[1];
	GLES20.glGetProgramiv(mProgram,_param, ok,0);
    if(ok[0]==0){
    	Log.e(TAG,"error ");
    	Log.e(TAG,GLES20.glGetProgramInfoLog(mProgram));
    }
    
}

glGetShaderiv

glGetShaderiv(GLuint shader,GLenum pname,GLint *params);

glGetShaderiv(shader,GL_SHADER_TYPE...);

戻り値はGL_VERTEX_SHADER,か GL_FRAGMENT_SHADER

  • GL_SHADER_TYPE
  • GL_DELETE_STATUS
  • GL_COMPILE_STATUS....ちゃんとシェーダがコンパイルできたらparamsにはGL_TRUEが返る。失敗したらGL_FALSEが返る。
  • GL_INFO_LOG_LENGTH
  • GL_SHADER_SOURCE_LENGTH

glGetProgramiv

  • GL_DELETE_STATUS
  • GL_LINK_STATUS
  • GL_VALIDATE_STATUS
  • GL_INFO_LOG_LENGTH
  • GL_ATTACHED_SHADERS
  • GL_ACTIVE_ATTRIBUTES
  • GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
  • GL_ACTIVE_UNIFORMS
    : GL_ACTIVE_UNIFORM_MAX_LENGTH : 現在アクティブなユニフォーム変数の名前の最大文字数。なんでこれを知る必要が???

glGetShaderSource

glGetShaderInfoLog

シェーダがちゃんとコンパイルできたか確認する

void GetShaderInfoLog(GLuint shader)
{
	GLsizei bufSize;

	/* シェーダのコンパイル時のログの長さを取得する */
	glGetShaderiv(shader, GL_INFO_LOG_LENGTH , &bufSize);

	if (bufSize > 1) {
		GLchar *infoLog = (GLchar *)malloc(bufSize);

		if (infoLog != NULL) {
			GLsizei length;

			/* シェーダのコンパイル時のログの内容を取得する */
			glGetShaderInfoLog(shader, bufSize, &length, infoLog);
			TRACE("InfoLog:\n%s\n\n", infoLog);
			free(infoLog);
		}
		else
			TRACE("Could not allocate InfoLog buffer.\n");
	}
}
 private int loadShader(int type, String shaderCode){
	   int[] compiled=new int[1];
	   int shader=GLES20.glCreateShader(type);
	   GLES20.glShaderSource(shader, shaderCode);
	   GLES20.glCompileShader(shader);
	   int[] compiled=new int[1];
		   GLES20.glGetShaderiv(shader,GLES20.GL_COMPILE_STATUS,compiled,0);
		   if(compiled[0]==0){//もしコンパイルに失敗していたら
			   Log.e(TAG,GLES20.glGetShaderInfoLog(shader));//何行目がどんなふうに間違ってるか吐き出す。
			   GLES20.glDeleteShader(shader);
			   return 0;
		   }
	   return shader;
   }
}

これを書くと、このように

"warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(8) : warning C7503: OpenGL does not allow C-style casts
0(8) : warning C7503: OpenGL does not allow C-style casts
0(8) : warning C7503: OpenGL does not allow C-style casts
0(12) : warning C7011: implicit cast from "float" to "vec4"
0(13) : error C0000: syntax error, unexpected '}', expecting ',' or ';' at token "}"
0(4) : error C1068: too much data in type constructor"

何行目がエラーなのか教えてくれる。

16
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?