Skip to content

Commit

Permalink
Cleaned up built-in GLSL functions in ShaderProgram
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Sep 20, 2012
1 parent 4da0ec9 commit 2ef6003
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ define([
'../Core/WindingOrder',
'../Core/BoundingRectangle',
'../Core/createGuid',
'../Shaders/BuiltinFunctions',
'./Buffer',
'./BufferUsage',
'./BlendEquation',
Expand Down Expand Up @@ -48,7 +47,6 @@ define([
WindingOrder,
BoundingRectangle,
createGuid,
ShadersBuiltinFunctions,
Buffer,
BufferUsage,
BlendEquation,
Expand Down Expand Up @@ -1111,7 +1109,7 @@ define([
* sp = context.createShaderProgram(vs, fs, attributes); *
*/
Context.prototype.createShaderProgram = function(vertexShaderSource, fragmentShaderSource, attributeLocations) {
return new ShaderProgram(this._gl, this._logShaderCompilation, ShadersBuiltinFunctions, vertexShaderSource, fragmentShaderSource, attributeLocations);
return new ShaderProgram(this._gl, this._logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations);
};

function createBuffer(gl, bufferTarget, typedArrayOrSizeInBytes, usage) {
Expand Down
20 changes: 11 additions & 9 deletions Source/Renderer/ShaderProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ define([
'../Core/Matrix2',
'../Core/Matrix3',
'../Core/Matrix4',
'./UniformDatatype'
'./UniformDatatype',
'../Shaders/BuiltinFunctions'
], function(
DeveloperError,
RuntimeError,
Expand All @@ -16,7 +17,8 @@ define([
Matrix2,
Matrix3,
Matrix4,
UniformDatatype) {
UniformDatatype,
ShadersBuiltinFunctions) {
"use strict";
/*global console*/

Expand Down Expand Up @@ -553,8 +555,8 @@ define([
* @see Context#createShaderProgram
* @see Context#getShaderCache
*/
var ShaderProgram = function(gl, logShaderCompilation, builtInGlslFunctions, vertexShaderSource, fragmentShaderSource, attributeLocations) {
var program = createAndLinkProgram(gl, logShaderCompilation, builtInGlslFunctions, vertexShaderSource, fragmentShaderSource, attributeLocations);
var ShaderProgram = function(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
var program = createAndLinkProgram(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations);
var numberOfVertexAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
var uniforms = findUniforms(gl, program);
var automaticUniforms = findAutomaticUniforms(uniforms.allUniforms);
Expand Down Expand Up @@ -867,7 +869,7 @@ define([
return automatics;
}

var getShaderDefinitions = function(builtInGlslFunctions) {
var getShaderDefinitions = function() {
// I think this should be #line 1 given what the GL ES spec says:
//
// After processing this directive (including its new-line), the implementation will
Expand All @@ -878,7 +880,7 @@ define([
// Functions after constants and uniforms because functions depend on them.
var definitions = getBuiltinConstants() +
getAutomaticUniforms() +
builtInGlslFunctions + '\n\n' +
ShadersBuiltinFunctions + '\n\n' +
'#line 0 \n';

getShaderDefinitions = function() {
Expand All @@ -888,15 +890,15 @@ define([
return definitions;
};

function createAndLinkProgram(gl, logShaderCompilation, builtInGlslFunctions, vertexShaderSource, fragmentShaderSource, attributeLocations) {
function createAndLinkProgram(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
var vsSourceVersioned = extractShaderVersion(vertexShaderSource);
var fsSourceVersioned = extractShaderVersion(fragmentShaderSource);

var vsSource = vsSourceVersioned.versionDirective +
getShaderDefinitions(builtInGlslFunctions) +
getShaderDefinitions() +
commentOutAutomaticUniforms(vsSourceVersioned.modifiedSource);
var fsSource = fsSourceVersioned.versionDirective +
getFragmentShaderPrecision(builtInGlslFunctions) +
getFragmentShaderPrecision() +
getShaderDefinitions() +
commentOutAutomaticUniforms(fsSourceVersioned.modifiedSource);

Expand Down

0 comments on commit 2ef6003

Please sign in to comment.