Use common engine type instead of explicitly GingerGL
parent
8acb688f19
commit
c4a84e48c0
|
@ -9,7 +9,7 @@ import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
|||
import com.github.halotroop.litecraft.util.RelativeDirection;
|
||||
import com.github.halotroop.litecraft.world.World;
|
||||
import com.github.hydos.ginger.engine.common.Constants;
|
||||
import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.common.api.*;
|
||||
import com.github.hydos.ginger.engine.common.api.game.*;
|
||||
import com.github.hydos.ginger.engine.common.cameras.*;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.*;
|
||||
|
@ -22,15 +22,18 @@ import com.github.hydos.ginger.engine.opengl.postprocessing.PostProcessing;
|
|||
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
||||
import com.github.hydos.ginger.engine.vulkan.api.GingerVK;
|
||||
|
||||
import tk.valoeghese.gateways.client.io.*;
|
||||
|
||||
public class Litecraft extends Game
|
||||
{
|
||||
// FIXME: search for ((GingerGL)engine) and properly implement both render APIs when Vulkan is complete.
|
||||
|
||||
private static Litecraft INSTANCE;
|
||||
private World world;
|
||||
private LitecraftSave save;
|
||||
private GingerGL engine;
|
||||
private GingerEngine engine;
|
||||
public int fps, ups, tps;
|
||||
public Vector4i dbgStats = new Vector4i();
|
||||
private long frameTimer;
|
||||
|
@ -97,12 +100,12 @@ public class Litecraft extends Game
|
|||
public void renderWorld(Game game)
|
||||
{
|
||||
GameData data = game.data;
|
||||
GingerUtils.preRenderScene(engine.getRegistry().masterRenderer);
|
||||
engine.contrastFbo.bindFBO();
|
||||
engine.getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane);
|
||||
engine.contrastFbo.unbindFBO();
|
||||
PostProcessing.doPostProcessing(engine.contrastFbo.colorTexture);
|
||||
if (data.handleGuis) engine.renderOverlays(game);
|
||||
GingerUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer);
|
||||
((GingerGL)engine).contrastFbo.bindFBO();
|
||||
((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane);
|
||||
((GingerGL)engine).contrastFbo.unbindFBO();
|
||||
PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture);
|
||||
if (data.handleGuis) ((GingerGL)engine).renderOverlays(game);
|
||||
}
|
||||
|
||||
public void update()
|
||||
|
@ -129,20 +132,34 @@ public class Litecraft extends Game
|
|||
MouseCallbackHandler.trackWindow(Window.getWindow());
|
||||
// set up ginger utilities
|
||||
GingerUtils.init();
|
||||
|
||||
switch (Window.renderAPI)
|
||||
{
|
||||
case OpenGL:
|
||||
{
|
||||
this.engine = new GingerGL();
|
||||
//Set the player model
|
||||
GLTexturedModel playerModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
|
||||
Light sun = new Light(new Vector3f(0, 105, 0), new Vector3f(0.9765625f, 0.98828125f, 0.05859375f), new Vector3f(0.002f, 0.002f, 0.002f));
|
||||
FontType font = new FontType(GLLoader.loadFontAtlas("candara.png"), "candara.fnt");
|
||||
this.engine = new GingerGL();
|
||||
this.player = new PlayerEntity(playerModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.camera = new FirstPersonCamera(player);
|
||||
this.player.setVisible(false);
|
||||
this.data = new GameData(this.player, this.camera, 20);
|
||||
this.data.handleGuis = false;
|
||||
this.engine.setup(new MasterRenderer(this.camera), INSTANCE);
|
||||
this.engine.setGlobalFont(font);
|
||||
this.data.lights.add(sun);
|
||||
((GingerGL)engine).setup(new MasterRenderer(this.camera), INSTANCE);
|
||||
((GingerGL)engine).setGlobalFont(font);
|
||||
this.data.entities.add(this.player);
|
||||
break;
|
||||
}
|
||||
case Vulkan:
|
||||
{
|
||||
this.engine = new GingerVK();
|
||||
// TODO: Setup Vulkan
|
||||
exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Light sun = new Light(new Vector3f(0, 105, 0), new Vector3f(0.9765625f, 0.98828125f, 0.05859375f), new Vector3f(0.002f, 0.002f, 0.002f));
|
||||
this.data.lights.add(sun);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +185,7 @@ public class Litecraft extends Game
|
|||
{
|
||||
tps += 1;
|
||||
// Open the title screen if it's not already open.
|
||||
if (GingerRegister.getInstance().currentScreen == null && world == null) engine.openScreen(new TitleScreen());
|
||||
if (GingerRegister.getInstance().currentScreen == null && world == null) ((GingerGL)engine).openScreen(new TitleScreen());
|
||||
|
||||
if (this.player instanceof PlayerEntity && camera != null)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.github.halotroop.litecraft;
|
|||
import org.lwjgl.Version;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class Starter
|
||||
public class StarterGL
|
||||
{
|
||||
// private static final boolean usingEclipse = false;
|
||||
public static void main(String[] args)
|
|
@ -12,6 +12,7 @@ import com.github.hydos.ginger.engine.common.math.Maths;
|
|||
import com.github.hydos.ginger.engine.opengl.render.Renderer;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
import com.github.hydos.ginger.engine.opengl.render.shaders.StaticShader;
|
||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
||||
|
||||
public class BlockRenderer extends Renderer implements WorldGenConstants
|
||||
{
|
||||
|
@ -24,7 +25,7 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
shader.start();
|
||||
shader.loadProjectionMatrix(projectionMatrix);
|
||||
shader.stop();
|
||||
this.atlasID = VoxelLoader.createBlockAtlas();
|
||||
this.atlasID = GLLoader.createBlockAtlas();
|
||||
}
|
||||
|
||||
private void prepBlockInstance(RenderObject entity)
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.github.halotroop.litecraft.screens;
|
|||
|
||||
import org.joml.Vector2f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.api.GingerEngine;
|
||||
import com.github.hydos.ginger.engine.common.font.GUIText;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
|
@ -10,11 +11,12 @@ import com.github.hydos.ginger.engine.opengl.api.GingerGL;
|
|||
public class ExitGameScreen extends Screen
|
||||
{
|
||||
private GUIText infoText;
|
||||
private GingerGL ginger3D = GingerGL.getInstance();
|
||||
// TODO: Add Vulkan text renderer
|
||||
private GingerEngine engine = GingerGL.getInstance();
|
||||
|
||||
public ExitGameScreen()
|
||||
{
|
||||
infoText = ginger3D.registerText("Saving and exiting...", 3, new Vector2f(Window.getWidth() / 2, Window.getHeight() / 2), 1f, true, "info");
|
||||
infoText = ((GingerGL)engine).registerText("Saving and exiting...", 3, new Vector2f(Window.getWidth() / 2, Window.getHeight() / 2), 1f, true, "info");
|
||||
infoText.setBorderWidth(0.5f);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.github.halotroop.litecraft.screens;
|
|||
import org.joml.*;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.common.api.*;
|
||||
import com.github.hydos.ginger.engine.common.font.GUIText;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
import com.github.hydos.ginger.engine.opengl.api.GingerGL;
|
||||
|
@ -12,14 +12,15 @@ public class IngameHUD extends Screen
|
|||
{
|
||||
private GUIText debugText;
|
||||
private GUIText positionText;
|
||||
private GingerGL ginger3D = GingerGL.getInstance();
|
||||
// TODO: Add Vulkan text renderer
|
||||
private GingerEngine engine = GingerGL.getInstance();
|
||||
private Litecraft litecraft = Litecraft.getInstance();
|
||||
|
||||
public IngameHUD()
|
||||
{
|
||||
debugText = ginger3D.registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
|
||||
debugText = ((GingerGL)engine).registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
|
||||
debugText.setBorderWidth(0.5f);
|
||||
positionText = ginger3D.registerText("Loading...", 2, new Vector2f(0, -0.1f), 1f, true, "posInfo");
|
||||
positionText = ((GingerGL)engine).registerText("Loading...", 2, new Vector2f(0, -0.1f), 1f, true, "posInfo");
|
||||
positionText.setBorderWidth(0.5f);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.joml.*;
|
|||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
import com.github.halotroop.litecraft.world.dimension.Dimensions;
|
||||
import com.github.hydos.ginger.engine.common.api.GingerEngine;
|
||||
import com.github.hydos.ginger.engine.common.elements.GuiTexture;
|
||||
import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton;
|
||||
import com.github.hydos.ginger.engine.common.font.GUIText;
|
||||
|
@ -20,16 +21,17 @@ import com.github.hydos.ginger.engine.opengl.api.GingerGL;
|
|||
public class TitleScreen extends Screen
|
||||
{
|
||||
private GUIText debugText;
|
||||
private GingerGL engine = GingerGL.getInstance();
|
||||
// TODO: Add Vulkan text renderer
|
||||
private GingerEngine engine = GingerGL.getInstance();
|
||||
private TextureButton playButton;
|
||||
private Litecraft litecraft = Litecraft.getInstance();
|
||||
|
||||
public TitleScreen()
|
||||
{
|
||||
elements = new ArrayList<GuiTexture>();
|
||||
playButton = engine.registerButton("/textures/guis/playbutton.png", new Vector2f(0, 0), new Vector2f(0.25f, 0.1f));
|
||||
playButton = ((GingerGL)engine).registerButton("/textures/guis/playbutton.png", new Vector2f(0, 0), new Vector2f(0.25f, 0.1f));
|
||||
playButton.show(Litecraft.getInstance().data.guis);
|
||||
debugText = engine.registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
|
||||
debugText = ((GingerGL)engine).registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
|
||||
debugText.setBorderWidth(0.5f);
|
||||
}
|
||||
|
||||
|
@ -51,11 +53,11 @@ public class TitleScreen extends Screen
|
|||
{
|
||||
Litecraft.getInstance().setSave(new LitecraftSave("SegregatedOrdinalData", false));
|
||||
Litecraft.getInstance().changeWorld(Litecraft.getInstance().getSave().getWorldOrCreate(Dimensions.OVERWORLD));
|
||||
engine.setGingerPlayer(Litecraft.getInstance().getWorld().playerEntity);
|
||||
((GingerGL)engine).setGingerPlayer(Litecraft.getInstance().getWorld().playerEntity);
|
||||
}
|
||||
if (Litecraft.getInstance().getWorld() != null)
|
||||
{
|
||||
engine.openScreen(new IngameHUD());
|
||||
((GingerGL)engine).openScreen(new IngameHUD());
|
||||
this.cleanup();
|
||||
}
|
||||
//TODO: add world creation gui so it takes u to world creation place
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.function.LongConsumer;
|
|||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.render.BlockRenderer;
|
||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
import com.github.halotroop.litecraft.types.block.*;
|
||||
|
@ -14,8 +15,6 @@ import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
|||
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
import com.github.halotroop.litecraft.world.gen.modifier.WorldModifier;
|
||||
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.*;
|
||||
|
||||
|
@ -85,8 +84,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
public PlayerEntity spawnPlayer(float x, float y, float z)
|
||||
{
|
||||
GLTexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/soil/dirt.png");
|
||||
this.playerEntity = new PlayerEntity(dirtModel, new Vector3f(x, y, z), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.playerEntity = (PlayerEntity) Litecraft.getInstance().player;
|
||||
this.playerEntity.setVisible(false);
|
||||
|
||||
// Generate world around player
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
package com.github.halotroop.litecraft.world.block;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.BlockInstance;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.math.Maths;
|
||||
import com.github.hydos.ginger.engine.opengl.render.Renderer;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
import com.github.hydos.ginger.engine.opengl.render.shaders.StaticShader;
|
||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
||||
|
||||
public class BlockRenderer extends Renderer implements WorldGenConstants
|
||||
{
|
||||
public StaticShader shader;
|
||||
public int atlasID;
|
||||
|
||||
public BlockRenderer(StaticShader shader, Matrix4f projectionMatrix)
|
||||
{
|
||||
this.shader = shader;
|
||||
shader.start();
|
||||
shader.loadProjectionMatrix(projectionMatrix);
|
||||
shader.stop();
|
||||
this.atlasID = GLLoader.createBlockAtlas();
|
||||
}
|
||||
|
||||
private void prepBlockInstance(RenderObject entity)
|
||||
{
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(),
|
||||
entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
shader.loadTransformationMatrix(transformationMatrix);
|
||||
}
|
||||
|
||||
public void prepareModel(GLTexturedModel model)
|
||||
{
|
||||
GL30.glBindVertexArray(model.getRawModel().getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL20.glEnableVertexAttribArray(1);
|
||||
GL20.glEnableVertexAttribArray(2);
|
||||
}
|
||||
|
||||
public void unbindModel()
|
||||
{
|
||||
GL20.glDisableVertexAttribArray(0);
|
||||
GL20.glDisableVertexAttribArray(1);
|
||||
GL20.glDisableVertexAttribArray(2);
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void enableWireframe()
|
||||
{ if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); }
|
||||
|
||||
public void disableWireframe()
|
||||
{ if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); }
|
||||
|
||||
public void prepareRender()
|
||||
{
|
||||
// TODO: combine VBOS
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
shader.loadFakeLightingVariable(true);
|
||||
shader.loadShine(1, 1);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, atlasID);
|
||||
enableWireframe();
|
||||
}
|
||||
|
||||
public void render(BlockInstance[] renderList)
|
||||
{
|
||||
prepareRender();
|
||||
|
||||
for (BlockInstance entity : renderList) {
|
||||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
GLTexturedModel blockModel = entity.getModel();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockModel.getTexture().getTextureID());
|
||||
prepBlockInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
}
|
||||
// disableWireframe();
|
||||
// shader.stop();
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
|||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
||||
import com.github.hydos.ginger.engine.vulkan.*;
|
||||
import com.github.hydos.ginger.engine.vulkan.api.VKGinger;
|
||||
import com.github.hydos.ginger.engine.vulkan.api.GingerVK;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.*;
|
||||
import com.github.hydos.ginger.engine.vulkan.registers.VKRegister;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.RenderUtils;
|
||||
|
@ -232,7 +232,7 @@ public class VulkanStarter
|
|||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
Window.create(1200, 600, "Litecraft Vulkan", 60, RenderAPI.Vulkan);
|
||||
new VKGinger();
|
||||
new GingerVK();
|
||||
VKRegister.exampleVKModel = new VKModelData();
|
||||
/* Look for instance extensions */
|
||||
PointerBuffer requiredExtensions = GLFWVulkan.glfwGetRequiredInstanceExtensions();
|
||||
|
@ -401,6 +401,6 @@ public class VulkanStarter
|
|||
VK12.vkDestroySemaphore(VKRegister.device, pImageAcquiredSemaphore.get(0), null);
|
||||
VK12.vkDestroySemaphore(VKRegister.device, pRenderCompleteSemaphore.get(0), null);
|
||||
}
|
||||
VKGinger.getInstance().end(pWaitDstStageMask, pImageAcquiredSemaphore, pRenderCompleteSemaphore, pSwapchains, pCommandBuffers, semaphoreCreateInfo, submitInfo, presentInfo, vulkanInstance, debugCallbackHandle, framebufferSizeCallback, keyCallback);
|
||||
((GingerVK)GingerVK.getInstance()).end(pWaitDstStageMask, pImageAcquiredSemaphore, pRenderCompleteSemaphore, pSwapchains, pCommandBuffers, semaphoreCreateInfo, submitInfo, presentInfo, vulkanInstance, debugCallbackHandle, framebufferSizeCallback, keyCallback);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.github.hydos.ginger.engine.common.api;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.api.game.Game;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
import com.github.hydos.ginger.engine.common.util.Timer;
|
||||
import com.github.hydos.ginger.engine.common.util.Timer.TickListener;
|
||||
import com.github.hydos.ginger.engine.opengl.api.GingerUtils;
|
||||
|
||||
public abstract class GingerEngine
|
||||
{
|
||||
protected static GingerEngine INSTANCE;
|
||||
protected GingerRegister registry;
|
||||
|
||||
public static GingerEngine getInstance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
protected Timer timer;
|
||||
protected TickListener gameTickListener = new TickListener()
|
||||
{
|
||||
@Override
|
||||
public void onTick(float deltaTime)
|
||||
{
|
||||
if (GingerRegister.getInstance().game != null) GingerRegister.getInstance().game.tick();
|
||||
if (GingerRegister.getInstance().currentScreen != null) GingerRegister.getInstance().currentScreen.tick();
|
||||
};
|
||||
};
|
||||
|
||||
public void startGameLoop()
|
||||
{
|
||||
while (!Window.closed())
|
||||
{
|
||||
update(); // Run this regardless, (so as fast as possible)
|
||||
timer.tick(); // Run this only [ticklimit] times per second (This invokes gameTickListener.onTick!)
|
||||
if (Window.shouldRender()) GingerRegister.getInstance().game.render(); // Run this only [framelimit] times per second
|
||||
}
|
||||
GingerRegister.getInstance().game.exit();
|
||||
}
|
||||
|
||||
// Things that should be run as often as possible, without limits
|
||||
public void update()
|
||||
{
|
||||
GingerUtils.update();
|
||||
Window.update();
|
||||
}
|
||||
|
||||
public abstract void cleanup();
|
||||
|
||||
public abstract void openScreen(Screen screen);
|
||||
|
||||
public abstract void renderOverlays(Game game);
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.github.hydos.ginger.engine.common.font;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.opengl.api.GingerGL;
|
||||
import com.github.hydos.ginger.engine.opengl.render.renderers.FontRenderer;
|
||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
||||
|
@ -44,12 +46,16 @@ public class TextMaster
|
|||
{ renderer.render(texts); }
|
||||
|
||||
public static void render(GUIText buildText)
|
||||
{
|
||||
// TODO: Add Vulkan font renderer
|
||||
if (Window.renderAPI == RenderAPI.OpenGL)
|
||||
{
|
||||
Map<FontType, List<GUIText>> oldTexts = texts;
|
||||
List<GUIText> oldFontText = texts.get(GingerGL.getInstance().globalFont);
|
||||
List<GUIText> oldFontText = texts.get(((GingerGL)GingerGL.getInstance()).globalFont);
|
||||
oldFontText.add(buildText);
|
||||
texts.clear();
|
||||
texts.put(GingerGL.getInstance().globalFont, oldFontText);
|
||||
texts.put(((GingerGL)GingerGL.getInstance()).globalFont, oldFontText);
|
||||
texts = oldTexts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ public class Window
|
|||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
||||
}else if (renderAPI == RenderAPI.Vulkan)
|
||||
}
|
||||
else if (renderAPI == RenderAPI.Vulkan)
|
||||
{
|
||||
GLFW.glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
if (!GLFWVulkan.glfwVulkanSupported()) {
|
||||
|
@ -210,7 +211,7 @@ public class Window
|
|||
if(renderAPI == RenderAPI.OpenGL) {
|
||||
if ((oldWindowHeight != Window.getHeight() || oldWindowWidth != Window.getWidth()) && Window.getHeight() > 10 && Window.getWidth() > 10)
|
||||
{
|
||||
GingerGL.getInstance().contrastFbo.resizeFBOs();
|
||||
((GingerGL)GingerGL.getInstance()).contrastFbo.resizeFBOs();
|
||||
oldWindowWidth = Window.getWidth();
|
||||
oldWindowHeight = Window.getHeight();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.github.hydos.ginger.engine.opengl.api;
|
|||
|
||||
import org.joml.Vector2f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.common.api.*;
|
||||
import com.github.hydos.ginger.engine.common.api.game.Game;
|
||||
import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
|
@ -11,30 +11,16 @@ import com.github.hydos.ginger.engine.common.io.Window;
|
|||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
import com.github.hydos.ginger.engine.common.tools.MousePicker;
|
||||
import com.github.hydos.ginger.engine.common.util.Timer;
|
||||
import com.github.hydos.ginger.engine.common.util.Timer.TickListener;
|
||||
import com.github.hydos.ginger.engine.opengl.postprocessing.*;
|
||||
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
||||
|
||||
public class GingerGL
|
||||
public class GingerGL extends GingerEngine
|
||||
{
|
||||
private static GingerGL INSTANCE;
|
||||
private GingerRegister registry;
|
||||
public MousePicker picker;
|
||||
public FontType globalFont;
|
||||
public Fbo contrastFbo;
|
||||
|
||||
private Timer timer;
|
||||
TickListener gameTickListener = new TickListener()
|
||||
{
|
||||
@Override
|
||||
public void onTick(float deltaTime)
|
||||
{
|
||||
if (getRegistry().game != null) getRegistry().game.tick();
|
||||
if (getRegistry().currentScreen != null) getRegistry().currentScreen.tick();
|
||||
};
|
||||
};
|
||||
|
||||
public void cleanup()
|
||||
{
|
||||
Window.stop();
|
||||
|
@ -97,29 +83,14 @@ public class GingerGL
|
|||
PostProcessing.init();
|
||||
}
|
||||
|
||||
public void startGameLoop()
|
||||
{
|
||||
while (!Window.closed())
|
||||
{
|
||||
update(); // Run this regardless, (so as fast as possible)
|
||||
timer.tick(); // Run this only [ticklimit] times per second (This invokes gameTickListener.onTick!)
|
||||
if (Window.shouldRender()) getRegistry().game.render(); // Run this only [framelimit] times per second
|
||||
}
|
||||
getRegistry().game.exit();
|
||||
}
|
||||
|
||||
// Things that should be run as often as possible, without limits
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
getRegistry().game.update();
|
||||
picker.update();
|
||||
GingerUtils.update();
|
||||
Window.update();
|
||||
super.update();
|
||||
}
|
||||
|
||||
public static GingerGL getInstance()
|
||||
{ return INSTANCE; }
|
||||
|
||||
public GingerRegister getRegistry()
|
||||
{
|
||||
return registry;
|
||||
|
|
|
@ -14,20 +14,18 @@ import org.lwjgl.vulkan.VkPresentInfoKHR;
|
|||
import org.lwjgl.vulkan.VkSemaphoreCreateInfo;
|
||||
import org.lwjgl.vulkan.VkSubmitInfo;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.api.GingerEngine;
|
||||
import com.github.hydos.ginger.engine.common.api.game.Game;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
|
||||
public class VKGinger {
|
||||
|
||||
private static VKGinger INSTANCE;
|
||||
|
||||
public VKGinger()
|
||||
public class GingerVK extends GingerEngine
|
||||
{
|
||||
public GingerVK()
|
||||
{
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
public static VKGinger getInstance()
|
||||
{return INSTANCE; }
|
||||
|
||||
public void end(IntBuffer pWaitDstStageMask, LongBuffer pImageAcquiredSemaphore, LongBuffer pRenderCompleteSemaphore, LongBuffer pSwapchains, PointerBuffer pCommandBuffers, VkSemaphoreCreateInfo semaphoreCreateInfo, VkSubmitInfo submitInfo, VkPresentInfoKHR presentInfo, VkInstance vulkanInstance, long debugCallbackHandle, GLFWFramebufferSizeCallback framebufferSizeCallback, GLFWKeyCallback keyCallback)
|
||||
{
|
||||
MemoryUtil.memFree(pWaitDstStageMask);
|
||||
|
@ -45,4 +43,22 @@ public class VKGinger {
|
|||
GLFW.glfwTerminate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openScreen(Screen screen)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderOverlays(Game game)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue