summaryrefslogtreecommitdiffstats
path: root/src/demos/dualDepthPeeling/GLHelper.java
blob: acfd9ae0274f3b6d20f9934b10732e739c220edf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package demos.dualDepthPeeling;


// Translated from C++ Version see below:
//
// GLSLProgramObject.h - Wrapper for GLSL program objects
//
// Author: Louis Bavoil
// Email: sdkfeedback@nvidia.com
//
// Copyright (c) NVIDIA Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
import com.jogamp.opengl.GL2;

public class GLHelper
{
	public static void setTextureUnit(GL2 gl, int progId, String texname, int texunit)
	{
		int[] params = new int[]{0};
		gl.glGetProgramiv( progId, GL2.GL_LINK_STATUS, params, 0);
		if ( params[0] != 1 ) {
			System.err.println( "Error: setTextureUnit needs program to be linked.");
		}
		int id = gl.glGetUniformLocation(progId, texname );
		if (id == -1) {
			System.err.println( "Warning: Invalid texture " + texname );
			return;
		}
		gl.glUniform1i(id, texunit);
	}


	public static void bindTexture(GL2 gl, int target, int texid, int texUnit)
	{
		gl.glActiveTexture(GL2.GL_TEXTURE0 + texUnit);
		gl.glBindTexture(target, texid);
		gl.glActiveTexture(GL2.GL_TEXTURE0);
	}


	public static void bindTexture2D(GL2 gl, int texid, int texUnit) {
		bindTexture(gl, GL2.GL_TEXTURE_2D, texid, texUnit);
	}

	public static void bindTexture3D(GL2 gl, int texid, int texUnit) {
		bindTexture(gl, GL2.GL_TEXTURE_3D, texid, texUnit);
	}

	// g_shaderDualPeel.bindTextureRECT(gl, g_shaderState, s_DepthBlenderTex, g_dualDepthTexId[prevId]);
	public static void bindTextureRECT(GL2 gl, int texid, int texUnit) {
		bindTexture(gl, GL2.GL_TEXTURE_RECTANGLE_ARB, texid, texUnit);
	}
};