Skip to content

Commit

Permalink
Fix so that regl.stats.shaderCount takes the shader cache into account.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkaman committed Sep 13, 2016
1 parent b6a624a commit 41ddab5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ module.exports = function wrapShaderState (gl, stringStore, stats, config) {
check.command(vertId >= 0, 'missing vertex shader', command)
check.command(fragId >= 0, 'missing fragment shader', command)

stats.shaderCount++

var cache = programCache[fragId]
if (!cache) {
cache = programCache[fragId] = {}
}
var program = cache[vertId]
if (!program) {
program = new REGLProgram(fragId, vertId)
stats.shaderCount++

linkProgram(program, command)
cache[vertId] = program
programList.push(program)
Expand Down
31 changes: 31 additions & 0 deletions test/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ tape('test regl.stats', function (t) {

regl.destroy()
t.equals(stats.shaderCount, 0, 'stats.shaderCount==0 after regl.destroy()')

regl = createREGL(gl)
stats = regl.stats

var frag = [
'precision mediump float;',
'void main () { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); } '
].join('\n')

var vert = [
'precision mediump float;',
'attribute vec2 position;',
'void main () {gl_Position = vec4(position, 0, 1); }'
].join('\n')

var draw3 = regl({
frag: regl.prop('frag'),
vert: regl.prop('vert'),
attributes: { position: [[-1, 0], [0, -1], [1, 1]] },
uniforms: { color: [1, 0, 0, 1] },
count: 3
})

for (var i = 0; i < 30; i++) {
draw3({frag: frag, vert: vert})
}

t.equals(stats.shaderCount, 1, 'stats.shaderCount==1, after calling dynamic drawCommand several times')

regl.destroy()

//
// End Test stats.shaderCount
//
Expand Down

0 comments on commit 41ddab5

Please sign in to comment.