public void drawCustom(spriteBatcher spriteBatcher, spriteMat _mat, spriteRect uv, spriteRect rect, spriteColor c, spriteColor c2) { _mat.tex0 = this; { var p = this.pointbuf[0]; p.x = rect.x; p.y = rect.y; p.z = 0; p.u = uv.x; p.v = uv.y; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a; p = this.pointbuf[1]; p.x = rect.x + rect.w; p.y = rect.y; p.z = 0; p.u = uv.x + uv.w; p.v = uv.y; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a; p = this.pointbuf[2]; p.x = rect.x; p.y = rect.y + rect.h; p.z = 0; p.u = uv.x; p.v = uv.y + uv.h; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a; p = this.pointbuf[3]; p.x = rect.x + rect.w; p.y = rect.y + rect.h; p.z = 0; p.u = uv.x + uv.w; p.v = uv.y + uv.h; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a; } spriteBatcher.setMat(_mat); spriteBatcher.addRect(this.pointbuf); }
public void drawSpriteCustom(string atlas, string sprite, spriteMat _mat, spriteRect rect, spriteColor color = null, spriteColor color2 = null) { if (color == null) { color = spriteColor.white; } if (color2 == null) { color2 = spriteColor.white; } var a = atlasMgr.Instance().load(this.webgl, atlas); if (a == null) { return; } var r = a.sprites[sprite]; if (r == Script.Undefined) { return; } if (a.texture == null) { return; } a.texture.drawCustom(this.spriteBatcher, _mat, r.ToRect(), rect, color, color2); }
public void drawTextureCustom(spriteTexture texture, spriteMat _mat, spriteRect rect, spriteRect uvrect, spriteColor color = null, spriteColor color2 = null) { //if (uvrect == null) // uvrect = spriteRect.one; if (color == null) { color = spriteColor.white; } if (color2 == null) { color2 = spriteColor.white; } texture.drawCustom(this.spriteBatcher, _mat, uvrect, rect, color, color2); }
public void endbatch() { this.mat = null; if (this.dataseek == 0) { return; } //填充vbo this.webgl.BufferData(this.webgl.ARRAY_BUFFER, this.array, this.webgl.DYNAMIC_DRAW); //绘制 this.webgl.DrawArrays(this.webgl.TRIANGLES, 0, this.dataseek); //清理状态,可以不干 //this.webgl.bindBuffer(this.webgl.ARRAY_BUFFER, null); //this.data.length = 0; this.dataseek = 0; }
public spriteFont(WebGLRenderingContext webgl, string urlconfig, spriteTexture texture) { this.webgl = webgl; if (urlconfig != null) { lighttool.loadTool.loadText(urlconfig, (txt, err) => { this._parse(txt); } ); } this.texture = texture; this.mat = new spriteMat();//ness this.mat.shader = "spritefont"; this.mat.tex0 = this.texture; this.mat.transparent = true; }
public void drawSprite9Custom(string atlas, string sprite, spriteMat _mat, spriteRect rect, spriteBorder border, spriteColor color = null, spriteColor color2 = null) { if (color == null) { color = spriteColor.white; } if (color2 == null) { color2 = spriteColor.white; } var a = atlasMgr.Instance().load(this.webgl, atlas); if (a == null) { return; } var _r = a.sprites[sprite]; if (_r == Script.Undefined) { return; } var l = (border.l - 1) / a.texturewidth; var r = (border.r - 1) / a.texturewidth; var t = (border.t - 1) / a.textureheight; var b = (border.b - 1) / a.textureheight; //left top this.uvrect.x = _r.x; this.uvrect.y = _r.y; this.uvrect.w = l; this.uvrect.h = t; this.trect.x = rect.x; this.trect.y = rect.y; this.trect.w = border.l; this.trect.h = border.t; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //top this.uvrect.x = _r.x + l; this.uvrect.y = _r.y; this.uvrect.w = _r.w - r - l; this.uvrect.h = t; this.trect.x = rect.x + border.l; this.trect.y = rect.y; this.trect.w = rect.w - border.r - border.l; this.trect.h = border.t; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //right top this.uvrect.x = _r.x + _r.w - r; this.uvrect.y = _r.y; this.uvrect.w = r; this.uvrect.h = t; this.trect.x = rect.x + rect.w - border.r; this.trect.y = rect.y; this.trect.w = border.r; this.trect.h = border.t; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //left this.uvrect.x = _r.x; this.uvrect.y = _r.y + t; this.uvrect.w = l; this.uvrect.h = _r.h - t - b; this.trect.x = rect.x; this.trect.y = rect.y + border.t; this.trect.w = border.l; this.trect.h = rect.h - border.t - border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //center this.uvrect.x = _r.x + l; this.uvrect.y = _r.y + t; this.uvrect.w = _r.w - r - l; this.uvrect.h = _r.h - t - b; this.trect.x = rect.x + border.l; this.trect.y = rect.y + border.t; this.trect.w = rect.w - border.r - border.l; this.trect.h = rect.h - border.t - border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //right this.uvrect.x = _r.x + _r.w - r; this.uvrect.y = _r.y + t; this.uvrect.w = r; this.uvrect.h = _r.h - t - b; this.trect.x = rect.x + rect.w - border.r; this.trect.y = rect.y + border.t; this.trect.w = border.r; this.trect.h = rect.h - border.t - border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //left bottom this.uvrect.x = _r.x; this.uvrect.y = _r.h + _r.y - b; this.uvrect.w = l; this.uvrect.h = b; this.trect.x = rect.x; this.trect.y = rect.y + rect.h - border.b; this.trect.w = border.l; this.trect.h = border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //bottom this.uvrect.x = _r.x + l; this.uvrect.y = _r.h + _r.y - b; this.uvrect.w = _r.w - r - l; this.uvrect.h = b; this.trect.x = rect.x + border.l; this.trect.y = rect.y + rect.h - border.b; this.trect.w = rect.w - border.r - border.l; this.trect.h = border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); //right bottom this.uvrect.x = _r.x + _r.w - r; this.uvrect.y = _r.h + _r.y - b; this.uvrect.w = r; this.uvrect.h = b; this.trect.x = rect.x + rect.w - border.r; this.trect.y = rect.y + rect.h - border.b; this.trect.w = border.r; this.trect.h = border.b; a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2); }
public void setMat(spriteMat mat) { if (mat == this.mat) { return; } this.endbatch(); this.webgl.Disable(this.webgl.CULL_FACE); this.mat = mat; if (this.shaderparser.mapshader.ContainsKey(this.mat.shader) == false) { return; } this.shadercode = this.shaderparser.mapshader[this.mat.shader]; //if (this.shadercode == null) return; //指定shader和vbo //关于深度 ,跟着spritebatcher走 this.webgl.DepthMask(false);//这是zwrite if (this.ztest) { this.webgl.Enable(this.webgl.DEPTH_TEST); //这是ztest this.webgl.DepthFunc(this.webgl.LEQUAL); //这是ztest方法 } else { this.webgl.Disable(this.webgl.DEPTH_TEST);//这是ztest } if (this.mat.transparent) { //alphablend ,跟着mat走 this.webgl.Enable(this.webgl.BLEND); this.webgl.BlendEquation(this.webgl.FUNC_ADD); //this.webgl.blendFunc(this.webgl.ONE, this.webgl.ONE_MINUS_SRC_ALPHA); this.webgl.BlendFuncSeparate(this.webgl.ONE, this.webgl.ONE_MINUS_SRC_ALPHA, this.webgl.SRC_ALPHA, this.webgl.ONE); } else { this.webgl.Disable(this.webgl.BLEND); } this.webgl.UseProgram(this.shadercode.program); this.webgl.BindBuffer(this.webgl.ARRAY_BUFFER, this.vbo); //指定固定的数据结构,然后根据存在program的数据去绑定咯。 //绑定vbo和shader顶点格式,这部分应该要区分材质改变与参数改变,可以少切换一些状态 if (this.shadercode.posPos >= 0) { this.webgl.EnableVertexAttribArray(this.shadercode.posPos); //28 是数据步长(字节),就是数据结构的长度 //12 是数据偏移(字节) this.webgl.VertexAttribPointer(this.shadercode.posPos, 3, this.webgl.FLOAT, false, 52, 0); } if (this.shadercode.posColor >= 0) { this.webgl.EnableVertexAttribArray(this.shadercode.posColor); this.webgl.VertexAttribPointer(this.shadercode.posColor, 4, this.webgl.FLOAT, false, 52, 12); } if (this.shadercode.posColor2 >= 0) { this.webgl.EnableVertexAttribArray(this.shadercode.posColor2); this.webgl.VertexAttribPointer(this.shadercode.posColor2, 4, this.webgl.FLOAT, false, 52, 28); } if (this.shadercode.posUV >= 0) { this.webgl.EnableVertexAttribArray(this.shadercode.posUV); this.webgl.VertexAttribPointer(this.shadercode.posUV, 2, this.webgl.FLOAT, false, 52, 44); } if (this.shadercode.uniMatrix != null) { this.webgl.UniformMatrix4fv(this.shadercode.uniMatrix, false, (Array)(object)this.matrix); } if (this.shadercode.uniTex0 != null) { this.webgl.ActiveTexture(this.webgl.TEXTURE0); var tex = this.mat.tex0; this.webgl.BindTexture(this.webgl.TEXTURE_2D, tex == null ? null : tex.texture); this.webgl.Uniform1i(this.shadercode.uniTex0, 0); //console.log("settex"); } if (this.shadercode.uniTex1 != null) { this.webgl.ActiveTexture(this.webgl.TEXTURE1); var tex = this.mat.tex1; this.webgl.BindTexture(this.webgl.TEXTURE_2D, tex == null ? null : tex.texture); this.webgl.Uniform1i(this.shadercode.uniTex1, 1); //console.log("settex"); } if (this.shadercode.uniCol0 != null) { this.webgl.Uniform4f(this.shadercode.uniCol0, mat.col0.r, mat.col0.g, mat.col0.b, mat.col0.a); //console.log("settex"); } if (this.shadercode.uniCol1 != null) { this.webgl.Uniform4f(this.shadercode.uniCol1, mat.col1.r, mat.col1.g, mat.col1.b, mat.col1.a); //console.log("settex"); } }