use of net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader in project tdme by andreasdr.
the class Engine method init.
/**
* Initialize render engine
* @param drawable
* @param debug
*/
public void init(GLAutoDrawable drawable, boolean debug) {
// exit if already initialized like a offscreen engine instance
if (initialized == true)
return;
//
GLContext glContext = drawable.getGL().getContext();
if (drawable.getGL().isGL3()) {
GL3 gl = (GL3) drawable.getGL().getGL3();
if (debug == true) {
drawable.setGL(new DebugGL3(gl));
}
// use gl3 renderer
renderer = new GL3Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GL3");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// engine defaults
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(2048, 2048);
} else if (drawable.getGL().isGL2()) {
GL2 gl = (GL2) drawable.getGL().getGL2();
if (debug == true) {
drawable.setGL(new DebugGL2(gl));
}
// use gl2 renderer
renderer = new GL2Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GL2");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// engine defaults
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(2048, 2048);
} else if (drawable.getGL().isGLES2()) {
GLES2 gl = (GLES2) drawable.getGL().getGLES2();
if (debug == true) {
drawable.setGL(new DebugGLES2(gl));
}
// use gl es 2 renderer
renderer = new GLES2Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GLES2");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// is shadow mapping available?
if (renderer.isBufferObjectsAvailable() == true && renderer.isDepthTextureAvailable() == true) {
// yep, nice
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(512, 512);
} else {
// nope, renderer skinning on GPU to speed up things and do not shadow mapping
shadowMappingEnabled = false;
animationProcessingTarget = AnimationProcessingTarget.GPU;
}
} else {
System.out.println("Engine::init(): unsupported GL!");
return;
}
// init
initialized = true;
renderer.init();
renderer.renderingTexturingClientState = false;
// create manager
textureManager = new TextureManager(renderer);
vboManager = new VBOManager(renderer);
meshManager = new MeshManager();
// create object 3d vbo renderer
object3DVBORenderer = new Object3DVBORenderer(this, renderer);
object3DVBORenderer.init();
// create GUI
guiRenderer = new GUIRenderer(renderer);
guiRenderer.init();
gui = new GUI(this, guiRenderer);
gui.init();
// create camera
camera = new Camera(renderer);
partition = new PartitionQuadTree();
// create lights
for (int i = 0; i < lights.length; i++) lights[i] = new Light(renderer, i);
// create lighting shader
lightingShader = new LightingShader(renderer);
lightingShader.init();
// create particles shader
particlesShader = new ParticlesShader(this, renderer);
particlesShader.init();
// create GUI shader
guiShader = new GUIShader(renderer);
guiShader.init();
// check if VBOs are available
if (renderer.isBufferObjectsAvailable()) {
System.out.println("TDME::VBOs are available.");
} else {
System.out.println("TDME::VBOs are not available! Engine will not work!");
initialized = false;
}
// check FBO support
if (glContext.hasBasicFBOSupport() == false) {
System.out.println("TDME::Basic FBOs are not available!");
shadowMappingEnabled = false;
} else {
System.out.println("TDME::Basic FBOs are available.");
}
// initialize shadow mapping
if (shadowMappingEnabled == true) {
System.out.println("TDME::Using shadow mapping");
shadowMappingShaderPre = new ShadowMappingShaderPre(renderer);
shadowMappingShaderPre.init();
shadowMappingShaderRender = new ShadowMappingShaderRender(renderer);
shadowMappingShaderRender.init();
shadowMapping = new ShadowMapping(this, renderer, object3DVBORenderer);
} else {
System.out.println("TDME::Not using shadow mapping");
}
// print out animation processing target
System.out.println("TDME: animation processing target: " + animationProcessingTarget);
// determine initialized from sub systems
initialized &= shadowMappingShaderPre == null ? true : shadowMappingShaderPre.isInitialized();
initialized &= shadowMappingShaderRender == null ? true : shadowMappingShaderRender.isInitialized();
initialized &= lightingShader.isInitialized();
initialized &= particlesShader.isInitialized();
initialized &= guiShader.isInitialized();
//
System.out.println("TDME::initialized & ready: " + initialized);
}
Aggregations