<commit_before>package de.markusfisch.android.shadereditor.opengl;

import android.opengl.GLES20;

public class Program
{
	private static String infoLog;

	public static String getInfoLog()
	{
		return infoLog;
	}

	public static int loadProgram(
		String vertexShader,
		String fragmentShader )
	{
		int vs, fs, p = 0;

		if( (vs = compileShader(
			GLES20.GL_VERTEX_SHADER,
			vertexShader )) != 0 )
		{
			if( (fs = compileShader(
				GLES20.GL_FRAGMENT_SHADER,
				fragmentShader )) != 0 )
			{
				p = linkProgram( vs, fs );

				// mark shader objects as deleted so they get
				// deleted as soon as glDeleteProgram() does
				// detach them
				GLES20.glDeleteShader( fs );
			}

			// same as above
			GLES20.glDeleteShader( vs );
		}

		return p;
	}

	private static int linkProgram( int... shaders )
	{
		int p = GLES20.glCreateProgram();

		if( p == 0 )
			return 0;

		for( int n = 0, l = shaders.length; n < l; ++n )
			GLES20.glAttachShader( p, shaders[n] );

		GLES20.glLinkProgram( p );

		int[] linkStatus = new int[1];
		GLES20.glGetProgramiv(
			p,
			GLES20.GL_LINK_STATUS,
			linkStatus, 0 );

		if( linkStatus[0] != GLES20.GL_TRUE )
		{
			infoLog = GLES20.glGetProgramInfoLog( p );

			GLES20.glDeleteProgram( p );
			p = 0;
		}

		return p;
	}

	private static int compileShader( int type, String src )
	{
		int s = GLES20.glCreateShader( type );

		if( s == 0 )
			return 0;

		GLES20.glShaderSource( s, src );
		GLES20.glCompileShader( s );

		int[] compiled = new int[1];
		GLES20.glGetShaderiv(
			s,
			GLES20.GL_COMPILE_STATUS,
			compiled,
			0 );

		if( compiled[0] == 0 )
		{
			infoLog = GLES20.glGetShaderInfoLog( s );

			GLES20.glDeleteShader( s );
			s = 0;
		}

		return s;
	}
}<commit_msg>Generic error messages if creating a shader fails<commit_after>package de.markusfisch.android.shadereditor.opengl;

import android.opengl.GLES20;

public class Program
{
	private static String infoLog;

	public static String getInfoLog()
	{
		return infoLog;
	}

	public static int loadProgram(
		String vertexShader,
		String fragmentShader )
	{
		int vs, fs, p = 0;

		if( (vs = compileShader(
			GLES20.GL_VERTEX_SHADER,
			vertexShader )) != 0 )
		{
			if( (fs = compileShader(
				GLES20.GL_FRAGMENT_SHADER,
				fragmentShader )) != 0 )
			{
				p = linkProgram( vs, fs );

				// mark shader objects as deleted so they get
				// deleted as soon as glDeleteProgram() does
				// detach them
				GLES20.glDeleteShader( fs );
			}

			// same as above
			GLES20.glDeleteShader( vs );
		}

		return p;
	}

	private static int linkProgram( int... shaders )
	{
		int p = GLES20.glCreateProgram();

		if( p == 0 )
		{
			infoLog = "Cannot create program";
			return 0;
		}

		for( int n = 0, l = shaders.length; n < l; ++n )
			GLES20.glAttachShader( p, shaders[n] );

		GLES20.glLinkProgram( p );

		int linkStatus[] = new int[1];
		GLES20.glGetProgramiv(
			p,
			GLES20.GL_LINK_STATUS,
			linkStatus, 0 );

		if( linkStatus[0] != GLES20.GL_TRUE )
		{
			infoLog = GLES20.glGetProgramInfoLog( p );

			GLES20.glDeleteProgram( p );
			p = 0;
		}

		return p;
	}

	private static int compileShader( int type, String src )
	{
		int s = GLES20.glCreateShader( type );

		if( s == 0 )
		{
			infoLog = "Cannot create shader";
			return 0;
		}

		GLES20.glShaderSource( s, src );
		GLES20.glCompileShader( s );

		int compiled[] = new int[1];
		GLES20.glGetShaderiv(
			s,
			GLES20.GL_COMPILE_STATUS,
			compiled,
			0 );

		if( compiled[0] == 0 )
		{
			infoLog = GLES20.glGetShaderInfoLog( s );

			GLES20.glDeleteShader( s );
			s = 0;
		}

		return s;
	}
}
{'fraction_non_alphanumeric': 0.12043490381934764, 'fraction_numerical': 0.031781432952327854, 'mean_word_length': 2.776842105263158, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6349611', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1350, 'n_words': 343}