Skip to content

Commit d216793

Browse files
committed
Texture Filtering and Repeat property
1 parent 129a045 commit d216793

7 files changed

Lines changed: 53 additions & 7 deletions

File tree

v3/src/gameobjects/effectlayer/EffectLayer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ var EffectLayer = new Class({
3232
{
3333
GameObject.call(this, state, 'EffectLayer');
3434

35+
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
3536
var resourceManager = state.game.renderer.resourceManager;
37+
var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
3638
var gl;
3739

3840
this.dstRenderTarget = null;
@@ -52,7 +54,7 @@ var EffectLayer = new Class({
5254
this.renderTexture = resourceManager.createTexture(
5355
0,
5456
gl.LINEAR, gl.LINEAR,
55-
gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE,
57+
wrap, wrap,
5658
gl.RGBA,
5759
null, width, height
5860
);

v3/src/gameobjects/renderpass/RenderPass.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var RenderPass = new Class({
3636
GameObject.call(this, state, 'RenderPass');
3737

3838
var resourceManager = state.game.renderer.resourceManager;
39+
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
40+
var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
3941
var gl;
4042

4143
this.renderer = state.game.renderer;
@@ -48,7 +50,7 @@ var RenderPass = new Class({
4850
{
4951
gl = state.game.renderer.gl;
5052
this.passShader = resourceManager.createShader(shaderName, {vert: TexturedAndNormalizedTintedShader.vert, frag: fragmentShader});
51-
this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE, gl.RGBA, null, width, height);
53+
this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, wrap, wrap, gl.RGBA, null, width, height);
5254
this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null);
5355
state.game.renderer.currentTexture = null; // force rebinding of prev texture
5456
}

v3/src/gameobjects/tilesprite/TileSprite.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var TileSprite = new Class({
2929
function TileSprite (state, x, y, width, height, texture, frame)
3030
{
3131
var resourceManager = state.game.renderer.resourceManager;
32-
var gl;
3332

3433
GameObject.call(this, state, 'TileSprite');
3534

v3/src/renderer/webgl/WebGLRenderer.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ WebGLRenderer.prototype = {
122122

123123
createTexture: function (source, width, height)
124124
{
125+
var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0);
125126
var gl = this.gl;
126127
var filter = gl.NEAREST;
128+
var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE;
127129

128130
if (!source.glTexture)
129131
{
@@ -143,8 +145,8 @@ WebGLRenderer.prototype = {
143145
0,
144146
filter,
145147
filter,
146-
gl.CLAMP_TO_EDGE,
147-
gl.CLAMP_TO_EDGE,
148+
wrap,
149+
wrap,
148150
gl.RGBA,
149151
null,
150152
width, height
@@ -156,8 +158,8 @@ WebGLRenderer.prototype = {
156158
0,
157159
filter,
158160
filter,
159-
gl.CLAMP_TO_EDGE,
160-
gl.CLAMP_TO_EDGE,
161+
wrap,
162+
wrap,
161163
gl.RGBA,
162164
source.image
163165
);
@@ -434,6 +436,22 @@ WebGLRenderer.prototype = {
434436
return null;
435437
},
436438

439+
setTextureFilterMode: function (texture, filterMode)
440+
{
441+
var gl = this.gl;
442+
var glFilter = [gl.LINEAR, gl.NEAREST][filterMode];
443+
444+
gl.bindTexture(gl.TEXTURE_2D, texture.texture);
445+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, glFilter);
446+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, glFilter);
447+
if (this.currentTexture !== null)
448+
gl.bindTexture(gl.TEXTURE_2D, this.currentTexture.texture);
449+
else
450+
gl.bindTexture(gl.TEXTURE_2D, null);
451+
452+
return texture;
453+
},
454+
437455
uploadCanvasToGPU: function (srcCanvas, dstTexture, shouldUpdateResource)
438456
{
439457
var gl = this.gl;

v3/src/textures/FilterMode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var CONST = {
2+
3+
LINEAR: 0,
4+
NEAREST: 1
5+
6+
};
7+
8+
module.exports = CONST;

v3/src/textures/Texture.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ Texture.prototype = {
171171
destroy: function ()
172172
{
173173
// TODO
174+
},
175+
176+
setFilter: function (filterMode)
177+
{
178+
for (var i = 0; i < this.source.length; i++)
179+
{
180+
this.source[i].setFilter(filterMode);
181+
}
174182
}
175183

176184
};

v3/src/textures/TextureSource.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,13 @@ var TextureSource = function (texture, source, width, height)
127127
}
128128
};
129129

130+
TextureSource.prototype.setFilter = function (filterMode)
131+
{
132+
var game = this.texture.manager.game;
133+
if (game.config.renderType === CONST.WEBGL)
134+
{
135+
game.renderer.setTextureFilterMode(this.glTexture, filterMode);
136+
}
137+
};
138+
130139
module.exports = TextureSource;

0 commit comments

Comments
 (0)