Java Code Examples for org.lwjgl.opengl.GL20#glUniform1i()

The following examples show how to use org.lwjgl.opengl.GL20#glUniform1i() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutlineShader.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateUniforms() {
    GL20.glUniform1i(getUniform("texture"), 0);
    GL20.glUniform2f(getUniform("texelSize"), 1F / mc.displayWidth * (radius * quality), 1F / mc.displayHeight * (radius * quality));
    GL20.glUniform4f(getUniform("color"), red, green, blue, alpha);
    GL20.glUniform1f(getUniform("radius"), radius);
}
 
Example 2
Source File: GlowShader.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateUniforms() {
    GL20.glUniform1i(getUniform("texture"), 0);
    GL20.glUniform2f(getUniform("texelSize"), 1F / mc.displayWidth * (radius * quality), 1F / mc.displayHeight * (radius * quality));
    GL20.glUniform3f(getUniform("color"), red, green, blue);
    GL20.glUniform1f(getUniform("divider"), 140F);
    GL20.glUniform1f(getUniform("radius"), radius);
    GL20.glUniform1f(getUniform("maxSample"), 10F);
}
 
Example 3
Source File: UniformSampler.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public void loadTexUnit(int texUnit) {
	if (!used || currentValue != texUnit) {
		GL20.glUniform1i(super.getLocation(), texUnit);
		used = true;
		currentValue = texUnit;
	}
}
 
Example 4
Source File: UniformSampler.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadTexUnit(int texUnit) {
	if (!used || currentValue != texUnit) {
		GL20.glUniform1i(super.getLocation(), texUnit);
		used = true;
		currentValue = texUnit;
	}
}
 
Example 5
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst) {
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	}
	final int mirrors = OPTION_DANCE_MIRROR.state ? this.mirrors : 1;
	for (int i = 0; i < mirrors; i++) {
		if (pointsToRender == null) {
			renderCurve(from, to, i);
		} else {
			renderCurve(i);
		}
		//from++;
		//to++;
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 6
Source File: ShaderUniformCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void apply() {
    if (dirty) {
        switch (type.getCarrier()) {
            //@formatter:off
            case INT:
                switch (type.getSize()) {
                    case 1: GL20.glUniform1i(getLocation(), cache[0]); break;
                    case 2: GL20.glUniform2i(getLocation(), cache[0], cache[1]); break;
                    case 3: GL20.glUniform3i(getLocation(), cache[0], cache[1], cache[2]); break;
                    case 4: GL20.glUniform4i(getLocation(), cache[0], cache[1], cache[2], cache[3]); break;
                    default: throw new IllegalStateException("Invalid size for Int type." + type.getSize());
                }
                break;
            case U_INT:
                switch (type.getSize()) {
                    case 1: GL30.glUniform1ui(getLocation(), cache[0]); break;
                    case 2: GL30.glUniform2ui(getLocation(), cache[0], cache[1]); break;
                    case 3: GL30.glUniform3ui(getLocation(), cache[0], cache[1], cache[2]); break;
                    case 4: GL30.glUniform4ui(getLocation(), cache[0], cache[1], cache[2], cache[3]); break;
                    default: throw new IllegalStateException("Invalid size for Int type." + type.getSize());
                }
                break;
            default: throw new IllegalStateException("Invalid type for IntUniformEntry: " + type.getCarrier());
            //@formatter:on
        }
        dirty = false;
    }
}
 
Example 7
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 8
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int to) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform4f(staticState.colLoc, color.r, color.g, color.b, color.a);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);

	float lastSegmentX = to == 0 ? curve[1].x - curve[0].x : curve[to].x - curve[to-1].x;
	float lastSegmentY = to == 0 ? curve[1].y - curve[0].y : curve[to].y - curve[to-1].y;
	float lastSegmentInvLen = 1.f/(float)Math.hypot(lastSegmentX, lastSegmentY);
	GL20.glUniform4f(staticState.endPointLoc, curve[to].x, curve[to].y, lastSegmentX * lastSegmentInvLen, lastSegmentY * lastSegmentInvLen);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);

	GL11.glColorMask(false,false,false,false);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glColorMask(true,true,true,true);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glDepthFunc(GL11.GL_EQUAL);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glDepthFunc(GL11.GL_LESS);

	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 9
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
void init() {
	uniform_names = new String[] {"projection", "globalTransform", "transform", "texHandle", "color", "height", "uni_info"};
	shaders = new ArrayList<>();

	prog_background = new ShaderProgram("background");
	prog_unified = new ShaderProgram("tex-unified");
	prog_color = new ShaderProgram("color");
	prog_tex = new ShaderProgram("tex");

	for(ShaderProgram shader : shaders) {
		useProgram(shader);
		if(shader.ufs[TEX] != -1) GL20.glUniform1i(shader.ufs[TEX], 0);
	}
}
 
