WebGL Textures & Vertices

Beginner's Guide

Page Forty Two

WebGL API getShaderParameter(WebGLShader, COMPILE_STATUS)

It's often helpful to determine if the shader compiled correctly. If not, display some information to help understand what failed. The WebGL API method getShaderParameter(WebGLShader, COMPILE_STATUS) returns false if the shader compilation failed. If getShaderParameter(WebGLShader, COMPILE_STATUS) returns true, everything compiled fine so far.

The first parameter to getShaderParameter(WebGLShader, COMPILE_STATUS) is our shader reference. To obtain information regarding the compile, pass the WebGL constant COMPILE_STATUS as the second parameter. The following listing tests the shader compile status with an if block. If the compile failed, display reasons for the failure next.

if (!gl.getShaderParameter
{ ... }

Listing 40: WebGL API getShaderParameter(WebGLShader, COMPILE_STATUS)

WebGL API getShaderInfoLog(WebGLShader)

The WebGL API method getShaderInfoLog(WebGLShader) returns a String, with information regarding the specified shader. The following listing demonstrates calling getShaderInfoLog(WebGLShader), where shader is a WebGLShader. Read the String for more information regarding errors. Errors result from invalid vertex or fragment shader source code.

var sError = gl.getShaderInfoLog

Listing 41: WebGL API getShaderInfoLog(WebGLShader)

If the shader compiled correctly, then getShader(String,nType) returns a valid WebGLShader. Otherwise getShader(String,nType) returns null. See the source code for method getShader().

WebGL Beginner's Guide Introduction WebGL Beginner's Guide
Copyright © 2015 Seven Thunder Software. All Rights Reserved.