r.i.p Litecraft
parent
9a047c9750
commit
d6795052cc
|
@ -6,7 +6,7 @@ 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.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.math.Maths;
|
||||
import com.github.hydos.ginger.engine.common.render.Renderer;
|
||||
|
@ -28,7 +28,7 @@ public class GLBlockRenderer extends Renderer implements WorldGenConstants
|
|||
this.atlasID = GLLoader.createBlockAtlas();
|
||||
}
|
||||
|
||||
private void prepBlockInstance(RenderObject entity)
|
||||
private void prepBlockInstance(GLRenderObject entity)
|
||||
{
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(),
|
||||
entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.github.halotroop.litecraft.types.block;
|
|||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.halotroop.litecraft.world.Chunk;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
|
||||
public class BlockInstance extends RenderObject
|
||||
public class BlockInstance extends GLRenderObject
|
||||
{
|
||||
public BlockInstance(Block block, Vector3f position)
|
||||
{ super(block.model, position, 0, 0, 0, new Vector3f(1f, 1f, 1f)); }
|
||||
|
|
|
@ -2,10 +2,10 @@ package com.github.halotroop.litecraft.types.entity;
|
|||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
|
||||
public abstract class Entity extends RenderObject
|
||||
public abstract class Entity extends GLRenderObject
|
||||
{
|
||||
public Entity(GLTexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
{ super(model, position, rotX, rotY, rotZ, scale); }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.github.hydos.ginger;
|
||||
|
||||
import com.github.hydos.ginger.engine.vulkan.VKVariables;
|
||||
import com.github.hydos.ginger.engine.vulkan.elements.VKRenderObject;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.*;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.renderers.EntityRenderer;
|
||||
|
||||
|
@ -27,7 +28,8 @@ public class GingerVK
|
|||
|
||||
public void cleanup()
|
||||
{
|
||||
for(VKBufferMesh bufferMesh: entityRenderer.entities) {
|
||||
for(VKRenderObject entity: entityRenderer.entities) {
|
||||
VKBufferMesh bufferMesh = entity.getModel();
|
||||
bufferMesh.cleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,13 @@ import java.nio.IntBuffer;
|
|||
import java.util.Set;
|
||||
import java.util.stream.*;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.*;
|
||||
import org.lwjgl.vulkan.*;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.vulkan.*;
|
||||
import com.github.hydos.ginger.engine.vulkan.elements.VKRenderObject;
|
||||
import com.github.hydos.ginger.engine.vulkan.io.VKWindow;
|
||||
import com.github.hydos.ginger.engine.vulkan.managers.VKTextureManager;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.VKModelLoader;
|
||||
|
@ -86,7 +87,8 @@ public class VulkanExample {
|
|||
File modelFile = new File(ClassLoader.getSystemClassLoader().getResource("models/chalet.obj").getFile());
|
||||
|
||||
VKMesh model = VKModelLoader.loadModel(modelFile, aiProcess_FlipUVs | aiProcess_DropNormals);
|
||||
GingerVK.getInstance().entityRenderer.processEntity(model);
|
||||
VKRenderObject object = new VKRenderObject(model, new Vector3f(), 1, 1, 1, new Vector3f());
|
||||
GingerVK.getInstance().entityRenderer.processEntity(object);
|
||||
}
|
||||
|
||||
private void initWindow() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.github.hydos.ginger.engine.common.api.game;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.cameras.Camera;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
|
||||
public abstract class Game
|
||||
{
|
||||
public GameData data;
|
||||
public RenderObject player; // FIXME: @hYdos you know these probably don't need to be here, but the game stops working when they're not.
|
||||
public GLRenderObject player; // FIXME: @hYdos you know these probably don't need to be here, but the game stops working when they're not.
|
||||
public Camera camera;
|
||||
|
||||
public Game()
|
||||
|
|
|
@ -15,22 +15,22 @@ import com.github.hydos.ginger.engine.common.elements.objects.*;
|
|||
public class GameData
|
||||
{
|
||||
public List<GLGuiTexture> guis;
|
||||
public List<RenderObject> entities;
|
||||
public List<GLRenderObject> entities;
|
||||
public List<Light> lights;
|
||||
public List<RenderObject> normalMapEntities;
|
||||
public RenderObject playerObject;
|
||||
public List<GLRenderObject> normalMapEntities;
|
||||
public GLRenderObject playerObject;
|
||||
public Camera camera;
|
||||
public Vector4f clippingPlane;
|
||||
public boolean handleGuis = true;
|
||||
public int tickSpeed = 20;
|
||||
|
||||
public GameData(RenderObject playerEntity, Camera camera, int tickSpeed)
|
||||
public GameData(GLRenderObject playerEntity, Camera camera, int tickSpeed)
|
||||
{
|
||||
clippingPlane = new Vector4f(0, -1, 0, 100000);
|
||||
guis = new ArrayList<GLGuiTexture>();
|
||||
entities = new ArrayList<RenderObject>();
|
||||
entities = new ArrayList<GLRenderObject>();
|
||||
lights = new ArrayList<Light>();
|
||||
normalMapEntities = new ArrayList<RenderObject>();
|
||||
normalMapEntities = new ArrayList<GLRenderObject>();
|
||||
this.playerObject = playerEntity;
|
||||
this.camera = camera;
|
||||
this.tickSpeed = tickSpeed;
|
||||
|
|
|
@ -2,11 +2,11 @@ package com.github.hydos.ginger.engine.common.cameras;
|
|||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
|
||||
public abstract class Camera
|
||||
{
|
||||
public RenderObject player;
|
||||
public GLRenderObject player;
|
||||
private float pitch, yaw, roll;
|
||||
private Vector3f position = new Vector3f(0, 0, 0);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.github.hydos.ginger.engine.common.cameras;
|
|||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
|
||||
public class FirstPersonCamera extends Camera
|
||||
|
@ -11,7 +11,7 @@ public class FirstPersonCamera extends Camera
|
|||
private float pitch, yaw;
|
||||
private float roll;
|
||||
|
||||
public FirstPersonCamera(RenderObject playerEntity)
|
||||
public FirstPersonCamera(GLRenderObject playerEntity)
|
||||
{
|
||||
this.player = playerEntity;
|
||||
playerEntity.setVisible(false);
|
||||
|
|
|
@ -2,12 +2,12 @@ package com.github.hydos.ginger.engine.common.cameras;
|
|||
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
|
||||
public class ThirdPersonCamera extends Camera
|
||||
{
|
||||
public ThirdPersonCamera(RenderObject playerEntity)
|
||||
public ThirdPersonCamera(GLRenderObject playerEntity)
|
||||
{
|
||||
this.player = playerEntity;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
package com.github.hydos.ginger.engine.common.elements.objects;
|
||||
package com.github.hydos.ginger.engine.common.elements;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class RenderObject
|
||||
public abstract class RenderObject
|
||||
{
|
||||
private TexturedModel model;
|
||||
|
||||
public Vector3f position;
|
||||
private float rotX = 0, rotY = 0, rotZ = 0;
|
||||
private Vector3f scale;
|
||||
private boolean visible = true;
|
||||
|
||||
public RenderObject(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
{
|
||||
this.model = model;
|
||||
this.position = position;
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public float rotX = 0, rotY = 0, rotZ = 0;
|
||||
public Vector3f scale;
|
||||
public boolean visible = true;
|
||||
|
||||
public void x(float x)
|
||||
{ this.position.x = x; }
|
||||
|
||||
|
@ -28,9 +18,7 @@ public class RenderObject
|
|||
|
||||
public void z(float z)
|
||||
{ this.position.z = z; }
|
||||
|
||||
public TexturedModel getModel()
|
||||
{ return model; }
|
||||
|
||||
|
||||
public Vector3f getPosition()
|
||||
{ return position; }
|
||||
|
@ -61,9 +49,6 @@ public class RenderObject
|
|||
this.rotZ += dz;
|
||||
}
|
||||
|
||||
public void setModel(TexturedModel model)
|
||||
{ this.model = model; }
|
||||
|
||||
public void setPosition(Vector3f position)
|
||||
{ this.position = position; }
|
||||
|
||||
|
@ -88,4 +73,5 @@ public class RenderObject
|
|||
{
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.github.hydos.ginger.engine.common.elements.objects;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.RenderObject;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
|
||||
public class GLRenderObject extends RenderObject
|
||||
{
|
||||
private TexturedModel model;
|
||||
|
||||
public GLRenderObject(GLTexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
{
|
||||
this.model = model;
|
||||
this.position = position;
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public TexturedModel getModel()
|
||||
{ return model; }
|
||||
|
||||
public void setModel(TexturedModel model)
|
||||
{ this.model = model; }
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
|||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||
|
||||
public class Player extends RenderObject implements WorldGenConstants
|
||||
public class Player extends GLRenderObject implements WorldGenConstants
|
||||
{
|
||||
private boolean isInAir = false;
|
||||
private double upwardsSpeed;
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.joml.Vector2f;
|
|||
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;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.font.*;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
|
@ -36,7 +36,7 @@ public class GingerGL extends GingerEngine
|
|||
getRegistry().currentScreen = screen;
|
||||
}
|
||||
|
||||
public void setGingerPlayer(RenderObject player)
|
||||
public void setGingerPlayer(GLRenderObject player)
|
||||
{
|
||||
registry.game.data.entities.remove(registry.game.player); // remove the old player
|
||||
registry.game.data.playerObject = player; // set all the player variables
|
||||
|
|
|
@ -41,8 +41,8 @@ public class GLRenderManager
|
|||
private GLNormalMappingRenderer normalRenderer;
|
||||
private Matrix4f projectionMatrix;
|
||||
private ShadowMapMasterRenderer shadowMapRenderer;
|
||||
private Map<GLTexturedModel, List<RenderObject>> entities = new HashMap<GLTexturedModel, List<RenderObject>>();
|
||||
private Map<GLTexturedModel, List<RenderObject>> normalMapEntities = new HashMap<GLTexturedModel, List<RenderObject>>();
|
||||
private Map<GLTexturedModel, List<GLRenderObject>> entities = new HashMap<GLTexturedModel, List<GLRenderObject>>();
|
||||
private Map<GLTexturedModel, List<GLRenderObject>> normalMapEntities = new HashMap<GLTexturedModel, List<GLRenderObject>>();
|
||||
|
||||
public GLRenderManager(Camera camera)
|
||||
{
|
||||
|
@ -93,41 +93,41 @@ public class GLRenderManager
|
|||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
}
|
||||
|
||||
private void processEntity(RenderObject entity)
|
||||
private void processEntity(GLRenderObject entity)
|
||||
{
|
||||
GLTexturedModel entityModel = (GLTexturedModel) entity.getModel();
|
||||
List<RenderObject> batch = entities.get(entityModel);
|
||||
List<GLRenderObject> batch = entities.get(entityModel);
|
||||
if (batch != null)
|
||||
{
|
||||
batch.add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RenderObject> newBatch = new ArrayList<RenderObject>();
|
||||
List<GLRenderObject> newBatch = new ArrayList<GLRenderObject>();
|
||||
newBatch.add(entity);
|
||||
entities.put(entityModel, newBatch);
|
||||
}
|
||||
}
|
||||
|
||||
private void processEntityWithNormal(RenderObject entity)
|
||||
private void processEntityWithNormal(GLRenderObject entity)
|
||||
{
|
||||
GLTexturedModel entityModel = (GLTexturedModel) entity.getModel();
|
||||
List<RenderObject> batch = normalMapEntities.get(entityModel);
|
||||
List<GLRenderObject> batch = normalMapEntities.get(entityModel);
|
||||
if (batch != null)
|
||||
{
|
||||
batch.add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RenderObject> newBatch = new ArrayList<RenderObject>();
|
||||
List<GLRenderObject> newBatch = new ArrayList<GLRenderObject>();
|
||||
newBatch.add(entity);
|
||||
normalMapEntities.put(entityModel, newBatch);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderEntities(List<RenderObject> entities, Camera camera, List<Light> lights)
|
||||
private void renderEntities(List<GLRenderObject> entities, Camera camera, List<Light> lights)
|
||||
{
|
||||
for (RenderObject entity : entities)
|
||||
for (GLRenderObject entity : entities)
|
||||
{ processEntity(entity); }
|
||||
entityRenderer.prepare();
|
||||
entityShader.start();
|
||||
|
@ -149,14 +149,14 @@ public class GLRenderManager
|
|||
public void renderGuis(List<GLGuiTexture> guis)
|
||||
{ guiRenderer.render(guis); }
|
||||
|
||||
private void renderNormalEntities(List<RenderObject> normalEntities, List<Light> lights, Camera camera, Vector4f clipPlane)
|
||||
private void renderNormalEntities(List<GLRenderObject> normalEntities, List<Light> lights, Camera camera, Vector4f clipPlane)
|
||||
{
|
||||
for (RenderObject entity : normalEntities)
|
||||
for (GLRenderObject entity : normalEntities)
|
||||
{ processEntityWithNormal(entity); }
|
||||
normalRenderer.render(normalMapEntities, clipPlane, lights, camera);
|
||||
}
|
||||
|
||||
public void renderScene(List<RenderObject> entities, List<RenderObject> normalEntities, List<Light> lights, Camera camera, Vector4f clipPlane)
|
||||
public void renderScene(List<GLRenderObject> entities, List<GLRenderObject> normalEntities, List<Light> lights, Camera camera, Vector4f clipPlane)
|
||||
{
|
||||
prepare();
|
||||
renderEntities(entities, camera, lights);
|
||||
|
@ -165,9 +165,9 @@ public class GLRenderManager
|
|||
// skyboxRenderer.render(camera);
|
||||
}
|
||||
|
||||
public void renderShadowMap(List<RenderObject> entityList, Light sun)
|
||||
public void renderShadowMap(List<GLRenderObject> entityList, Light sun)
|
||||
{
|
||||
for (RenderObject entity : entityList)
|
||||
for (GLRenderObject entity : entityList)
|
||||
{ processEntity(entity); }
|
||||
shadowMapRenderer.render(entities, sun);
|
||||
entities.clear();
|
||||
|
|
|
@ -41,7 +41,7 @@ public class GLNormalMappingRenderer extends Renderer
|
|||
shader.loadViewMatrix(viewMatrix);
|
||||
}
|
||||
|
||||
private void prepareInstance(RenderObject entity)
|
||||
private void prepareInstance(GLRenderObject entity)
|
||||
{
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(),
|
||||
entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
|
@ -67,15 +67,15 @@ public class GLNormalMappingRenderer extends Renderer
|
|||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getNormalMap());
|
||||
}
|
||||
|
||||
public void render(Map<GLTexturedModel, List<RenderObject>> entities, Vector4f clipPlane, List<Light> lights, Camera camera)
|
||||
public void render(Map<GLTexturedModel, List<GLRenderObject>> entities, Vector4f clipPlane, List<Light> lights, Camera camera)
|
||||
{
|
||||
shader.start();
|
||||
prepare(clipPlane, lights, camera);
|
||||
for (GLTexturedModel model : entities.keySet())
|
||||
{
|
||||
prepareTexturedModel(model);
|
||||
List<RenderObject> batch = entities.get(model);
|
||||
for (RenderObject entity : batch)
|
||||
List<GLRenderObject> batch = entities.get(model);
|
||||
for (GLRenderObject entity : batch)
|
||||
{
|
||||
prepareInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.lwjgl.opengl.*;
|
|||
|
||||
import com.github.halotroop.litecraft.types.block.BlockInstance;
|
||||
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.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.math.Maths;
|
||||
import com.github.hydos.ginger.engine.common.render.Renderer;
|
||||
|
@ -31,7 +31,7 @@ public class GLObjectRenderer extends Renderer
|
|||
public void prepare()
|
||||
{ GL11.glEnable(GL11.GL_DEPTH_TEST); }
|
||||
|
||||
private void prepareInstance(RenderObject entity)
|
||||
private void prepareInstance(GLRenderObject entity)
|
||||
{
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
shader.loadTransformationMatrix(transformationMatrix);
|
||||
|
@ -59,13 +59,13 @@ public class GLObjectRenderer extends Renderer
|
|||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
|
||||
}
|
||||
|
||||
public void render(Map<GLTexturedModel, List<RenderObject>> entities)
|
||||
public void render(Map<GLTexturedModel, List<GLRenderObject>> entities)
|
||||
{
|
||||
for (GLTexturedModel model : entities.keySet())
|
||||
{
|
||||
prepareTexturedModel(model);
|
||||
List<RenderObject> batch = entities.get(model);
|
||||
for (RenderObject entity : batch)
|
||||
List<GLRenderObject> batch = entities.get(model);
|
||||
for (GLRenderObject entity : batch)
|
||||
{
|
||||
if (entity.isVisible())
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ public class GLObjectRenderer extends Renderer
|
|||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
for (RenderObject entity : renderList)
|
||||
for (GLRenderObject entity : renderList)
|
||||
{
|
||||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.*;
|
|||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.GLRenderObject;
|
||||
import com.github.hydos.ginger.engine.common.math.Maths;
|
||||
import com.github.hydos.ginger.engine.opengl.render.GLRenderManager;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.*;
|
||||
|
@ -47,7 +47,7 @@ public class ShadowMapEntityRenderer
|
|||
*
|
||||
* @param entity
|
||||
* - the entity to be prepared for rendering. */
|
||||
private void prepareInstance(RenderObject entity)
|
||||
private void prepareInstance(GLRenderObject entity)
|
||||
{
|
||||
Matrix4f modelMatrix = Maths.createTransformationMatrix(entity.getPosition(),
|
||||
entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
|
@ -60,7 +60,7 @@ public class ShadowMapEntityRenderer
|
|||
*
|
||||
* @param entities
|
||||
* - the entities to be rendered to the shadow map. */
|
||||
protected void render(Map<GLTexturedModel, List<RenderObject>> entities)
|
||||
protected void render(Map<GLTexturedModel, List<GLRenderObject>> entities)
|
||||
{
|
||||
for (GLTexturedModel model : entities.keySet())
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ public class ShadowMapEntityRenderer
|
|||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
|
||||
if (model.getTexture().isTransparent())
|
||||
{ GLRenderManager.disableCulling(); }
|
||||
for (RenderObject entity : entities.get(model))
|
||||
for (GLRenderObject entity : entities.get(model))
|
||||
{
|
||||
prepareInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, rawModel.getVertexCount(),
|
||||
|
|
|
@ -134,7 +134,7 @@ public class ShadowMapMasterRenderer
|
|||
* entities in that list use.
|
||||
* @param sun
|
||||
* - the light acting as the sun in the scene. */
|
||||
public void render(Map<GLTexturedModel, List<RenderObject>> entities, Light sun)
|
||||
public void render(Map<GLTexturedModel, List<GLRenderObject>> entities, Light sun)
|
||||
{
|
||||
shadowBox.update();
|
||||
Vector3f sunPosition = sun.getPosition();
|
||||
|
|
|
@ -82,5 +82,6 @@ public class VKVariables
|
|||
|
||||
public static boolean framebufferResize;
|
||||
public static VKRenderManager renderManager;
|
||||
public static int currentImageIndex;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.github.hydos.ginger.engine.vulkan.elements;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.RenderObject;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.VKModelLoader.VKMesh;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.VKBufferMesh;
|
||||
|
||||
public class VKRenderObject extends RenderObject
|
||||
{
|
||||
|
||||
private VKBufferMesh model = null;//until i add VKTextured models
|
||||
private VKMesh rawModel;//until i add VKTextured models
|
||||
|
||||
public VKRenderObject(VKMesh rawModel, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
{
|
||||
this.rawModel = rawModel;
|
||||
this.position = position;
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public VKBufferMesh getModel()
|
||||
{ return model; }
|
||||
|
||||
public void setModel(VKBufferMesh model)
|
||||
{ this.model = model; }
|
||||
|
||||
public VKMesh getRawModel()
|
||||
{
|
||||
return rawModel;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ import org.lwjgl.vulkan.*;
|
|||
import com.github.hydos.ginger.VulkanExample;
|
||||
import com.github.hydos.ginger.engine.vulkan.VKVariables;
|
||||
import com.github.hydos.ginger.engine.vulkan.swapchain.VKSwapchainManager;
|
||||
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
|
||||
|
||||
/**
|
||||
* Wraps the needed sync objects for an in flight frame
|
||||
|
@ -75,8 +74,7 @@ public class Frame {
|
|||
}
|
||||
|
||||
final int imageIndex = pImageIndex.get(0);
|
||||
|
||||
VKUtils.updateUniformBuffer(imageIndex);
|
||||
VKVariables.currentImageIndex = imageIndex;
|
||||
|
||||
if(VKVariables.imagesInFlight.containsKey(imageIndex)) {
|
||||
vkWaitForFences(VKVariables.device, VKVariables.imagesInFlight.get(imageIndex).fence(), true, VulkanExample.UINT64_MAX);
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.lwjgl.vulkan.VkCommandBuffer;
|
|||
|
||||
import com.github.hydos.ginger.engine.common.render.Renderer;
|
||||
import com.github.hydos.ginger.engine.vulkan.VKVariables;
|
||||
import com.github.hydos.ginger.engine.vulkan.elements.VKRenderObject;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.VKVertex;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.VKModelLoader.VKMesh;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.VKBufferMesh;
|
||||
|
@ -18,15 +19,15 @@ import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
|
|||
|
||||
public class EntityRenderer extends Renderer
|
||||
{
|
||||
|
||||
public List<VKBufferMesh> entities;//TODO: batch rendering
|
||||
public List<VKRenderObject> entities;//TODO: batch rendering
|
||||
|
||||
public EntityRenderer() {
|
||||
priority = 1;
|
||||
entities = new ArrayList<VKBufferMesh>();
|
||||
entities = new ArrayList<VKRenderObject>();
|
||||
}
|
||||
|
||||
public void processEntity(VKMesh mesh) {
|
||||
public void processEntity(VKRenderObject entity) {
|
||||
VKMesh mesh = entity.getRawModel();
|
||||
VKBufferMesh processedMesh = new VKBufferMesh();
|
||||
processedMesh.vkMesh = mesh;
|
||||
int vertexCount = mesh.positions.size();
|
||||
|
@ -50,20 +51,24 @@ public class EntityRenderer extends Renderer
|
|||
|
||||
processedMesh = VKUtils.createVertexBuffer(processedMesh);
|
||||
processedMesh = VKUtils.createIndexBuffer(processedMesh);
|
||||
entities.add(processedMesh);
|
||||
entity.setModel(processedMesh);
|
||||
entities.add(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void VKRender(MemoryStack stack, VkCommandBuffer commandBuffer, int index)
|
||||
{
|
||||
|
||||
for(VKBufferMesh entity : entities)
|
||||
for(VKRenderObject entity : entities)
|
||||
{
|
||||
LongBuffer vertexBuffers = stack.longs(entity.vertexBuffer);
|
||||
VKBufferMesh mesh = entity.getModel();
|
||||
VKUtils.updateUniformBuffer(VKVariables.currentImageIndex, entity);//TODO: move this to entitiy renderer and update before every entity is drawn
|
||||
|
||||
LongBuffer vertexBuffers = stack.longs(mesh.vertexBuffer);
|
||||
LongBuffer offsets = stack.longs(0);
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, vertexBuffers, offsets);
|
||||
|
||||
vkCmdBindIndexBuffer(commandBuffer, entity.indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
vkCmdBindIndexBuffer(commandBuffer, mesh.indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
|
||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
VKVariables.pipelineLayout,
|
||||
|
@ -72,7 +77,7 @@ public class EntityRenderer extends Renderer
|
|||
),
|
||||
null);
|
||||
|
||||
vkCmdDrawIndexed(commandBuffer, entity.vkMesh.indices.size(), 1, 0, 0, 0);
|
||||
vkCmdDrawIndexed(commandBuffer, mesh.vkMesh.indices.size(), 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.github.hydos.ginger.VulkanExample;
|
|||
import com.github.hydos.ginger.VulkanExample.*;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.vulkan.VKVariables;
|
||||
import com.github.hydos.ginger.engine.vulkan.elements.VKRenderObject;
|
||||
import com.github.hydos.ginger.engine.vulkan.managers.CommandBufferManager;
|
||||
import com.github.hydos.ginger.engine.vulkan.model.VKVertex;
|
||||
import com.github.hydos.ginger.engine.vulkan.render.*;
|
||||
|
@ -782,7 +783,7 @@ public class VKUtils
|
|||
buffer.rewind();
|
||||
}
|
||||
|
||||
private static void memcpy(ByteBuffer buffer, UniformBufferObject ubo) {
|
||||
private static void putUBOInMemory(ByteBuffer buffer, UniformBufferObject ubo) {
|
||||
|
||||
final int mat4Size = 16 * Float.BYTES;
|
||||
|
||||
|
@ -840,7 +841,7 @@ public class VKUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static void updateUniformBuffer(int currentImage) {
|
||||
public static void updateUniformBuffer(int currentImage, VKRenderObject renderObject) {
|
||||
|
||||
try(MemoryStack stack = stackPush()) {
|
||||
|
||||
|
@ -857,7 +858,7 @@ public class VKUtils
|
|||
PointerBuffer data = stack.mallocPointer(1);
|
||||
vkMapMemory(VKVariables.device, VKVariables.uniformBuffersMemory.get(currentImage), 0, UniformBufferObject.SIZEOF, 0, data);
|
||||
{
|
||||
memcpy(data.getByteBuffer(0, UniformBufferObject.SIZEOF), ubo);
|
||||
putUBOInMemory(data.getByteBuffer(0, UniformBufferObject.SIZEOF), ubo);
|
||||
}
|
||||
vkUnmapMemory(VKVariables.device, VKVariables.uniformBuffersMemory.get(currentImage));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue