Skip to content

Commit 8be3ee4

Browse files
committed
Graphics Emtpy Texture generation
1 parent 53a0dbd commit 8be3ee4

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ var Graphics = new Class({
4949

5050
if (resourceManager !== undefined)
5151
{
52-
//var gl = state.game.renderer.gl;
53-
//this.passShader = resourceManager.createShader(shaderName, {vert: TexturedAndNormalizedTintedShader.vert, frag: fragmentShader});
54-
//this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE, gl.RGBA, null, width, height);
55-
//this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null);
56-
//state.game.renderer.currentTexture = null; // force rebinding of prev texture
5752
this.resourceManager = resourceManager;
5853
this.gl = state.game.renderer.gl;
5954
}
@@ -407,9 +402,19 @@ var Graphics = new Class({
407402
}
408403
},
409404

410-
bakeToRenderTarget: function ()
405+
generateTexture: function (key, width, height)
411406
{
407+
width = (typeof width === 'number') ? width : this.state.game.config.width;
408+
height = (typeof height === 'number') ? height : this.state.game.config.height;
412409

410+
if (this.gl)
411+
{
412+
this.state.game.textures.create(key, null, width, height);
413+
}
414+
else
415+
{
416+
this.state.game.textures.createCanvas(key, width, height);
417+
}
413418
}
414419

415420
});

v3/src/textures/Texture.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var TextureSource = require('./TextureSource');
2323
* @param {object} source
2424
* @param {number} scaleMode
2525
*/
26-
var Texture = function (manager, key, source)
26+
var Texture = function (manager, key, source, width, height)
2727
{
2828
this.manager = manager;
2929

@@ -55,7 +55,7 @@ var Texture = function (manager, key, source)
5555
// Load the Sources
5656
for (var i = 0; i < source.length; i++)
5757
{
58-
this.source.push(new TextureSource(this, source[i]));
58+
this.source.push(new TextureSource(this, source[i], width, height));
5959
}
6060
};
6161

v3/src/textures/TextureManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ TextureManager.prototype = {
235235
return texture;
236236
},
237237

238-
create: function (key, source)
238+
create: function (key, source, width, height)
239239
{
240-
var texture = new Texture(this, key, source);
240+
var texture = new Texture(this, key, source, width, height);
241241

242242
this.list[key] = texture;
243243

v3/src/textures/TextureSource.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
1515
* @param {object} source
1616
* @param {number} scaleMode
1717
*/
18-
var TextureSource = function (texture, source)
18+
var TextureSource = function (texture, source, width, height)
1919
{
2020
this.texture = texture;
2121

@@ -38,7 +38,7 @@ var TextureSource = function (texture, source)
3838
* @type Number
3939
* @readOnly
4040
*/
41-
this.width = source.naturalWidth || source.width || 0;
41+
this.width = width || source.naturalWidth || source.width || 0;
4242

4343
/**
4444
* The height of the Texture.
@@ -47,7 +47,7 @@ var TextureSource = function (texture, source)
4747
* @type Number
4848
* @readOnly
4949
*/
50-
this.height = source.naturalHeight || source.height || 0;
50+
this.height = height || source.naturalHeight || source.height || 0;
5151

5252
/**
5353
* The scale mode to apply when scaling this texture.

0 commit comments

Comments
 (0)