renamed Image to Image32 to prepare to add Image8

This commit is contained in:
DaniTheSkunk 2022-12-17 15:44:20 +00:00
parent fb3a988375
commit 4747abe678
10 changed files with 33 additions and 38 deletions

View File

@ -1,6 +1,6 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import com.danitheskunk.skunkworks.gfx.NineSlice; import com.danitheskunk.skunkworks.gfx.NineSlice;
import com.danitheskunk.skunkworks.gfx.font.FontTTF; import com.danitheskunk.skunkworks.gfx.font.FontTTF;
import com.danitheskunk.skunkworks.gfx.font.FontTileset; import com.danitheskunk.skunkworks.gfx.font.FontTileset;
@ -41,7 +41,7 @@ abstract public class BaseWindow implements IWindow {
} }
@Override @Override
public NineSlice loadNineSlice(Image image) { public NineSlice loadNineSlice(Image32 image) {
int x1 = -1; int x1 = -1;
int x2 = -1; int x2 = -1;
int y1 = -1; int y1 = -1;

View File

@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.backends.gl.Window; import com.danitheskunk.skunkworks.backends.gl.Window;
import com.danitheskunk.skunkworks.gfx.GraphicsBackend; import com.danitheskunk.skunkworks.gfx.GraphicsBackend;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -65,8 +65,8 @@ public class Engine {
return data; return data;
} }
public Image loadImage(String path) { public Image32 loadImage(String path) {
return new Image(loadBytes(path)); return new Image32(loadBytes(path));
} }
public IWindow openWindow(Vec2i size, String title) { public IWindow openWindow(Vec2i size, String title) {

View File

@ -23,15 +23,15 @@ public interface IWindow {
IFont loadFontTileset(String path); IFont loadFontTileset(String path);
NineSlice loadNineSlice(Image image); NineSlice loadNineSlice(Image32 image);
NineSlice loadNineSlice(String path); NineSlice loadNineSlice(String path);
ITexture loadTexture(Image image); ITexture loadTexture(Image32 image);
ITexture loadTexture(String path); ITexture loadTexture(String path);
List<ITexture> loadTextureArray(Image image, Vec2i tileSize); List<ITexture> loadTextureArray(Image32 image, Vec2i tileSize);
List<ITexture> loadTextureArray(String path, Vec2i tileSize); List<ITexture> loadTextureArray(String path, Vec2i tileSize);

View File

@ -2,15 +2,10 @@ package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.Color; import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext; import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image;
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D; import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
import com.danitheskunk.skunkworks.gfx.threedee.Mesh;
import com.danitheskunk.skunkworks.gfx.threedee.Model; import com.danitheskunk.skunkworks.gfx.threedee.Model;
import org.lwjgl.assimp.*; import org.lwjgl.assimp.*;
import java.nio.IntBuffer;
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
public class Test3D extends BaseGame { public class Test3D extends BaseGame {
int trans; int trans;

View File

@ -3,13 +3,13 @@ package com.danitheskunk.skunkworks.backends.gl;
import com.danitheskunk.skunkworks.Recti; import com.danitheskunk.skunkworks.Recti;
import com.danitheskunk.skunkworks.Vec2i; import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.ITexture; import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
class Texture implements ITexture { class Texture implements ITexture {
private final Image img; //for re-blitting onto texture atlas private final Image32 img; //for re-blitting onto texture atlas
private Recti texArea; private Recti texArea;
Texture(Recti texArea, Image img) { Texture(Recti texArea, Image32 img) {
this.texArea = texArea; this.texArea = texArea;
this.img = img; this.img = img;
} }
@ -20,7 +20,7 @@ class Texture implements ITexture {
} }
//setters //setters
Image getImg() { Image32 getImg() {
return img; return img;
} }

View File

@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.backends.gl;
import com.danitheskunk.skunkworks.Recti; import com.danitheskunk.skunkworks.Recti;
import com.danitheskunk.skunkworks.Vec2i; import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.ITexture; import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,11 +16,11 @@ class TextureAtlas {
final private int textureID; final private int textureID;
private final List<Texture> textures; private final List<Texture> textures;
private Texture atlasTexture; //for debugging private Texture atlasTexture; //for debugging
private Image img; private Image32 img;
private boolean shouldUpdate; private boolean shouldUpdate;
TextureAtlas() { TextureAtlas() {
img = new Image(new Vec2i(32, 32)); img = new Image32(new Vec2i(32, 32));
textureID = glGenTextures(); textureID = glGenTextures();
textures = new ArrayList<>(); textures = new ArrayList<>();
shouldUpdate = true; shouldUpdate = true;
@ -33,7 +33,7 @@ class TextureAtlas {
} }
ITexture addTexture(Image img) { ITexture addTexture(Image32 img) {
//todo: do the actual texture stuff //todo: do the actual texture stuff
//this.img = img; //this.img = img;
var texture = new Texture(new Recti(new Vec2i(0, 0), img.getSize()), var texture = new Texture(new Recti(new Vec2i(0, 0), img.getSize()),
@ -49,7 +49,7 @@ class TextureAtlas {
} }
void doubleAtlasSize() { void doubleAtlasSize() {
img = new Image(Vec2i.mul(img.getSize(), 2)); img = new Image32(Vec2i.mul(img.getSize(), 2));
System.out.printf("Resized atlas to %dx%d\n", System.out.printf("Resized atlas to %dx%d\n",
img.getSize().getX(), img.getSize().getX(),
img.getSize().getY() img.getSize().getY()

View File

@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.backends.gl;
import com.danitheskunk.skunkworks.*; import com.danitheskunk.skunkworks.*;
import com.danitheskunk.skunkworks.gfx.IPipeline; import com.danitheskunk.skunkworks.gfx.IPipeline;
import com.danitheskunk.skunkworks.gfx.ITexture; import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -111,7 +111,7 @@ public class Window extends BaseWindow {
} }
@Override @Override
public ITexture loadTexture(Image image) { public ITexture loadTexture(Image32 image) {
return textureAtlas.addTexture(image); return textureAtlas.addTexture(image);
} }
@ -122,7 +122,7 @@ public class Window extends BaseWindow {
} }
@Override @Override
public List<ITexture> loadTextureArray(Image image, Vec2i tileSize) { public List<ITexture> loadTextureArray(Image32 image, Vec2i tileSize) {
var tileCount = Vec2i.div(image.getSize(), tileSize); var tileCount = Vec2i.div(image.getSize(), tileSize);
var tiles = new ArrayList<ITexture>(); var tiles = new ArrayList<ITexture>();

View File

@ -6,12 +6,12 @@ import org.lwjgl.stb.STBImage;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class Image { public class Image32 {
private final byte[] data; private final byte[] data;
private final Vec2i size; private final Vec2i size;
//constructors //constructors
public Image(ByteBuffer buffer) { //png or similar public Image32(ByteBuffer buffer) { //png or similar
//todo: resource system //todo: resource system
int[] x = {0}, y = {0}, n = {0}; int[] x = {0}, y = {0}, n = {0};
var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4); var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4);
@ -21,23 +21,23 @@ public class Image {
img.get(data); img.get(data);
} }
public Image(Vec2i size) { public Image32(Vec2i size) {
this.size = size; this.size = size;
data = new byte[size.getX() * size.getY() * 4]; data = new byte[size.getX() * size.getY() * 4];
} }
public Image(ByteBuffer buffer, Vec2i size) { public Image32(ByteBuffer buffer, Vec2i size) {
data = new byte[buffer.remaining()]; data = new byte[buffer.remaining()];
buffer.get(data); buffer.get(data);
this.size = size; this.size = size;
} }
public void drawImage(Image srcImage, Vec2i destPos) { public void drawImage(Image32 srcImage, Vec2i destPos) {
drawImage(srcImage, destPos, new Recti(Vec2i.ZERO, drawImage(srcImage, destPos, new Recti(Vec2i.ZERO,
srcImage.getSize())); srcImage.getSize()));
} }
public void drawImage(Image srcImage, Vec2i destPos, Recti srcRect) { public void drawImage(Image32 srcImage, Vec2i destPos, Recti srcRect) {
//todo: check bounds //todo: check bounds
//todo: write in faster way than pixel stuff //todo: write in faster way than pixel stuff
for(int y = 0; y < srcRect.getHeight(); ++y) { for(int y = 0; y < srcRect.getHeight(); ++y) {
@ -72,8 +72,8 @@ public class Image {
return size; return size;
} }
public Image getSubImage(Recti rect) { public Image32 getSubImage(Recti rect) {
Image img = new Image(rect.getSize()); Image32 img = new Image32(rect.getSize());
img.drawImage(this, Vec2i.ZERO, rect); img.drawImage(this, Vec2i.ZERO, rect);
return img; return img;
} }

View File

@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.gfx.font;
import com.danitheskunk.skunkworks.IWindow; import com.danitheskunk.skunkworks.IWindow;
import com.danitheskunk.skunkworks.Vec2i; import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.ITexture; import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import org.lwjgl.stb.STBTTFontinfo; import org.lwjgl.stb.STBTTFontinfo;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -72,11 +72,11 @@ public class FontTTF extends BaseFont {
buf.put(b); buf.put(b);
} }
buf.flip(); buf.flip();
tex = window.loadTexture(new Image(buf, tex = window.loadTexture(new Image32(buf,
new Vec2i(width[0], height[0]) new Vec2i(width[0], height[0])
)); ));
} else { } else {
tex = window.loadTexture(new Image(Vec2i.ZERO)); tex = window.loadTexture(new Image32(Vec2i.ZERO));
} }
stbtt_GetCodepointHMetrics(info, ch, advanceWidth, leftSideBearing); stbtt_GetCodepointHMetrics(info, ch, advanceWidth, leftSideBearing);
var c = new Char(tex, var c = new Char(tex,

View File

@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks.gfx.threedee;
import com.danitheskunk.skunkworks.IWindow; import com.danitheskunk.skunkworks.IWindow;
import com.danitheskunk.skunkworks.gfx.ITexture; import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image; import com.danitheskunk.skunkworks.gfx.Image32;
import org.lwjgl.assimp.*; import org.lwjgl.assimp.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -52,7 +52,7 @@ public class Model {
var texPB = ai.mTextures(); var texPB = ai.mTextures();
for(int i = 0; i < numTextures; ++i) { for(int i = 0; i < numTextures; ++i) {
var aiTex = AITexture.create(texPB.get(i)); var aiTex = AITexture.create(texPB.get(i));
var img = new Image(aiTex.pcDataCompressed()); var img = new Image32(aiTex.pcDataCompressed());
var tex = window.loadTexture(img); var tex = window.loadTexture(img);
textures[i] = tex; textures[i] = tex;
System.out.printf("tex %dx%d\n", img.getWidth(), img.getHeight()); System.out.printf("tex %dx%d\n", img.getWidth(), img.getHeight());