/*     */ package org.engine;
/*     */ 
/*     */ import java.awt.Dimension;
/*     */ import java.nio.FloatBuffer;
/*     */ import org.lwjgl.BufferUtils;
/*     */ import org.lwjgl.opengl.GL11;
/*     */ import org.lwjgl.opengl.GL15;
/*     */ import org.lwjgl.opengl.GL20;
/*     */ import org.lwjgl.opengl.GL30C;
/*     */ import org.renderer.FBO;
/*     */ import org.renderer.PostProcessConfig;
/*     */ import org.renderer.PostProcessor;
/*     */ import org.renderer.SceneRenderer;
/*     */ import org.view.Camera;
/*     */ import org.world.World;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Renderer
/*     */   implements AutoCloseable
/*     */ {
/*  26 */   private static final float[] QUAD_VERTICES = new float[] { -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F, -1.0F, -1.0F, 1.0F };
/*  27 */   private static final int DRAW_COUNT = QUAD_VERTICES.length >> 1;
/*     */ 
/*     */ 
/*     */   
/*     */   private int arrayBufferHandle;
/*     */ 
/*     */ 
/*     */   
/*     */   private PostProcessConfig ppConfig;
/*     */ 
/*     */ 
/*     */   
/*     */   private PostProcessor postProcessor;
/*     */ 
/*     */   
/*     */   private SceneRenderer sceneRenderer;
/*     */ 
/*     */   
/*     */   private FBO fbo;
/*     */ 
/*     */   
/*     */   private Dimension size;
/*     */ 
/*     */ 
/*     */   
/*     */   public Renderer(Dimension size) throws AssertionError {
/*  53 */     this.ppConfig = new PostProcessConfig();
/*     */     
/*  55 */     createQuadGeometry();
/*     */     
/*  57 */     GL11.glEnable(3553);
/*     */     
/*  59 */     this.sceneRenderer = new SceneRenderer();
/*  60 */     this.postProcessor = new PostProcessor();
/*     */     
/*  62 */     this.fbo = new FBO(size);
/*     */ 
/*     */     
/*  65 */     this.size = size;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createQuadGeometry() {
/*  73 */     this.arrayBufferHandle = GL15.glGenBuffers();
/*     */ 
/*     */     
/*  76 */     FloatBuffer buffer = BufferUtils.createFloatBuffer(QUAD_VERTICES.length);
/*  77 */     buffer.put(QUAD_VERTICES);
/*  78 */     buffer.flip();
/*     */ 
/*     */     
/*  81 */     GL15.glBindBuffer(34962, this.arrayBufferHandle);
/*  82 */     GL15.glBufferData(34962, buffer, 35044);
/*  83 */     GL15.glBindBuffer(34962, 0);
/*     */ 
/*     */     
/*  86 */     buffer.clear();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void update(Dimension size, float globalTime, Camera camera, World world, boolean rebuildFBO) {
/* 100 */     if (rebuildFBO) {
/* 101 */       this.fbo.recreate(size);
/*     */     }
/*     */     
/* 104 */     this.sceneRenderer.bind();
/*     */     
/* 106 */     this.sceneRenderer.loadUniformData(size, globalTime, camera, world);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final void render() {
/* 114 */     renderSceneToFBO();
/*     */     
/* 116 */     renderFBOtoScreen();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void renderFBOtoScreen() {
/* 123 */     GL11.glEnableClientState(32884);
/*     */ 
/*     */     
/* 126 */     GL15.glBindBuffer(34962, this.arrayBufferHandle);
/*     */     
/* 128 */     GL11.glVertexPointer(2, 5126, 0, 0L);
/*     */ 
/*     */     
/* 131 */     this.postProcessor.bind();
/*     */     
/* 133 */     this.postProcessor.loadData(this.size, this.fbo, this.ppConfig);
/*     */ 
/*     */     
/* 136 */     GL11.glDrawArrays(4, 0, DRAW_COUNT);
/*     */     
/* 138 */     this.postProcessor.unbind();
/*     */ 
/*     */ 
/*     */     
/* 142 */     GL15.glBindBuffer(34962, 0);
/* 143 */     GL30C.glBindVertexArray(0);
/*     */ 
/*     */     
/* 146 */     GL11.glDisableClientState(32884);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void renderSceneToFBO() {
/* 153 */     GL11.glEnableClientState(32884);
/*     */ 
/*     */     
/* 156 */     GL15.glBindBuffer(34962, this.arrayBufferHandle);
/*     */     
/* 158 */     GL11.glVertexPointer(2, 5126, 0, 0L);
/*     */     
/* 160 */     this.fbo.bind();
/*     */ 
/*     */     
/* 163 */     GL11.glDrawArrays(4, 0, DRAW_COUNT);
/*     */ 
/*     */     
/* 166 */     this.fbo.unbind();
/*     */ 
/*     */     
/* 169 */     GL15.glBindBuffer(34962, 0);
/* 170 */     GL30C.glBindVertexArray(0);
/*     */     
/* 172 */     GL20.glUseProgram(0);
/*     */ 
/*     */     
/* 175 */     GL11.glDisableClientState(32884);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void close() throws Exception {
/* 181 */     GL15.glDeleteBuffers(this.arrayBufferHandle);
/*     */     
/* 183 */     this.sceneRenderer.close();
/* 184 */     this.postProcessor.close();
/* 185 */     this.fbo.close();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final PostProcessConfig getPpConfig() {
/* 194 */     return this.ppConfig;
/*     */   }
/*     */ }


/* Location:              /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/engine/Renderer.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */