public ShaderProgram(MyFile vertexFile, MyFile geometryFile, MyFile fragmentFile, String... inVariables) { int vertexShaderID = loadShader(vertexFile, GL20.GL_VERTEX_SHADER); int geometryShaderID = loadShader(geometryFile, GL32.GL_GEOMETRY_SHADER); int fragmentShaderID = loadShader(fragmentFile, GL20.GL_FRAGMENT_SHADER); programID = GL20.glCreateProgram(); GL20.glAttachShader(programID, vertexShaderID); GL20.glAttachShader(programID, geometryShaderID); GL20.glAttachShader(programID, fragmentShaderID); bindAttributes(inVariables); GL20.glLinkProgram(programID); GL20.glDetachShader(programID, vertexShaderID); GL20.glDetachShader(programID, geometryShaderID); GL20.glDetachShader(programID, fragmentShaderID); GL20.glDeleteShader(vertexShaderID); GL20.glDeleteShader(geometryShaderID); GL20.glDeleteShader(fragmentShaderID); }
private ExtendedGLSLProgram compileGLSL( String vertexShaderCode, String fragmentShaderCode, String geometryShaderCode, String tcsShaderCode, String tesShaderCode, ProgramAssemblyInfo assemblyInfo) { int vertexShader = compileShader(GL20.GL_VERTEX_SHADER, vertexShaderCode, assemblyInfo); int fragmentShader = compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderCode, assemblyInfo); int geometryShader = compileShader(GL32.GL_GEOMETRY_SHADER, geometryShaderCode, assemblyInfo); int tcsShader = compileShader(GL40.GL_TESS_CONTROL_SHADER, tcsShaderCode, assemblyInfo); int tesShader = compileShader(GL40.GL_TESS_EVALUATION_SHADER, tesShaderCode, assemblyInfo); int program; String[] outNames = ProgramOutputResolver.getOutput(fragmentShaderCode); program = GLSLShaderCompiler.createProgram( new int[]{vertexShader, tcsShader, tesShader, geometryShader, fragmentShader}, outNames, assemblyInfo.getProgramName() ); return new ExtendedGLSLProgram(fragmentShader, vertexShader, geometryShader, tcsShader, tesShader, program); }
public GLShader(String _name, String type_as_string) { this.name = _name; switch (type_as_string) { case "GL_VERTEX_SHADER": this.type = GL20.GL_VERTEX_SHADER; break; case "GL_FRAGMENT_SHADER": this.type = GL20.GL_FRAGMENT_SHADER; break; case "GL_GEOMETRY_SHADER": this.type = GL32.GL_GEOMETRY_SHADER; break; default: Logger.getRootLogger().error("Unknow GL_TYPE " + type_as_string); break; } }
public void cancel() { if (hitIdSync != -1) { GL32.glDeleteSync(hitIdSync); hitIdSync = -1; } if (worldPositionSync != -1) { GL32.glDeleteSync(worldPositionSync); worldPositionSync = -1; } if (localPositionSync != -1) { GL32.glDeleteSync(localPositionSync); localPositionSync = -1; } if (workingPboIndex != -1) { renderer.freePbos.add(workingPboIndex); } }
private void recreate() { frameBufferID = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT1, GL11.GL_TEXTURE_2D, positionTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT2, GL11.GL_TEXTURE_2D, normalTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT3, GL11.GL_TEXTURE_2D, specularTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) { Logs.e("Framebuffer error: " + GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER)); throw new RuntimeException("Frame buffer is not complete"); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
private void recreate() { frameBufferID = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT1, GL11.GL_TEXTURE_2D, worldPositionTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT2, GL11.GL_TEXTURE_2D, localPositionTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) { Logs.e("Framebuffer error: " + GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER)); throw new RuntimeException("Frame buffer is not complete"); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
protected void compileShaders(String vertexShader, String geometryShader, String fragmentShader) throws Exception { if(!isCompiled()) return; $setValue_vertexShaderHandle(loadShader(GL20.GL_VERTEX_SHADER, vertexShader)); geometryShaderHandle = loadShader(GL32.GL_GEOMETRY_SHADER, geometryShader); $setValue_fragmentShaderHandle(loadShader(GL20.GL_FRAGMENT_SHADER, fragmentShader)); if(geometryShaderHandle == -1) { $setValue_isCompiled(false); return; } int programId = linkProgram(createProgram()); if(programId == -1) { $setValue_isCompiled(false); return; } $setValue_program(programId); $setValue_isCompiled(true); }
private static void throwIfLANotSupported() { if(!GLContext.getCapabilities().OpenGL30) { return; } if(!GLContext.getCapabilities().OpenGL32) { if(!GLContext.getCapabilities().GL_ARB_compatibility) { throw new ImageFormatUnsupportedException("Core OpenGL contexts cannot use Luminance/alpha."); } } else { int profileMask = glGetInteger(GL32.GL_CONTEXT_PROFILE_MASK); if((profileMask & GL32.GL_CONTEXT_CORE_PROFILE_BIT) != 0) { throw new ImageFormatUnsupportedException("Core OpenGL contexts cannot use Luminance/alpha."); } } }
/** * Prepares for a rendering pass. The depth and colour buffers of the * current framebuffer are cleared and a few other default settings are set. */ private void prepare() { GL11.glClearColor(1f, 1f, 1f, 1f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL32.glProvokingVertex(GL32.GL_FIRST_VERTEX_CONVENTION); OpenGlUtils.cullBackFaces(true); OpenGlUtils.enableDepthTesting(true); OpenGlUtils.antialias(true); }
public FBO attachTexture(Texture texture, int attachment, boolean updateViewPort) { this.bind(); this.texture = texture; this.viewport.setWidth((int) this.texture.width()); this.viewport.setHeight((int) this.texture.height()); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, attachment, this.texture.handle(), 0); this.unbind(); return this; }
/** * A few general settings. Clears the colour and depth buffer before * rendering, turns on backface culling, enables depth testing, turns on * antialiasing and allows for wireframe rendering if the "G" key is * pressed. The provoking vertex convention is also set here, indicating * that the first vertex of each triangle should be the provoking vertex. * This is important when using the "flat" type qualifier in the shaders. */ private void prepare() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL32.glProvokingVertex(GL32.GL_FIRST_VERTEX_CONVENTION); OpenGlUtils.cullBackFaces(true); OpenGlUtils.enableDepthTesting(true); OpenGlUtils.antialias(true); if (Keyboard.isKeyDown(Keyboard.KEY_G)) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); } else { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); } }
/** * Prepares for a rendering pass. The depth and colour buffers of the * current framebuffer are cleared and a few other default settings are set. */ private void prepare() { GL11.glClearColor(0f, 0.66f, 0.94f, 1f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL32.glProvokingVertex(GL32.GL_FIRST_VERTEX_CONVENTION); OpenGlUtils.cullBackFaces(true); OpenGlUtils.enableDepthTesting(true); OpenGlUtils.antialias(true); }
private int createTextureAttachment( int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, texture, 0); return texture; }
private int createDepthTextureAttachment(int width, int height){ int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0); return texture; }
private void init() { bindDraw(); GL32.glFramebufferTexture(GL30.GL_DRAW_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, gBuffer.getTextureName(3), 0); for(int i = 0; i < 3; i++) { int offset = GL30.GL_COLOR_ATTACHMENT0 + i; GL32.glFramebufferTexture(GL30.GL_DRAW_FRAMEBUFFER, offset, gBuffer.getTextureName(i), 0); } int buffers[] = {GL30.GL_COLOR_ATTACHMENT0, GL30.GL_COLOR_ATTACHMENT1, GL30.GL_COLOR_ATTACHMENT2}; GL20.glDrawBuffers(buffers); int status = GL30.glCheckFramebufferStatus(GL30.GL_DRAW_FRAMEBUFFER); if(status == GL30.GL_FRAMEBUFFER_COMPLETE) complete = true; else throw new FramebufferException("Failed to assemble framebuffer: " + getName() + ". Status is: " + status); }
private int createTextureAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); if (DisplayManager.hasAttribs()) GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, texture, 0); return texture; }
private int createDepthTextureAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); if (DisplayManager.hasAttribs()) GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0); return texture; }
private static int createDepthBufferAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); if (DisplayManager.hasAttribs()) GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0); return texture; }
/** * Create a new framebuffer * @param width The width * @param height The height */ public FramebufferDeferred(int width, int height) { this.width = width; this.height = height; depthTexutreID = GL11.glGenTextures(); frameBufferID = GL30.glGenFramebuffers(); colorTextureID = genTexture(width, height); positionTextureID = genTextureDetailed(width, height); normalTextureID = genTextureDetailed(width, height); specularTextureID = genTextureDetailed(width, height); GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexutreID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_DEPTH_COMPONENT32F, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT1, GL11.GL_TEXTURE_2D, positionTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT2, GL11.GL_TEXTURE_2D, normalTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT3, GL11.GL_TEXTURE_2D, specularTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) { Logs.d("Failed to create framebuffer of size " + width + "x" + height); throw new RuntimeException("Frame buffer is not complete"); } GL20.glDrawBuffers(DRAW_BUFFERS); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); framebuffers.add(this); }
/** * Create a new framebuffer * @param width The width * @param height The height */ public Framebuffer3D(int width, int height) { this.width = width; this.height = height; colorTextureID = GL11.glGenTextures(); depthTexutreID = GL11.glGenTextures(); frameBufferID = GL30.glGenFramebuffers(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTextureID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexutreID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_DEPTH_COMPONENT32F, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) throw new RuntimeException("Frame buffer is not complete"); GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); framebuffers.add(this); }
private void recreate() { frameBufferID = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) { Logs.e("Framebuffer error: " + GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER)); throw new RuntimeException("Frame buffer is not complete"); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
/** * Create a new framebuffer * @param width The width * @param height The height */ public FramebufferMousePick(int width, int height) { this.width = width; this.height = height; depthTexutreID = GL11.glGenTextures(); frameBufferID = GL30.glGenFramebuffers(); colorTextureID = genTextureDetailed(width, height); worldPositionTextureID = genTextureDetailed(width, height); localPositionTextureID = genTextureDetailed(width, height); GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexutreID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_DEPTH_COMPONENT32F, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT1, GL11.GL_TEXTURE_2D, worldPositionTextureID, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT2, GL11.GL_TEXTURE_2D, localPositionTextureID, 0); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0); if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) { Logs.d("Failed to create framebuffer of size " + width + "x" + height); throw new RuntimeException("Frame buffer is not complete"); } GL20.glDrawBuffers(DRAW_BUFFERS); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); framebuffers.add(this); }
private static void buildMapping() { if (mapping != null) return; Multimap<Integer, String> map = HashMultimap.create(); List<Class<?>> classes = ImmutableList.of( GL11.class, GL12.class, GL13.class, GL14.class, GL15.class, GL20.class, GL21.class, GL30.class, GL31.class, GL32.class, GL33.class, GL40.class, GL41.class, GL42.class, GL43.class, GL44.class, GL45.class, GLFW.class ); for (Class<?> clazz : classes) { for (Field f : clazz.getDeclaredFields()) { if (f.getName().toUpperCase(Locale.ROOT).equals(f.getName()) && f.getType() == int.class && Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) { List<String> li = Splitter.on('_').splitToList(f.getName()); li = li.subList(1, li.size()); String clean = Joiner.on(' ').join( li.stream() .map(Errors::toTitleCase) .iterator()); try { map.put(f.getInt(null), clean); } catch (Throwable t) { t.printStackTrace(); } } } } mapping = map; }
/** * Creates a depth buffer texture attachment. * * @param width * - the width of the texture. * @param height * - the height of the texture. * @return The ID of the depth texture. */ private static int createDepthBufferAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0); return texture; }
private int createTextureAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, texture, 0); return texture; }
private int createDepthTextureAttachment(int width, int height) { int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0); return texture; }
public ProgramParticleBillboarded() { super(); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/billboards.gs"), GL32.GL_GEOMETRY_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/billboards.vs"), GL20.GL_VERTEX_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/billboards.fs"), GL20.GL_FRAGMENT_SHADER)); this.link(); }
public ProgramTexturedQuad() { super(); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.gs"), GL32.GL_GEOMETRY_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
public ProgramColoredQuad() { super(); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.gs"), GL32.GL_GEOMETRY_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
public GLProgramPostProcessing(String filepath) { super(); if (vertex_shader == null) { vertex_shader = GLH.glhLoadShader(R.getResPath("shaders/post_process/post_processing.vs"), GL20.GL_VERTEX_SHADER); geometry_shader = GLH.glhLoadShader(R.getResPath("shaders/post_process/post_processing.gs"), GL32.GL_GEOMETRY_SHADER); } this.addShader(GLH.glhLoadShader(filepath, GL20.GL_FRAGMENT_SHADER)); this.addShader(geometry_shader); this.addShader(vertex_shader); this.link(); }
public static void loadCapNames() { loadCapNames(GL11.class); loadCapNames(GL20.class); loadCapNames(GL30.class); loadCapNames(GL32.class); }
private void createFramebuffer() { framebufferID = GL30.glGenFramebuffers(); textureID = GL11.glGenTextures(); int currentFramebuffer = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); int currentTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebufferID); // Set our texture up, empty. GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, renderTextureSize, renderTextureSize, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null); // Restore old texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTexture); // Create depth buffer depthbufferID = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthbufferID); GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, renderTextureSize, renderTextureSize); // Bind depth buffer to the framebuffer GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthbufferID); // Bind our texture to the framebuffer GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureID, 0); // Revert to default framebuffer GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, currentFramebuffer); }
public static int glClientWaitSync(long sync, int flags, long timeout) throws GLException { int ret = GL32.glClientWaitSync(sync, flags, timeout); RenderHelper.checkForGLError(); return ret; }
public static long glFenceSync(int condition, int flags) throws GLException { long ret = GL32.glFenceSync(condition, flags); RenderHelper.checkForGLError(); return ret; }
public static long glGetBufferParameteri64(int target, int pname) throws GLException { long ret = GL32.glGetBufferParameteri64(target, pname); RenderHelper.checkForGLError(); return ret; }