Game Development Reference
In-Depth Information
else
{
GLES20.glAttachShader(m_ShaderProgram,m_FragmentShader);
Log.d("DEBUG - FRAGMENT SHADER ATTACHED ",
"In InitFragmentShader()");
}
}
The ReadInShader() function is called by the InitFragmentShader() and InitVertexShader()
functions (see Listing 4-10).
Listing 4-10. ReadInShader() Function
StringBuffer ReadInShader(int ResourceId)
{
StringBuffer TempBuffer = new StringBuffer();
InputStream inputStream = m_Context.getResources().openRawResource(ResourceId);
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
try
{
String read = in.readLine();
while (read != null)
{
TempBuffer.append(read + "\n");
read = in.readLine();
}
}
catch (Exception e)
{
//Send a ERROR log message and log the exception.
Log.e("ERROR - SHADER READ ERROR",
"Error in ReadInShader(): " +
e.getLocalizedMessage());
}
return TempBuffer;
}
First, a new string buffer object is created, called TempBuffer .
Next, a new InputStream object is created from the shader source file, using the file's resource
id. This input stream is then used to create an InputStreamReader , which is then used to create a
BufferedReader object called “ in .” The in object is then used to read in the shader source code
line by line, and each line is added to the TempBuffer string buffer that was created first. If any error
occurs, an error message is printed out in the Android LogCat window within the Eclipse IDE.
Finally, the shader source code is returned in a StringBuffer object.
The imports that bring BufferedReader, InputStreamReader, and InputStream into the current
namespace are as follows:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
 
Search WWH ::




Custom Search