/** * The constructor, to be used in the initialise method of a node. * * Sample use: * addDesiredStateChange(new SetInputTexture(GL_TEXTURE_2D, 0, "engine:water", "engine:prog.chunk", "textureWater")); * * @param textureType an opengl constant, can be GL_TEXTURE_2D, GL_TEXTURE_3D and any other texture type listed in https://www.khronos.org/opengl/wiki/Texture#Theory * @param textureSlot a 0-based integer. Notice that textureUnit = GL_TEXTURE0 + textureSlot. See OpenGL spects for maximum allowed values. * @param textureUrn a String identifying a loaded texture, whose id will then be used by this StateChange. * @param materialUrn a ResourceURN object uniquely identifying a Material asset. * @param materialParameter a String representing the variable within the shader holding the texture. */ protected SetInputTexture(int textureType, int textureSlot, String textureUrn, ResourceUrn materialUrn, String materialParameter) { this.textureType = textureType; this.textureSlot = textureSlot; this.materialUrn = materialUrn; this.materialParameter = materialParameter; this.material = getMaterial(materialUrn); Optional<Texture> optionalTexture = Assets.getTexture(textureUrn); if (optionalTexture.isPresent()) { this.textureId = optionalTexture.get().getId(); } else { this.textureId = 0; // TODO: Maybe throw some exception or use Logger.error()? } // TODO: take advantage of Texture.subscribeToDisposal(Runnable) to reobtain the asset if necessary }
@Override public void bindTexture(int slot, Texture texture) { if (activeMaterial != null && !activeMaterial.isDisposed()) { GL13.glActiveTexture(GL13.GL_TEXTURE0 + slot); // TODO: Need to be cubemap aware, only need to clear bind when switching from cubemap to 2D and vice versa, // TODO: Don't bind if already bound to the same GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); GL13.glActiveTexture(GL13.GL_TEXTURE0); } }
public LwjglFrameBufferObject(ResourceUrn urn, BaseVector2i size) { this.size = ImmutableVector2i.createOrUse(size); IntBuffer fboId = BufferUtils.createIntBuffer(1); GL30.glGenFramebuffers(fboId); frame = fboId.get(0); Texture texture = generateTexture(urn); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frame); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texture.getId(), 0); int result = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); if (result != GL30.GL_FRAMEBUFFER_COMPLETE) { throw new IllegalStateException("Something went wrong with framebuffer! " + result); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
public void beginRenderOverlay() { if (effectsTexture == null || !effectsTexture.isLoaded()) { return; } defaultTextured.activateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT); defaultTextured.enable(); glBindTexture(GL11.GL_TEXTURE_2D, effectsTexture.getId()); glEnable(GL11.GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
if (particleSystem.particleData.texture != null) { GL13.glActiveTexture(GL13.GL_TEXTURE0); glBindTexture(GL11.GL_TEXTURE_2D, particleSystem.particleData.texture.getId());
public AmbientOcclusionNode(String nodeUri, Context context) { super(nodeUri, context); activeCamera = worldRenderer.getActiveCamera(); RenderingConfig renderingConfig = context.get(Config.class).getRendering(); renderingConfig.subscribe(RenderingConfig.SSAO, this); requiresCondition(renderingConfig::isSsao); addDesiredStateChange(new EnableMaterial(SSAO_MATERIAL_URN)); ssaoMaterial = getMaterial(SSAO_MATERIAL_URN); DisplayResolutionDependentFBOs displayResolutionDependentFBOs = context.get(DisplayResolutionDependentFBOs.class); ssaoFbo = requiresFBO(new FBOConfig(SSAO_FBO_URI, FULL_SCALE, FBO.Type.DEFAULT), displayResolutionDependentFBOs); addDesiredStateChange(new BindFbo(ssaoFbo)); addDesiredStateChange(new SetViewportToSizeOf(ssaoFbo)); displayResolutionDependentFBOs.subscribe(POST_FBO_REGENERATION, this); retrieveFboDimensions(); // TODO: check for input textures brought in by the material FBO lastUpdatedGBuffer = displayResolutionDependentFBOs.getGBufferPair().getLastUpdatedFbo(); int texId = 0; addDesiredStateChange(new SetInputTextureFromFbo(texId++, lastUpdatedGBuffer, DepthStencilTexture, displayResolutionDependentFBOs, SSAO_MATERIAL_URN, "texDepth")); addDesiredStateChange(new SetInputTextureFromFbo(texId++, lastUpdatedGBuffer, NormalsTexture, displayResolutionDependentFBOs, SSAO_MATERIAL_URN, "texNormals")); addDesiredStateChange(new SetInputTexture2D(texId, generateNoiseTexture().getId(), SSAO_MATERIAL_URN, "texNoise")); if (ssaoSamples == null) { createSamplesBuffer(); } }