GL cleanup
This commit is contained in:
@@ -14,7 +14,6 @@ import arc.graphics.gl.Shader;
|
|||||||
* @author kalle_h
|
* @author kalle_h
|
||||||
*/
|
*/
|
||||||
public class Bloom{
|
public class Bloom{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To use implement bloom more like a glow. Texture alpha channel can be
|
* To use implement bloom more like a glow. Texture alpha channel can be
|
||||||
* used as mask which part are glowing and which are not. see more info at:
|
* used as mask which part are glowing and which are not. see more info at:
|
||||||
@@ -61,10 +60,8 @@ public class Bloom{
|
|||||||
*/
|
*/
|
||||||
public void resume(){
|
public void resume(){
|
||||||
bloomShader.begin();
|
bloomShader.begin();
|
||||||
{
|
bloomShader.setUniformi("u_texture0", 0);
|
||||||
bloomShader.setUniformi("u_texture0", 0);
|
bloomShader.setUniformi("u_texture1", 1);
|
||||||
bloomShader.setUniformi("u_texture1", 1);
|
|
||||||
}
|
|
||||||
bloomShader.end();
|
bloomShader.end();
|
||||||
|
|
||||||
setSize(w, h);
|
setSize(w, h);
|
||||||
@@ -83,13 +80,11 @@ public class Bloom{
|
|||||||
* blending = false 32bits = true
|
* blending = false 32bits = true
|
||||||
*/
|
*/
|
||||||
public Bloom(){
|
public Bloom(){
|
||||||
initialize(Core.graphics.getWidth() / 4, Core.graphics.getHeight() / 4,
|
initialize(Core.graphics.getWidth() / 4, Core.graphics.getHeight() / 4, null, false, false, true);
|
||||||
null, false, false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bloom(boolean useBlending){
|
public Bloom(boolean useBlending){
|
||||||
initialize(Core.graphics.getWidth() / 4, Core.graphics.getHeight() / 4,
|
initialize(Core.graphics.getWidth() / 4, Core.graphics.getHeight() / 4, null, false, useBlending, true);
|
||||||
null, false, useBlending, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,8 +100,7 @@ public class Bloom{
|
|||||||
* and only do blooming on certain objects param use32bitFBO does
|
* and only do blooming on certain objects param use32bitFBO does
|
||||||
* fbo use higher precision than 16bits.
|
* fbo use higher precision than 16bits.
|
||||||
*/
|
*/
|
||||||
public Bloom(int FBO_W, int FBO_H, boolean hasDepth, boolean useBlending,
|
public Bloom(int FBO_W, int FBO_H, boolean hasDepth, boolean useBlending, boolean use32bitFBO){
|
||||||
boolean use32bitFBO){
|
|
||||||
initialize(FBO_W, FBO_H, null, hasDepth, useBlending, use32bitFBO);
|
initialize(FBO_W, FBO_H, null, hasDepth, useBlending, use32bitFBO);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -129,18 +123,14 @@ public class Bloom{
|
|||||||
* and only do blooming on certain objects param use32bitFBO does
|
* and only do blooming on certain objects param use32bitFBO does
|
||||||
* fbo use higher precision than 16bits.
|
* fbo use higher precision than 16bits.
|
||||||
*/
|
*/
|
||||||
public Bloom(int FBO_W, int FBO_H, FrameBuffer sceneIsCapturedHere,
|
public Bloom(int FBO_W, int FBO_H, FrameBuffer sceneIsCapturedHere, boolean useBlending, boolean use32bitFBO){
|
||||||
boolean useBlending, boolean use32bitFBO){
|
initialize(FBO_W, FBO_H, sceneIsCapturedHere, false, useBlending, use32bitFBO);
|
||||||
|
|
||||||
initialize(FBO_W, FBO_H, sceneIsCapturedHere, false, useBlending,
|
|
||||||
use32bitFBO);
|
|
||||||
disposeFBO = false;
|
disposeFBO = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(int FBO_W, int FBO_H, FrameBuffer fbo,
|
private void initialize(int FBO_W, int FBO_H, FrameBuffer fbo, boolean hasDepth, boolean useBlending, boolean use32bitFBO){
|
||||||
boolean hasDepth, boolean useBlending, boolean use32bitFBO){
|
|
||||||
blending = useBlending;
|
blending = useBlending;
|
||||||
Format format = null;
|
Format format;
|
||||||
|
|
||||||
if(use32bitFBO){
|
if(use32bitFBO){
|
||||||
if(useBlending){
|
if(useBlending){
|
||||||
@@ -157,8 +147,7 @@ public class Bloom{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fbo == null){
|
if(fbo == null){
|
||||||
frameBuffer = new FrameBuffer(format, Core.graphics.getWidth(),
|
frameBuffer = new FrameBuffer(format, Core.graphics.getWidth(), Core.graphics.getHeight(), hasDepth);
|
||||||
Core.graphics.getHeight(), hasDepth);
|
|
||||||
}else{
|
}else{
|
||||||
frameBuffer = fbo;
|
frameBuffer = fbo;
|
||||||
}
|
}
|
||||||
@@ -190,10 +179,8 @@ public class Bloom{
|
|||||||
setThreshold(0.5f);
|
setThreshold(0.5f);
|
||||||
|
|
||||||
bloomShader.begin();
|
bloomShader.begin();
|
||||||
{
|
bloomShader.setUniformi("u_texture0", 0);
|
||||||
bloomShader.setUniformi("u_texture0", 0);
|
bloomShader.setUniformi("u_texture1", 1);
|
||||||
bloomShader.setUniformi("u_texture1", 1);
|
|
||||||
}
|
|
||||||
bloomShader.end();
|
bloomShader.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,8 +206,8 @@ public class Bloom{
|
|||||||
if(!capturing){
|
if(!capturing){
|
||||||
capturing = true;
|
capturing = true;
|
||||||
frameBuffer.begin();
|
frameBuffer.begin();
|
||||||
Core.gl.glClearColor(r, g, b, a);
|
Gl.clearColor(r, g, b, a);
|
||||||
Core.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gl.clear(Gl.colorBufferBit);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,23 +239,22 @@ public class Bloom{
|
|||||||
frameBuffer.end();
|
frameBuffer.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.gl.glDisable(GL20.GL_BLEND);
|
Gl.disable(Gl.blend);
|
||||||
Core.gl.glDisable(GL20.GL_DEPTH_TEST);
|
Gl.disable(Gl.depthTest);
|
||||||
Core.gl.glDepthMask(false);
|
Gl.depthMask(false);
|
||||||
|
|
||||||
gaussianBlur();
|
gaussianBlur();
|
||||||
|
|
||||||
if(blending){
|
if(blending){
|
||||||
Core.gl.glEnable(GL20.GL_BLEND);
|
Gl.enable(Gl.blend);
|
||||||
Core.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
Gl.blendFunc(Gl.srcAlpha, Gl.oneMinusSrcAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
pingPongTex1.bind(1);
|
pingPongTex1.bind(1);
|
||||||
original.bind(0);
|
original.bind(0);
|
||||||
|
|
||||||
bloomShader.begin();
|
bloomShader.begin();
|
||||||
{
|
fullScreenQuad.render(bloomShader, Gl.triangleFan);
|
||||||
fullScreenQuad.render(bloomShader, GL20.GL_TRIANGLE_FAN);
|
|
||||||
}
|
|
||||||
bloomShader.end();
|
bloomShader.end();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -279,15 +265,9 @@ public class Bloom{
|
|||||||
|
|
||||||
original.bind(0);
|
original.bind(0);
|
||||||
pingPongBuffer1.begin();
|
pingPongBuffer1.begin();
|
||||||
{
|
tresholdShader.begin();
|
||||||
tresholdShader.begin();
|
fullScreenQuad.render(tresholdShader, Gl.triangleFan, 0, 4);
|
||||||
{
|
tresholdShader.end();
|
||||||
// tresholdShader.setUniformi("u_texture0", 0);
|
|
||||||
fullScreenQuad.render(tresholdShader, GL20.GL_TRIANGLE_FAN, 0,
|
|
||||||
4);
|
|
||||||
}
|
|
||||||
tresholdShader.end();
|
|
||||||
}
|
|
||||||
pingPongBuffer1.end();
|
pingPongBuffer1.end();
|
||||||
|
|
||||||
for(int i = 0; i < blurPasses; i++){
|
for(int i = 0; i < blurPasses; i++){
|
||||||
@@ -296,30 +276,19 @@ public class Bloom{
|
|||||||
|
|
||||||
// horizontal
|
// horizontal
|
||||||
pingPongBuffer2.begin();
|
pingPongBuffer2.begin();
|
||||||
{
|
blurShader.begin();
|
||||||
blurShader.begin();
|
blurShader.setUniformf("dir", 1f, 0f);
|
||||||
{
|
fullScreenQuad.render(blurShader, Gl.triangleFan, 0, 4);
|
||||||
blurShader.setUniformf("dir", 1f, 0f);
|
blurShader.end();
|
||||||
fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0,
|
|
||||||
4);
|
|
||||||
}
|
|
||||||
blurShader.end();
|
|
||||||
}
|
|
||||||
pingPongBuffer2.end();
|
pingPongBuffer2.end();
|
||||||
|
|
||||||
pingPongTex2.bind(0);
|
pingPongTex2.bind(0);
|
||||||
// vertical
|
// vertical
|
||||||
pingPongBuffer1.begin();
|
pingPongBuffer1.begin();
|
||||||
{
|
blurShader.begin();
|
||||||
blurShader.begin();
|
blurShader.setUniformf("dir", 0f, 1f);
|
||||||
{
|
fullScreenQuad.render(blurShader, Gl.triangleFan, 0, 4);
|
||||||
blurShader.setUniformf("dir", 0f, 1f);
|
blurShader.end();
|
||||||
|
|
||||||
fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0,
|
|
||||||
4);
|
|
||||||
}
|
|
||||||
blurShader.end();
|
|
||||||
}
|
|
||||||
pingPongBuffer1.end();
|
pingPongBuffer1.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,9 +303,7 @@ public class Bloom{
|
|||||||
public void setBloomIntesity(float intensity){
|
public void setBloomIntesity(float intensity){
|
||||||
bloomIntensity = intensity;
|
bloomIntensity = intensity;
|
||||||
bloomShader.begin();
|
bloomShader.begin();
|
||||||
{
|
bloomShader.setUniformf("BloomIntensity", intensity);
|
||||||
bloomShader.setUniformf("BloomIntensity", intensity);
|
|
||||||
}
|
|
||||||
bloomShader.end();
|
bloomShader.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,9 +317,7 @@ public class Bloom{
|
|||||||
public void setOriginalIntesity(float intensity){
|
public void setOriginalIntesity(float intensity){
|
||||||
originalIntensity = intensity;
|
originalIntensity = intensity;
|
||||||
bloomShader.begin();
|
bloomShader.begin();
|
||||||
{
|
bloomShader.setUniformf("OriginalIntensity", intensity);
|
||||||
bloomShader.setUniformf("OriginalIntensity", intensity);
|
|
||||||
}
|
|
||||||
bloomShader.end();
|
bloomShader.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,10 +329,7 @@ public class Bloom{
|
|||||||
public void setThreshold(float threshold){
|
public void setThreshold(float threshold){
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
tresholdShader.begin();
|
tresholdShader.begin();
|
||||||
{
|
tresholdShader.setUniformf("threshold", threshold, 1f / (1 - threshold));
|
||||||
tresholdShader.setUniformf("threshold", threshold,
|
|
||||||
1f / (1 - threshold));
|
|
||||||
}
|
|
||||||
tresholdShader.end();
|
tresholdShader.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,8 +346,7 @@ public class Bloom{
|
|||||||
*/
|
*/
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
try{
|
try{
|
||||||
if(disposeFBO)
|
if(disposeFBO) frameBuffer.dispose();
|
||||||
frameBuffer.dispose();
|
|
||||||
|
|
||||||
fullScreenQuad.dispose();
|
fullScreenQuad.dispose();
|
||||||
|
|
||||||
@@ -402,9 +363,10 @@ public class Bloom{
|
|||||||
|
|
||||||
private static Mesh createFullScreenQuad(){
|
private static Mesh createFullScreenQuad(){
|
||||||
float[] verts = {-1, -1, 0, 0, 1, -1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 1};
|
float[] verts = {-1, -1, 0, 0, 1, -1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 1};
|
||||||
Mesh tmpMesh = new Mesh(true, 4, 0, new VertexAttribute(
|
Mesh tmpMesh = new Mesh(true, 4, 0,
|
||||||
Usage.Position, 2, "a_position"), new VertexAttribute(
|
new VertexAttribute(Usage.Position, 2, "a_position"),
|
||||||
Usage.TextureCoordinates, 2, "a_texCoord0"));
|
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0")
|
||||||
|
);
|
||||||
|
|
||||||
tmpMesh.setVertices(verts);
|
tmpMesh.setVertices(verts);
|
||||||
return tmpMesh;
|
return tmpMesh;
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
package mindustry.graphics;
|
package mindustry.graphics;
|
||||||
|
|
||||||
import arc.Core;
|
import arc.*;
|
||||||
import arc.Events;
|
import arc.graphics.*;
|
||||||
import arc.struct.*;
|
|
||||||
import arc.struct.IntSet.IntSetIterator;
|
|
||||||
import arc.graphics.Camera;
|
|
||||||
import arc.graphics.GL20;
|
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.Mathf;
|
import arc.math.*;
|
||||||
|
import arc.struct.*;
|
||||||
|
import arc.struct.IntSet.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.game.EventType.WorldLoadEvent;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.world.Tile;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.Floor;
|
import mindustry.world.blocks.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
|
|
||||||
import static mindustry.Vars.tilesize;
|
import static mindustry.Vars.*;
|
||||||
import static mindustry.Vars.world;
|
|
||||||
|
|
||||||
public class FloorRenderer implements Disposable{
|
public class FloorRenderer implements Disposable{
|
||||||
private final static int chunksize = 64;
|
private final static int chunksize = 64;
|
||||||
@@ -104,7 +101,7 @@ public class FloorRenderer implements Disposable{
|
|||||||
cbatch.setProjection(Core.camera.projection());
|
cbatch.setProjection(Core.camera.projection());
|
||||||
cbatch.beginDraw();
|
cbatch.beginDraw();
|
||||||
|
|
||||||
Core.gl.glEnable(GL20.GL_BLEND);
|
Gl.enable(Gl.blend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endDraw(){
|
public void endDraw(){
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
package mindustry.graphics;
|
package mindustry.graphics;
|
||||||
|
|
||||||
import arc.Core;
|
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.VertexAttributes.Usage;
|
import arc.graphics.VertexAttributes.*;
|
||||||
import arc.graphics.g2d.BatchShader;
|
import arc.graphics.g2d.*;
|
||||||
import arc.graphics.g2d.TextureRegion;
|
import arc.graphics.gl.*;
|
||||||
import arc.graphics.gl.Shader;
|
import arc.math.*;
|
||||||
import arc.math.Mathf;
|
import arc.util.*;
|
||||||
import arc.math.Matrix3;
|
|
||||||
import arc.util.Disposable;
|
|
||||||
import arc.util.Strings;
|
|
||||||
|
|
||||||
//TODO this class is a trainwreck, remove it
|
//TODO this class is a trainwreck, remove it
|
||||||
public class IndexedRenderer implements Disposable{
|
public class IndexedRenderer implements Disposable{
|
||||||
@@ -60,7 +56,7 @@ public class IndexedRenderer implements Disposable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render(Texture texture){
|
public void render(Texture texture){
|
||||||
Core.gl.glEnable(GL20.GL_BLEND);
|
Gl.enable(Gl.blend);
|
||||||
|
|
||||||
updateMatrix();
|
updateMatrix();
|
||||||
|
|
||||||
@@ -71,7 +67,7 @@ public class IndexedRenderer implements Disposable{
|
|||||||
program.setUniformMatrix4("u_projTrans", BatchShader.copyTransform(combined));
|
program.setUniformMatrix4("u_projTrans", BatchShader.copyTransform(combined));
|
||||||
program.setUniformi("u_texture", 0);
|
program.setUniformi("u_texture", 0);
|
||||||
|
|
||||||
mesh.render(program, GL20.GL_TRIANGLES, 0, vertices.length / vsize);
|
mesh.render(program, Gl.triangles, 0, vertices.length / vsize);
|
||||||
|
|
||||||
program.end();
|
program.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=e18f0f1074ef97fc72053c57d82c39183420575d
|
archash=a85dbe44f7fb7aa66a28755931efee5e2e294a29
|
||||||
|
|||||||
Reference in New Issue
Block a user