From 7709eb4d95e0a0e9e00192d6e6e8bd345b9afcad Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 4 May 2021 01:32:47 +0900 Subject: [PATCH] new mono texture format for gl --- assets/disk0/home/calc.js | 0 assets/disk0/tvdos/gl.js | 80 ++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 assets/disk0/home/calc.js diff --git a/assets/disk0/home/calc.js b/assets/disk0/home/calc.js new file mode 100644 index 0000000..e69de29 diff --git a/assets/disk0/tvdos/gl.js b/assets/disk0/tvdos/gl.js index 9b7e280..b6f3093 100644 --- a/assets/disk0/tvdos/gl.js +++ b/assets/disk0/tvdos/gl.js @@ -16,6 +16,15 @@ GL.Texture = function(w, h, bytes) { throw "Texture data is not an instance of array"; } }; +GL.MonoTex = function(w, h, bits) { + this.width = w; + this.height = h; + this.texData = bits; + + if (!Array.isArray(bits) && !bits.toString().startsWith("[B")) { + throw "Texture data is not an instance of array"; + } +}; GL.SpriteSheet = function(tilew, tileh, tex) { this.tileWidth = tilew; this.tileHeight = tileh; @@ -37,46 +46,65 @@ GL.SpriteSheet = function(tilew, tileh, tex) { return ty; }; }; -GL.drawTexPattern = function(texture, x, y, width, height) { - for (var yy = 0; yy < height; yy++) { - for (var xx = 0; xx < width; xx++) { - var tx = xx % texture.width; - var ty = yy % texture.height; - var c = texture.texData[ty * texture.width + tx]; - graphics.plotPixel(x + xx, y + yy, c); +GL.drawTexPattern = function(texture, x, y, width, height, fgcol, bgcol) { + if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types"); + + for (let yy = 0; yy < height; yy++) { + for (let xx = 0; xx < width;) { + let tx = xx % texture.width; + let ty = yy % texture.height; + if (texture instanceof GL.Texture) { + let c = texture.texData[ty * texture.width + tx]; + graphics.plotPixel(x + xx, y + yy, c); + } + else if (texture instanceof GL.MonoTex) { + let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)]; + for (let i = 0; i < 8; i++) { + let bit = ((octet >>> (7 - i)) & 1 != 0) + graphics.plotPixel(x + xx + i, y + yy, bit ? bgcol : fgcol); + } + } + + xx += (texture instanceof GL.MonoTex) ? 8 : 1; } } }; -GL.drawTexPatternOver = function(texture, x, y, width, height) { - for (var yy = 0; yy < height; yy++) { - for (var xx = 0; xx < width; xx++) { - var tx = xx % texture.width; - var ty = yy % texture.height; - var c = texture.texData[ty * texture.width + tx]; - if ((c & 255) != 255) { - graphics.plotPixel(x + xx, y + yy, c); +GL.drawTexPatternOver = function(texture, x, y, width, height, fgcol) { + if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types"); + + for (let yy = 0; yy < height; yy++) { + for (let xx = 0; xx < width;) { + let tx = xx % texture.width; + let ty = yy % texture.height; + if (texture instanceof GL.Texture) { + if ((c & 255) != 255) { + let c = texture.texData[ty * texture.width + tx]; + graphics.plotPixel(x + xx, y + yy, c); + } } + else if (texture instanceof GL.MonoTex) { + let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)]; + for (let i = 0; i < 8; i++) { + let bit = ((octet >>> (7 - i)) & 1 != 0) + if (bit) graphics.plotPixel(x + xx + i, y + yy, fgcol); + } + } + + xx += (texture instanceof GL.MonoTex) ? 8 : 1; } } }; /* * Draws a texture verbatim - color of 255 will be written to the screen buffer */ -GL.drawTexImage = function(texture, x, y) { - GL.drawTexPattern(texture, x, y, texture.width, texture.height); +GL.drawTexImage = function(texture, x, y, fgcol, bgcol) { + GL.drawTexPattern(texture, x, y, texture.width, texture.height, fgcol, bgcol); }; /* * Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer */ -GL.drawTexImageOver = function(texture, x, y) { - for (var ty = 0; ty < texture.height; ty++) { - for (var tx = 0; tx < texture.width; tx++) { - var c = texture.texData[ty * texture.width + tx]; - if ((c & 255) != 255) { - graphics.plotPixel(x + tx, y + ty, c); - } - } - } +GL.drawTexImageOver = function(texture, x, y, fgcol) { + GL.drawTexPatternOver(texture, x, y, texture.width, texture.height, fgcol); }; GL.drawSprite = function(sheet, xi, yi, x, y) { var offx = sheet.getOffX(xi);