Example 10
Source File: GTexture.java    From ldparteditor with MIT License 4 votes vote down vote up
public void bind(boolean drawSolidMaterials, boolean normalSwitch, boolean lightOn, OpenGLRenderer20 renderer, int useCubeMap) {

        int ID = -1;
        int ID_glossmap = -1;
        int ID_cubemap = -1;
        int ID_cubemap_matte = -1;
        int ID_cubemap_metal = -1;
        boolean disposed = true;

        if (OpenGlDisposed.containsKey(renderer)) {
            disposed = OpenGlDisposed.get(renderer);
            ID = OpenGlID.get(renderer);
            ID_glossmap = OpenGlID_glossmap.get(renderer);
            ID_cubemap = OpenGlID_cubemap.get(renderer);
            ID_cubemap_matte = OpenGlID_cubemapMatte.get(renderer);
            ID_cubemap_metal = OpenGlID_cubemapMetal.get(renderer);
        } else {
            OpenGlDisposed.put(renderer, true);
        }

        if (disposed) {

            DatFile df = renderer.getC3D().getLockableDatFileReference();

            ID = loadPNGTexture(texture, GL13.GL_TEXTURE0, df);
            if (glossy)
                ID_glossmap = loadPNGTexture(glossmap, GL13.GL_TEXTURE1, df);
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    ID_cubemap = loadPNGTexture("cmap.png", GL13.GL_TEXTURE2, df ); //$NON-NLS-1$
                    break;
                case 2:
                    ID_cubemap_matte = loadPNGTexture("matte_metal.png", GL13.GL_TEXTURE3, df); //$NON-NLS-1$
                    break;
                case 3:
                    ID_cubemap_metal = loadPNGTexture("metal.png", GL13.GL_TEXTURE4, df); //$NON-NLS-1$
                    break;
                }
            }
            OpenGlDisposed.put(renderer, false);
            renderer.registerTexture(this);
            OpenGlID.put(renderer, ID);
            OpenGlID_glossmap.put(renderer, ID_glossmap);
            OpenGlID_cubemap.put(renderer, ID_cubemap);
            OpenGlID_cubemapMatte.put(renderer, ID_cubemap_matte);
            OpenGlID_cubemapMetal.put(renderer, ID_cubemap_metal);
        } else if (ID != -1) {
            accessTime = System.currentTimeMillis();
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID);
            GL20.glUniform1f(renderer.getAlphaSwitchLoc(), drawSolidMaterials ? 1f : 0f); // Draw transparent
            GL20.glUniform1f(renderer.getNormalSwitchLoc(), normalSwitch ? 1f : 0f); // Draw transparent
            GL20.glUniform1i(renderer.getBaseImageLoc(), 0); // Texture unit 0 is for base images.
            GL20.glUniform1f(renderer.getNoTextureSwitch(), 0f);
            GL20.glUniform1f(renderer.getNoLightSwitch(), lightOn ? 0f : 1f);
            GL20.glUniform1f(renderer.getCubeMapSwitch(), useCubeMap);

            if (glossy) {
                GL13.glActiveTexture(GL13.GL_TEXTURE0 + 2);
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_glossmap);
                GL20.glUniform1i(renderer.getGlossMapLoc(), 2); // Texture unit 2 is for gloss maps.
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 0f);
            } else {
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 1f);
            }
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 4);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap);
                    GL20.glUniform1i(renderer.getCubeMapLoc(), 4); // Texture unit 4 is for cube maps.
                    break;
                case 2:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 8);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_matte);
                    GL20.glUniform1i(renderer.getCubeMapMatteLoc(), 8); // Texture unit 8 is for cube maps.
                    break;
                case 3:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 16);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_metal);
                    GL20.glUniform1i(renderer.getCubeMapMetalLoc(), 16); // Texture unit 16 is for cube maps.
                    break;
                }
            }
        }
    }
 
Example 11
Source File: GTexture.java    From ldparteditor with MIT License 4 votes vote down vote up
public void bindGL33(OpenGLRenderer renderer, GLShader shader) {

        int ID = -1;
        int ID_glossmap = -1;
        int ID_cubemap = -1;
        int ID_cubemap_matte = -1;
        int ID_cubemap_metal = -1;
        boolean disposed = true;

        if (OpenGlDisposed.containsKey(renderer)) {
            disposed = OpenGlDisposed.get(renderer);
            ID = OpenGlID.get(renderer);
            ID_glossmap = OpenGlID_glossmap.get(renderer);
            ID_cubemap = OpenGlID_cubemap.get(renderer);
            ID_cubemap_matte = OpenGlID_cubemapMatte.get(renderer);
            ID_cubemap_metal = OpenGlID_cubemapMetal.get(renderer);
        } else {
            OpenGlDisposed.put(renderer, true);
        }

        if (disposed) {

            DatFile df = renderer.getC3D().getLockableDatFileReference();

            ID = loadPNGTexture(texture, GL13.GL_TEXTURE0, df);
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    ID_cubemap = loadPNGTexture("cmap.png", GL13.GL_TEXTURE2, df ); //$NON-NLS-1$
                    break;
                case 2:
                    ID_cubemap_matte = loadPNGTexture("matte_metal.png", GL13.GL_TEXTURE3, df); //$NON-NLS-1$
                    break;
                case 3:
                    ID_cubemap_metal = loadPNGTexture("metal.png", GL13.GL_TEXTURE4, df); //$NON-NLS-1$
                    break;
                }
            }
            OpenGlDisposed.put(renderer, false);
            renderer.registerTexture(this);
            OpenGlID.put(renderer, ID);
            OpenGlID_glossmap.put(renderer, ID_glossmap);
            OpenGlID_cubemap.put(renderer, ID_cubemap);
            OpenGlID_cubemapMatte.put(renderer, ID_cubemap_matte);
            OpenGlID_cubemapMetal.put(renderer, ID_cubemap_metal);
        } else if (ID != -1) {
            accessTime = System.currentTimeMillis();
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID);
            GL20.glUniform1i(shader.getUniformLocation("ldpePngSampler"), 0); // Texture unit 0 is for base images. //$NON-NLS-1$

            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 4);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMap"), 4); // Texture unit 4 is for cube maps. //$NON-NLS-1$
                    break;
                case 2:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 8);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_matte);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMapMatte"), 8); // Texture unit 8 is for cube maps. //$NON-NLS-1$
                    break;
                case 3:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 16);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_metal);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMapMetal"), 16); // Texture unit 16 is for cube maps. //$NON-NLS-1$
                    break;
                }
            }
        }
    }
 
Example 12
Source File: ShaderHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void glUniform1i(int loc, int val) {
	GL20.glUniform1i(loc, val);
}