renderer code cleanup

This commit is contained in:
austin 2025-05-18 23:46:33 -04:00
parent 6b5408f2ca
commit ae2dd048a6
16 changed files with 397 additions and 361 deletions

View File

@ -1891,6 +1891,7 @@ Convert Mesh.java to only use GL45
Material and Mesh cleanup work Material and Mesh cleanup work
Texture class cleanup work Texture class cleanup work
OS data wrapper OS data wrapper
Renderer code cleanup

View File

@ -13,17 +13,31 @@ import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.buffer.HomogenousUniformBuffer.HomogenousBufferTypes; import electrosphere.renderer.buffer.HomogenousUniformBuffer.HomogenousBufferTypes;
public class HomogenousInstancedArray { public class HomogenousInstancedArray {
//The type of this buffer
HomogenousBufferTypes type;
//The pointer for this buffer /**
int bufferPointer = -1; * The type of this buffer
//the bind point in the instance shader program for this buffer */
int capacity = -1; private HomogenousBufferTypes type;
//attribute index for a regular buffer
int attributeIndex; /**
//attribute indices for a matrix buffer * The pointer for this buffer
int[] matrixAttributeIndices; */
private int bufferPointer = -1;
/**
* the bind point in the instance shader program for this buffer
*/
private int capacity = -1;
/**
* attribute index for a regular buffer
*/
private int attributeIndex;
/**
* attribute indices for a matrix buffer
*/
private int[] matrixAttributeIndices;
/** /**
* Constructor * Constructor

View File

@ -33,15 +33,25 @@ public class HomogenousUniformBuffer {
DOUBLE, DOUBLE,
} }
//The type of this buffer /**
HomogenousBufferTypes type; * The type of this buffer
*/
private HomogenousBufferTypes type;
//The pointer for this buffer /**
int bufferPointer = -1; * The pointer for this buffer
//the bind point in the instance shader program for this buffer */
int capacity = -1; private int bufferPointer = -1;
//uniform name
String uniformName; /**
* the bind point in the instance shader program for this buffer
*/
private int capacity = -1;
/**
* uniform name
*/
private String uniformName;
/** /**
* Constructor * Constructor

View File

@ -10,20 +10,25 @@ import electrosphere.renderer.buffer.HomogenousUniformBuffer.HomogenousBufferTyp
*/ */
public class ShaderAttribute { public class ShaderAttribute {
//for single data types that map 1-1 with attributes (float, vec3, vec4, etc) /**
int attributeIndex = -1; * for single data types that map 1-1 with attributes (float, vec3, vec4, etc)
//for multi-attribute index types (mat4f, mat4d, etc) */
int[] attributeIndices; private int attributeIndex = -1;
/**
* for multi-attribute index types (mat4f, mat4d, etc)
*/
private int[] attributeIndices;
/** /**
* The name of the attribute * The name of the attribute
*/ */
String name; private String name;
/** /**
* The type of the attribute * The type of the attribute
*/ */
HomogenousBufferTypes type; private HomogenousBufferTypes type;
/** /**

View File

@ -18,12 +18,12 @@ public class ShaderStorageBuffer implements UniformBlockBinding {
/** /**
* The id for the buffer * The id for the buffer
*/ */
int id; private int id;
/** /**
* The java buffer associated with the SSBO * The java buffer associated with the SSBO
*/ */
ByteBuffer buffer; private ByteBuffer buffer;
/** /**
* Constructor * Constructor

View File

@ -14,13 +14,8 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL40;
import org.lwjgl.opengl.GL45; import org.lwjgl.opengl.GL45;
import static org.lwjgl.opengl.GL11.GL_NONE;
import static org.lwjgl.opengl.GL11.GL_TEXTURE;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
/** /**
* Framebuffer object * Framebuffer object
*/ */
@ -31,22 +26,36 @@ public class Framebuffer {
*/ */
public static final int DEFAULT_FRAMEBUFFER_POINTER = 0; public static final int DEFAULT_FRAMEBUFFER_POINTER = 0;
//the pointer to the framebuffer /**
int framebufferPointer; * the pointer to the framebuffer
//the mipmap level */
int mipMap = -1; private int framebufferPointer;
//the map of attachment point to texture object
Map<Integer,Texture> attachTextureMap = new HashMap<Integer,Texture>(); /**
//attached texture * the mipmap level
Texture texture; */
//the depth texture for the framebuffer private int mipMap = -1;
Texture depthTexture;
/**
* the map of attachment point to texture object
*/
private Map<Integer,Texture> attachTextureMap = new HashMap<Integer,Texture>();
/**
* attached texture
*/
private Texture texture;
/**
* the depth texture for the framebuffer
*/
private Texture depthTexture;
/** /**
* Creates a framebuffer * Creates a framebuffer
*/ */
public Framebuffer(){ public Framebuffer(){
this.framebufferPointer = GL40.glGenFramebuffers(); this.framebufferPointer = GL45.glGenFramebuffers();
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
@ -87,7 +96,7 @@ public class Framebuffer {
* @param openGLState The opengl state * @param openGLState The opengl state
*/ */
public void bind(OpenGLState openGLState){ public void bind(OpenGLState openGLState){
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); openGLState.glBindFramebuffer(GL45.GL_FRAMEBUFFER, this.framebufferPointer);
} }
/** /**
@ -98,7 +107,7 @@ public class Framebuffer {
if(this.framebufferPointer == DEFAULT_FRAMEBUFFER_POINTER){ if(this.framebufferPointer == DEFAULT_FRAMEBUFFER_POINTER){
throw new Error("Pointer is the default framebuffer!"); throw new Error("Pointer is the default framebuffer!");
} }
return GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) == GL40.GL_FRAMEBUFFER_COMPLETE; return GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL45.GL_FRAMEBUFFER) == GL45.GL_FRAMEBUFFER_COMPLETE;
} }
@ -109,13 +118,13 @@ public class Framebuffer {
*/ */
public void shouldBeComplete(OpenGLState openGLState) throws Exception{ public void shouldBeComplete(OpenGLState openGLState) throws Exception{
if(!this.isComplete(openGLState)){ if(!this.isComplete(openGLState)){
int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL45.GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
String attach0Type = ""; String attach0Type = "";
switch(colorAttach0){ switch(colorAttach0){
case GL_NONE: { case GL45.GL_NONE: {
attach0Type = "GL_NONE"; attach0Type = "GL_NONE";
} break; } break;
case GL_TEXTURE: { case GL45.GL_TEXTURE: {
attach0Type = " GL_TEXTURE"; attach0Type = " GL_TEXTURE";
} break; } break;
} }
@ -150,14 +159,14 @@ public class Framebuffer {
* Frees the framebuffer * Frees the framebuffer
*/ */
public void free(){ public void free(){
GL40.glDeleteFramebuffers(framebufferPointer); GL45.glDeleteFramebuffers(framebufferPointer);
} }
/** /**
* Blocks the thread until the framebuffer has compiled * Blocks the thread until the framebuffer has compiled
*/ */
public void blockUntilCompiled(){ public void blockUntilCompiled(){
while(GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) != GL40.GL_FRAMEBUFFER_UNDEFINED){ while(GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL45.GL_FRAMEBUFFER) != GL45.GL_FRAMEBUFFER_UNDEFINED){
try { try {
TimeUnit.MILLISECONDS.sleep(1); TimeUnit.MILLISECONDS.sleep(1);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -171,26 +180,26 @@ public class Framebuffer {
* @return The status * @return The status
*/ */
public String getStatus(){ public String getStatus(){
switch(GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER)){ switch(GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL45.GL_FRAMEBUFFER)){
case GL40.GL_FRAMEBUFFER_UNDEFINED: { case GL45.GL_FRAMEBUFFER_UNDEFINED: {
return "The specified framebuffer is the default read or draw framebuffer, but the default framebuffer does not exist."; return "The specified framebuffer is the default read or draw framebuffer, but the default framebuffer does not exist.";
} }
case GL40.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: { case GL45.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: {
return "Any of the framebuffer attachment points are framebuffer incomplete."; return "Any of the framebuffer attachment points are framebuffer incomplete.";
} }
case GL40.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: { case GL45.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: {
return "The framebuffer does not have at least one image attached to it."; return "The framebuffer does not have at least one image attached to it.";
} }
case GL40.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: { case GL45.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: {
return "The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi."; return "The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi.";
} }
case GL40.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: { case GL45.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: {
return "GL_READ_BUFFER is not GL_NONE and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point named by GL_READ_BUFFER."; return "GL_READ_BUFFER is not GL_NONE and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point named by GL_READ_BUFFER.";
} }
case GL40.GL_FRAMEBUFFER_UNSUPPORTED: { case GL45.GL_FRAMEBUFFER_UNSUPPORTED: {
return "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions."; return "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.";
} }
case GL40.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: { case GL45.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: {
return "The value of GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_RENDERBUFFER_SAMPLES does not match the value of GL_TEXTURE_SAMPLES."; return "The value of GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_RENDERBUFFER_SAMPLES does not match the value of GL_TEXTURE_SAMPLES.";
} }
case 0: { case 0: {
@ -235,19 +244,19 @@ public class Framebuffer {
if(texture.getTexturePointer() == Texture.UNINITIALIZED_TEXTURE){ if(texture.getTexturePointer() == Texture.UNINITIALIZED_TEXTURE){
throw new IllegalStateException("Trying to attach uninitialized image to frame buffer!"); throw new IllegalStateException("Trying to attach uninitialized image to frame buffer!");
} }
if(!GL40.glIsTexture(texture.getTexturePointer())){ if(!GL45.glIsTexture(texture.getTexturePointer())){
throw new IllegalStateException("Tried to attach incomplete texture to framebuffer!"); throw new IllegalStateException("Tried to attach incomplete texture to framebuffer!");
} }
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); openGLState.glBindFramebuffer(GL45.GL_FRAMEBUFFER, this.framebufferPointer);
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0); GL45.glFramebufferTexture2D(GL45.GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0 + attachmentNum, GL45.GL_TEXTURE_2D, texture.getTexturePointer(), 0);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
// check the attachment slot // check the attachment slot
int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL40.GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0 + attachmentNum, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL45.GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0 + attachmentNum, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
switch(colorAttach0){ switch(colorAttach0){
case GL_NONE: { case GL45.GL_NONE: {
throw new Error("Failed to attach!"); throw new Error("Failed to attach!");
} }
case GL_TEXTURE: { case GL45.GL_TEXTURE: {
} break; } break;
} }
Globals.renderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
@ -265,12 +274,12 @@ public class Framebuffer {
if(depthTexture.getTexturePointer() == Texture.UNINITIALIZED_TEXTURE){ if(depthTexture.getTexturePointer() == Texture.UNINITIALIZED_TEXTURE){
throw new IllegalStateException("Trying to attach uninitialized image to frame buffer!"); throw new IllegalStateException("Trying to attach uninitialized image to frame buffer!");
} }
if(!GL40.glIsTexture(depthTexture.getTexturePointer())){ if(!GL45.glIsTexture(depthTexture.getTexturePointer())){
throw new IllegalStateException("Tried to attach incomplete texture to framebuffer!"); throw new IllegalStateException("Tried to attach incomplete texture to framebuffer!");
} }
this.depthTexture = depthTexture; this.depthTexture = depthTexture;
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); openGLState.glBindFramebuffer(GL45.GL_FRAMEBUFFER, this.framebufferPointer);
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_DEPTH_ATTACHMENT, GL40.GL_TEXTURE_2D, this.depthTexture.getTexturePointer(), 0); GL45.glFramebufferTexture2D(GL45.GL_FRAMEBUFFER, GL45.GL_DEPTH_ATTACHMENT, GL45.GL_TEXTURE_2D, this.depthTexture.getTexturePointer(), 0);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
Globals.renderingEngine.defaultFramebuffer.bind(openGLState); Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
} }
@ -286,20 +295,20 @@ public class Framebuffer {
int height = openGLState.getViewport().y; int height = openGLState.getViewport().y;
//the formats we want opengl to return with //the formats we want opengl to return with
int pixelFormat = GL40.GL_RGBA; int pixelFormat = GL45.GL_RGBA;
int type = GL40.GL_UNSIGNED_BYTE; int type = GL45.GL_UNSIGNED_BYTE;
this.bind(openGLState); this.bind(openGLState);
if(this.framebufferPointer == Framebuffer.DEFAULT_FRAMEBUFFER_POINTER){ if(this.framebufferPointer == Framebuffer.DEFAULT_FRAMEBUFFER_POINTER){
//this is the default framebuffer, read from backbuffer because it is default //this is the default framebuffer, read from backbuffer because it is default
GL40.glReadBuffer(GL40.GL_BACK); GL45.glReadBuffer(GL45.GL_BACK);
//set viewport //set viewport
openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
} else if(attachTextureMap.containsKey(0)){ } else if(attachTextureMap.containsKey(0)){
//this is NOT the default framebuffer, read from the first color attachment //this is NOT the default framebuffer, read from the first color attachment
GL40.glReadBuffer(GL40.GL_COLOR_ATTACHMENT0); GL45.glReadBuffer(GL45.GL_COLOR_ATTACHMENT0);
//set viewport //set viewport
Texture texture = attachTextureMap.get(0); Texture texture = attachTextureMap.get(0);
@ -326,7 +335,7 @@ public class Framebuffer {
if(buffer == null || buffer.limit() < bufferSize){ if(buffer == null || buffer.limit() < bufferSize){
throw new Error("Failed to create buffer!"); throw new Error("Failed to create buffer!");
} }
GL40.glReadPixels(offsetX, offsetY, width, height, pixelFormat, type, buffer); GL45.glReadPixels(offsetX, offsetY, width, height, pixelFormat, type, buffer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//convert to a buffered images //convert to a buffered images
rVal = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); rVal = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
@ -337,7 +346,7 @@ public class Framebuffer {
int green = buffer.get(i + 1) & 0xFF; int green = buffer.get(i + 1) & 0xFF;
int blue = buffer.get(i + 2) & 0xFF; int blue = buffer.get(i + 2) & 0xFF;
int alpha = 255; int alpha = 255;
if(pixelFormat == GL40.GL_RGBA){ if(pixelFormat == GL45.GL_RGBA){
alpha = buffer.get(i + 3) & 0xFF; alpha = buffer.get(i + 3) & 0xFF;
} }
rVal.setRGB(x, height - (y + 1), (alpha << 24) | (red << 16) | (green << 8) | blue); rVal.setRGB(x, height - (y + 1), (alpha << 24) | (red << 16) | (green << 8) | blue);
@ -358,10 +367,10 @@ public class Framebuffer {
private static int pixelFormatToBytes(int format, int type){ private static int pixelFormatToBytes(int format, int type){
int multiplier = 1; int multiplier = 1;
switch(format){ switch(format){
case GL40.GL_RGBA: { case GL45.GL_RGBA: {
multiplier = 4; multiplier = 4;
} break; } break;
case GL40.GL_RGB: { case GL45.GL_RGB: {
multiplier = 3; multiplier = 3;
} break; } break;
default: { default: {

View File

@ -8,38 +8,8 @@ import electrosphere.renderer.texture.Texture;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL40;
import org.lwjgl.opengl.GL45; import org.lwjgl.opengl.GL45;
import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_LINEAR;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_NONE;
import static org.lwjgl.opengl.GL11.GL_RED;
import static org.lwjgl.opengl.GL11.GL_RGB;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_SHORT;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
import static org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE;
import static org.lwjgl.opengl.GL13.GL_CLAMP_TO_BORDER;
import static org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT0;
import static org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT1;
import static org.lwjgl.opengl.GL30.GL_DEPTH24_STENCIL8;
import static org.lwjgl.opengl.GL30.GL_DEPTH_STENCIL_ATTACHMENT;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.GL30.GL_RENDERBUFFER;
import static org.lwjgl.opengl.GL30.GL_HALF_FLOAT;
import static org.lwjgl.opengl.GL30.glBindRenderbuffer;
import static org.lwjgl.opengl.GL30.glFramebufferRenderbuffer;
import static org.lwjgl.opengl.GL30.glGenRenderbuffers;
import static org.lwjgl.opengl.GL30.glRenderbufferStorage;
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffer;
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffers;
import static org.lwjgl.opengl.GL45.glNamedFramebufferReadBuffer;
/** /**
* Utilities for framebuffer creation * Utilities for framebuffer creation
*/ */
@ -48,17 +18,17 @@ public class FramebufferUtils {
public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){ public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.bind(openGLState); texture.bind(openGLState);
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL45.GL_UNSIGNED_INT); texture.glTexImage2D(openGLState, width, height, GL45.GL_RGB, GL45.GL_UNSIGNED_INT);
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
texture.setBorderColor(openGLState, new float[]{0,0,0,1}); texture.setBorderColor(openGLState, new float[]{0,0,0,1});
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation) //guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
texture.bind(openGLState); texture.bind(openGLState);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE); openGLState.glBindTexture(GL45.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -67,17 +37,17 @@ public class FramebufferUtils {
public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){ public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.bind(openGLState); texture.bind(openGLState);
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL45.GL_UNSIGNED_INT); texture.glTexImage2D(openGLState, width, height, GL45.GL_RGBA, GL45.GL_UNSIGNED_INT);
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
texture.setBorderColor(openGLState, new float[]{0,0,0,1}); texture.setBorderColor(openGLState, new float[]{0,0,0,1});
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation) //guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
texture.bind(openGLState); texture.bind(openGLState);
openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D); openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL45.GL_TEXTURE_2D);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -86,18 +56,18 @@ public class FramebufferUtils {
public static Texture generateScreenTextureDepth(OpenGLState openGLState, int width, int height){ public static Texture generateScreenTextureDepth(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.bind(openGLState); texture.bind(openGLState);
texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_FLOAT); texture.glTexImage2D(openGLState, width, height, GL45.GL_DEPTH_COMPONENT, GL45.GL_FLOAT);
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
texture.setBorderColor(openGLState, new float[]{0,0,0,1}); texture.setBorderColor(openGLState, new float[]{0,0,0,1});
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation) //guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
texture.bind(openGLState); texture.bind(openGLState);
openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D); openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL45.GL_TEXTURE_2D);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -132,24 +102,24 @@ public class FramebufferUtils {
buffer.bind(openGLState); buffer.bind(openGLState);
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, GL45.GL_RGB, GL45.GL_UNSIGNED_BYTE);
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.attachTexture(openGLState,texture); buffer.attachTexture(openGLState,texture);
//renderbuffer //renderbuffer
int renderBuffer = glGenRenderbuffers(); int renderBuffer = GL45.glGenRenderbuffers();
glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); GL45.glBindRenderbuffer(GL45.GL_RENDERBUFFER, renderBuffer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); GL45.glRenderbufferStorage(GL45.GL_RENDERBUFFER, GL45.GL_DEPTH24_STENCIL8, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//bind rbo to fbo //bind rbo to fbo
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer); GL45.glFramebufferRenderbuffer(GL45.GL_FRAMEBUFFER, GL45.GL_DEPTH_STENCIL_ATTACHMENT, GL45.GL_RENDERBUFFER, renderBuffer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//check make sure compiled //check make sure compiled
buffer.shouldBeComplete(openGLState); buffer.shouldBeComplete(openGLState);
@ -170,25 +140,25 @@ public class FramebufferUtils {
buffer.bind(openGLState); buffer.bind(openGLState);
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, width, height, GL45.GL_RGBA, GL45.GL_UNSIGNED_BYTE);
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.attachTexture(openGLState,texture); buffer.attachTexture(openGLState,texture);
//renderbuffer //renderbuffer
int renderBuffer = glGenRenderbuffers(); int renderBuffer = GL45.glGenRenderbuffers();
GL40.glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); GL45.glBindRenderbuffer(GL45.GL_RENDERBUFFER, renderBuffer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
GL40.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); GL45.glRenderbufferStorage(GL45.GL_RENDERBUFFER, GL45.GL_DEPTH24_STENCIL8, width, height);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//bind rbo to fbo //bind rbo to fbo
buffer.bind(openGLState); buffer.bind(openGLState);
GL40.glFramebufferRenderbuffer(GL40.GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer); GL45.glFramebufferRenderbuffer(GL45.GL_FRAMEBUFFER, GL45.GL_DEPTH_STENCIL_ATTACHMENT, GL45.GL_RENDERBUFFER, renderBuffer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//check make sure compiled //check make sure compiled
buffer.shouldBeComplete(openGLState); buffer.shouldBeComplete(openGLState);
@ -204,7 +174,7 @@ public class FramebufferUtils {
public static Renderbuffer generateScreensizeStencilDepthRenderbuffer(OpenGLState openGLState){ public static Renderbuffer generateScreensizeStencilDepthRenderbuffer(OpenGLState openGLState){
Renderbuffer buffer = new Renderbuffer(); Renderbuffer buffer = new Renderbuffer();
buffer.bind(); buffer.bind();
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); GL45.glRenderbufferStorage(GL45.GL_RENDERBUFFER, GL45.GL_DEPTH24_STENCIL8, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
return buffer; return buffer;
} }
@ -217,20 +187,20 @@ public class FramebufferUtils {
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, ShadowMapPipeline.SHADOW_MAP_RESOLUTION, ShadowMapPipeline.SHADOW_MAP_RESOLUTION, GL_DEPTH_COMPONENT, GL_FLOAT); texture.glTexImage2D(openGLState, ShadowMapPipeline.SHADOW_MAP_RESOLUTION, ShadowMapPipeline.SHADOW_MAP_RESOLUTION, GL45.GL_DEPTH_COMPONENT, GL45.GL_FLOAT);
texture.setMinFilter(openGLState, GL_NEAREST); texture.setMinFilter(openGLState, GL45.GL_NEAREST);
texture.setMagFilter(openGLState, GL_NEAREST); texture.setMagFilter(openGLState, GL45.GL_NEAREST);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_BORDER);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_BORDER);
texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }); texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f });
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.setDepthAttachment(openGLState,texture); buffer.setDepthAttachment(openGLState,texture);
glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE); GL45.glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL45.GL_NONE);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE); GL45.glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL45.GL_NONE);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
@ -244,11 +214,11 @@ public class FramebufferUtils {
public static Texture generateDepthBufferTexture(OpenGLState openGLState, int width, int height){ public static Texture generateDepthBufferTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_SHORT); texture.glTexImage2D(openGLState, width, height, GL45.GL_DEPTH_COMPONENT, GL45.GL_SHORT);
texture.setMinFilter(openGLState, GL_NEAREST); texture.setMinFilter(openGLState, GL45.GL_NEAREST);
texture.setMagFilter(openGLState, GL_NEAREST); texture.setMagFilter(openGLState, GL45.GL_NEAREST);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_BORDER);
texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_BORDER);
texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }); texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f });
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -262,9 +232,9 @@ public class FramebufferUtils {
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.setDepthAttachment(openGLState,texture); buffer.setDepthAttachment(openGLState,texture);
glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE); GL45.glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL45.GL_NONE);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE); GL45.glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL45.GL_NONE);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
@ -277,18 +247,18 @@ public class FramebufferUtils {
public static Texture generateOITAccumulatorTexture(OpenGLState openGLState, int width, int height){ public static Texture generateOITAccumulatorTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_HALF_FLOAT); texture.glTexImage2D(openGLState, width, height, GL45.GL_RGBA, GL45.GL_HALF_FLOAT);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
} }
public static Texture generateOITRevealageTexture(OpenGLState openGLState, int width, int height){ public static Texture generateOITRevealageTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.setMinFilter(openGLState, GL_LINEAR); texture.setMinFilter(openGLState, GL45.GL_LINEAR);
texture.setMagFilter(openGLState, GL_LINEAR); texture.setMagFilter(openGLState, GL45.GL_LINEAR);
texture.glTexImage2D(openGLState, width, height, GL_RED, GL_FLOAT); texture.glTexImage2D(openGLState, width, height, GL45.GL_RED, GL45.GL_FLOAT);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
} }
@ -307,10 +277,10 @@ public class FramebufferUtils {
// const GLenum transparentDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; // const GLenum transparentDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
// glDrawBuffers(2, transparentDrawBuffers); // glDrawBuffers(2, transparentDrawBuffers);
IntBuffer drawBuffers = BufferUtils.createIntBuffer(2); IntBuffer drawBuffers = BufferUtils.createIntBuffer(2);
drawBuffers.put(GL_COLOR_ATTACHMENT0); drawBuffers.put(GL45.GL_COLOR_ATTACHMENT0);
drawBuffers.put(GL_COLOR_ATTACHMENT1); drawBuffers.put(GL45.GL_COLOR_ATTACHMENT1);
drawBuffers.flip(); drawBuffers.flip();
glNamedFramebufferDrawBuffers(buffer.getFramebufferPointer(),drawBuffers); GL45.glNamedFramebufferDrawBuffers(buffer.getFramebufferPointer(),drawBuffers);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
//check make sure compiled //check make sure compiled

View File

@ -1,29 +1,42 @@
package electrosphere.renderer.framebuffer; package electrosphere.renderer.framebuffer;
import static org.lwjgl.opengl.GL30.GL_RENDERBUFFER; import org.lwjgl.opengl.GL45;
import static org.lwjgl.opengl.GL30.glBindRenderbuffer;
import static org.lwjgl.opengl.GL30.glDeleteRenderbuffers;
import static org.lwjgl.opengl.GL30.glGenRenderbuffers;
/** /**
* A renderbuffer * A renderbuffer
*/ */
public class Renderbuffer { public class Renderbuffer {
/**
* The pointer for the renderbuffer
*/
int renderbuffer; int renderbuffer;
/**
* Constructor
*/
public Renderbuffer(){ public Renderbuffer(){
renderbuffer = glGenRenderbuffers(); renderbuffer = GL45.glGenRenderbuffers();
} }
/**
* Binds the renderbuffer
*/
public void bind(){ public void bind(){
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); GL45.glBindRenderbuffer(GL45.GL_RENDERBUFFER, renderbuffer);
} }
/**
* Gets the render buffer id
* @return
*/
public int getFramebufferID(){ public int getFramebufferID(){
return renderbuffer; return renderbuffer;
} }
/**
* Frees the render buffer
*/
public void free(){ public void free(){
glDeleteRenderbuffers(renderbuffer); GL45.glDeleteRenderbuffers(renderbuffer);
} }
} }

View File

@ -7,34 +7,63 @@ import org.joml.Vector3f;
*/ */
public class DirectionalLight { public class DirectionalLight {
//the direction of the light as a uniform vector /**
Vector3f direction; * the direction of the light as a uniform vector
*/
private Vector3f direction;
//the color /**
Vector3f color; * the color
*/
private Vector3f color;
/**
* Sets the direection of the directional light
* @param direction The direction
*/
public void setDirection(Vector3f direction) { public void setDirection(Vector3f direction) {
this.direction = direction; this.direction = direction;
} }
/**
* Sets the color of the light
* @param color The color
*/
public void setColor(Vector3f color) { public void setColor(Vector3f color) {
this.color = color; this.color = color;
} }
/**
* Gets the direction of the light
* @return The direction
*/
public Vector3f getDirection() { public Vector3f getDirection() {
return direction; return direction;
} }
/**
* Gets the color of the light
* @return The color
*/
public Vector3f getColor() { public Vector3f getColor() {
return color; return color;
} }
/**
* Constructor
* @param direction The direction of the light
*/
public DirectionalLight(Vector3f direction){ public DirectionalLight(Vector3f direction){
this.direction = direction; this.direction = direction;
color = new Vector3f(1.0f); color = new Vector3f(1.0f);
this.direction.normalize(); this.direction.normalize();
} }
/**
* Constructor
* @param direction The direction of the light
* @param color The color of the light
*/
public DirectionalLight(Vector3f direction, Vector3f color){ public DirectionalLight(Vector3f direction, Vector3f color){
this.direction = direction; this.direction = direction;
this.color = new Vector3f(color); this.color = new Vector3f(color);

View File

@ -111,12 +111,12 @@ public class LightManager {
} }
Totals to 436 bytes Totals to 436 bytes
*/ */
ShaderStorageBuffer clusterGridSSBO; private ShaderStorageBuffer clusterGridSSBO;
/** /**
* The map of all entities to point lights * The map of all entities to point lights
*/ */
Map<Entity,PointLight> entityPointLightMap; private Map<Entity,PointLight> entityPointLightMap;
/** /**
* The buffer of all point light data * The buffer of all point light data
@ -133,7 +133,7 @@ public class LightManager {
*/ */
ShaderStorageBuffer pointLightSSBO; private ShaderStorageBuffer pointLightSSBO;
/** /**
@ -144,12 +144,12 @@ public class LightManager {
vec3 color; //12 bytes vec3 color; //12 bytes
}; };
*/ */
ShaderStorageBuffer dirLightSSBO; private ShaderStorageBuffer dirLightSSBO;
/** /**
* The directional light * The directional light
*/ */
DirectionalLight directionalLight; private DirectionalLight directionalLight;
/** /**
* Constructor * Constructor

View File

@ -8,61 +8,137 @@ import electrosphere.data.entity.common.light.PointLightDescription;
* Data about a point light * Data about a point light
*/ */
public class PointLight { public class PointLight {
Vector3f position;
float constant;
float linear;
float quadratic;
float radius;
Vector3f color;
/**
* The position of the point light
*/
private Vector3f position;
/**
* The falloff constant of the point light
*/
private float constant;
/**
* The linear constant of the point light
*/
private float linear;
/**
* The quadratic constant of the point light
*/
private float quadratic;
/**
* The radius of the point light
*/
private float radius;
/**
* The color of the point light
*/
private Vector3f color;
/**
* Sets the position of the point light
* @param position The position
*/
public void setPosition(Vector3f position) { public void setPosition(Vector3f position) {
this.position = position; this.position = position;
} }
/**
* Sets the constant of the falloff
* @param constant The constant
*/
public void setConstant(float constant) { public void setConstant(float constant) {
this.constant = constant; this.constant = constant;
} }
/**
* Sets the linear constant of the falloff
* @param linear The linear constant
*/
public void setLinear(float linear) { public void setLinear(float linear) {
this.linear = linear; this.linear = linear;
} }
/**
* Sets the quadratic of the falloff
* @param quadratic The quadratic constant
*/
public void setQuadratic(float quadratic) { public void setQuadratic(float quadratic) {
this.quadratic = quadratic; this.quadratic = quadratic;
} }
/**
* Sets the radius of the point light
* @param radius The radius
*/
public void setRadius(float radius){ public void setRadius(float radius){
this.radius = radius; this.radius = radius;
} }
/**
* Sets the color of the point light
* @param color The color
*/
public void setColor(Vector3f color){ public void setColor(Vector3f color){
this.color = color; this.color = color;
} }
/**
* Gets the position of the point light
* @return The position
*/
public Vector3f getPosition() { public Vector3f getPosition() {
return position; return position;
} }
/**
* Gets the constant of the point light
* @return The constant
*/
public float getConstant() { public float getConstant() {
return constant; return constant;
} }
/**
* Gets the linear constant of the point light
* @return The linear constant
*/
public float getLinear() { public float getLinear() {
return linear; return linear;
} }
/**
* Gets the quadratic constant of the point light
* @return The quadratic constant
*/
public float getQuadratic() { public float getQuadratic() {
return quadratic; return quadratic;
} }
/**
* Gets the color of the point light
* @return The color
*/
public Vector3f getColor(){ public Vector3f getColor(){
return color; return color;
} }
/**
* Gets the radius of the point light
* @return The radius
*/
public float getRadius(){ public float getRadius(){
return radius; return radius;
} }
/**
* Constructs a point light
* @param position The position of the light
*/
protected PointLight(Vector3f position){ protected PointLight(Vector3f position){
this.position = position; this.position = position;
radius = 1; radius = 1;
@ -72,6 +148,11 @@ public class PointLight {
color = new Vector3f(1.0f); color = new Vector3f(1.0f);
} }
/**
* Constructor
* @param position The position of the point light
* @param color The color of the point light
*/
protected PointLight(Vector3f position, Vector3f color){ protected PointLight(Vector3f position, Vector3f color){
this.position = position; this.position = position;
radius = 1; radius = 1;

View File

@ -1,137 +0,0 @@
package electrosphere.renderer.light;
import org.joml.Vector3f;
/**
* Data about a spotlight
*/
public class SpotLight {
Vector3f position;
Vector3f direction;
float cutOff;
float outerCutOff;
float constant;
float linear;
float quadratic;
Vector3f ambient;
Vector3f diffuse;
Vector3f specular;
public void setPosition(Vector3f position) {
this.position = position;
}
public void setDirection(Vector3f direction) {
this.direction = direction;
}
public void setCutOff(float cutOff) {
this.cutOff = cutOff;
}
public void setOuterCutOff(float outerCutOff) {
this.outerCutOff = outerCutOff;
}
public void setConstant(float constant) {
this.constant = constant;
}
public void setLinear(float linear) {
this.linear = linear;
}
public void setQuadratic(float quadratic) {
this.quadratic = quadratic;
}
public void setAmbient(Vector3f ambient) {
this.ambient = ambient;
}
public void setDiffuse(Vector3f diffuse) {
this.diffuse = diffuse;
}
public void setSpecular(Vector3f specular) {
this.specular = specular;
}
public Vector3f getPosition() {
return position;
}
public Vector3f getDirection() {
return direction;
}
public float getCutOff() {
return cutOff;
}
public float getOuterCutOff() {
return outerCutOff;
}
public float getConstant() {
return constant;
}
public float getLinear() {
return linear;
}
public float getQuadratic() {
return quadratic;
}
public Vector3f getAmbient() {
return ambient;
}
public Vector3f getDiffuse() {
return diffuse;
}
public Vector3f getSpecular() {
return specular;
}
public SpotLight(Vector3f position, Vector3f direction){
this.position = position;
this.direction = direction;
cutOff = (float)Math.toRadians(12.5f);
outerCutOff = (float)Math.toRadians(15.0f);
constant = 1.0f;
linear = 0.01f;
quadratic = 0.01f;
ambient = new Vector3f(0.05f, 0.05f, 0.05f);
diffuse = new Vector3f(0.8f, 0.8f, 0.8f);
specular = new Vector3f(1.0f, 1.0f, 1.0f);
this.position.normalize();
this.direction.normalize();
ambient.normalize();
diffuse.normalize();
specular.normalize();
}
public SpotLight(Vector3f position, Vector3f direction, Vector3f color){
this.position = position;
this.direction = direction;
constant = 1.0f;
linear = 0.01f;
quadratic = 0.01f;
ambient = new Vector3f(color.x * 0.05f, color.y * 0.05f, color.z * 0.05f);
diffuse = new Vector3f(color.x * 0.8f, color.y * 0.8f, color.z * 0.8f);
specular = new Vector3f(color.x, color.y, color.z);
this.position.normalize();
this.direction.normalize();
ambient.normalize();
diffuse.normalize();
specular.normalize();
}
}

View File

@ -66,7 +66,7 @@ public class ModelLoader {
* @param localTextureMap The local texture map * @param localTextureMap The local texture map
* @param m The model * @param m The model
*/ */
static void attemptAddTexturesFromPathname(String path, TextureMap localTextureMap, Model m){ private static void attemptAddTexturesFromPathname(String path, TextureMap localTextureMap, Model m){
LoggerInterface.loggerRenderer.DEBUG("Load textures for " + path); LoggerInterface.loggerRenderer.DEBUG("Load textures for " + path);

View File

@ -28,33 +28,33 @@ public class Material {
/** /**
* The path of the diffuse texture when using texture lookups * The path of the diffuse texture when using texture lookups
*/ */
String diffuse; private String diffuse;
/** /**
* The path of the specular texture when using texture lookups * The path of the specular texture when using texture lookups
*/ */
String specular; private String specular;
/** /**
* Tracks whether this material has transparency or not * Tracks whether this material has transparency or not
*/ */
boolean hasTransparency = false; public boolean hasTransparency = false;
/** /**
* Sets whether this material should get its texture pointers from the assetManager by looking up diffuse and specular paths * Sets whether this material should get its texture pointers from the assetManager by looking up diffuse and specular paths
* or whether it should have a manually set texturePointer and not look up while binding * or whether it should have a manually set texturePointer and not look up while binding
*/ */
boolean usesFetch = true; private boolean usesFetch = true;
/** /**
* texture pointer for the specular * texture pointer for the specular
*/ */
int texturePointer; private int texturePointer;
/** /**
* texture pointer for the normal * texture pointer for the normal
*/ */
int normalPointer; private int normalPointer;
/** /**
* A material that contains textures * A material that contains textures

View File

@ -40,28 +40,55 @@ public class Texture {
*/ */
public static final int DEFAULT_TEXTURE = 0; public static final int DEFAULT_TEXTURE = 0;
//the pointer for the texture /**
int texturePointer = UNINITIALIZED_TEXTURE; * the pointer for the texture
//the width of the texture */
int width = -1; private int texturePointer = UNINITIALIZED_TEXTURE;
//the height of the texture
int height = -1;
//whether the texture has transparency or not
boolean hasTransparency;
//the path to the texture
String path = "";
//the border color
float[] borderColor = null;
//the min and max filter /**
int minFilter = -1; * the width of the texture
int maxFilter = -1; */
private int width = -1;
//the pixel format (ie RGB, ARGB, etc) /**
int pixelFormat = -1; * the height of the texture
*/
private int height = -1;
//the data type of a single component of a pixel (IE UNSIGNED_INT, BYTE, etc) /**
int datatype = -1; * whether the texture has transparency or not
*/
private boolean hasTransparency;
/**
* the path to the texture
*/
private String path = "";
/**
* the border color
*/
private float[] borderColor = null;
/**
* The min filter
*/
private int minFilter = -1;
/**
* The max filter
*/
private int maxFilter = -1;
/**
* the pixel format (ie RGB, ARGB, etc)
*/
private int pixelFormat = -1;
/**
* the data type of a single component of a pixel (IE UNSIGNED_INT, BYTE, etc)
*/
private int datatype = -1;
/** /**
* Creates a texture with a new opengl texture object * Creates a texture with a new opengl texture object
@ -370,7 +397,7 @@ public class Texture {
this.borderColor = borderColor; this.borderColor = borderColor;
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
GL45.glTexParameterfv(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_BORDER_COLOR, borderColor); GL45.glTexParameterfv(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_BORDER_COLOR, this.borderColor);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
@ -382,7 +409,7 @@ public class Texture {
this.minFilter = minFilter; this.minFilter = minFilter;
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MIN_FILTER, minFilter); GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MIN_FILTER, this.minFilter);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
@ -394,7 +421,7 @@ public class Texture {
this.maxFilter = maxFilter; this.maxFilter = maxFilter;
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MAG_FILTER, maxFilter); GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MAG_FILTER, this.maxFilter);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }

View File

@ -9,21 +9,35 @@ import java.util.Map;
public class TextureAtlas { public class TextureAtlas {
//A map of texture path -> coordinates in the atlas texture for its texture /**
Map<String,Integer> pathCoordMap = new HashMap<String,Integer>(); * A map of texture path -> coordinates in the atlas texture for its texture
*/
private Map<String,Integer> pathCoordMap = new HashMap<String,Integer>();
//the actual texture /**
Texture specular; * the actual texture
*/
private Texture specular;
//the normal texture /**
Texture normal; * the normal texture
*/
private Texture normal;
//the width in pixels of a single texture in the atlas /**
* the width in pixels of a single texture in the atlas
*/
public static final int ATLAS_ELEMENT_DIM = 64; public static final int ATLAS_ELEMENT_DIM = 64;
//the width in pixels of the whole atlas texture
/**
* the width in pixels of the whole atlas texture
*/
public static final int ATLAS_DIM = 1024; public static final int ATLAS_DIM = 1024;
//number of textures per row in the atlas
/**
* number of textures per row in the atlas
*/
public static final int ELEMENTS_PER_ROW = ATLAS_DIM / ATLAS_ELEMENT_DIM; public static final int ELEMENTS_PER_ROW = ATLAS_DIM / ATLAS_ELEMENT_DIM;
/** /**