com.jogamp.opengl.GL2GL3 Java Examples

The following examples show how to use com.jogamp.opengl.GL2GL3. 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: Renderer.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
/**
 * Common code to setup basic openGL state, including depth test, blending etc.
 * @param gl
 */
private void initSurfaceState(GL2GL3 gl) {
	// Some of this is probably redundant, but here goes
	gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	gl.glEnable(GL.GL_DEPTH_TEST);
	gl.glClearDepth(1.0);

	gl.glDepthFunc(GL2GL3.GL_LEQUAL);

	gl.glEnable(GL2GL3.GL_CULL_FACE);
	gl.glCullFace(GL2GL3.GL_BACK);

	gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX);
	gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ONE);

}
 
Example #2
Source File: Renderer.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void freeOffscreenTargetImp(OffscreenTarget target) {
	if (!target.isLoaded()) {
		return; // Nothing to free
	}
	sharedContext.makeCurrent();
	GL2GL3 gl = sharedContext.getGL().getGL2GL3(); // Just to clean up the code below

	int[] temp = new int[2];

	temp[0] = target.getDrawFBO();
	temp[1] = target.getBlitFBO();
	gl.glDeleteFramebuffers(2, temp, 0);

	temp[0] = target.getDrawTex();
	temp[1] = target.getBlitTex();
	gl.glDeleteTextures(2, temp, 0);

	temp[0] = target.getDepthBuffer();
	gl.glDeleteRenderbuffers(1, temp, 0);

	target.free();

	sharedContext.release();
}
 
Example #3
Source File: Polygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
@Override
public void renderTransparent(int contextID, Renderer renderer, Camera cam, Ray pickRay) {
	GL2GL3 gl = renderer.getGL();
	if (_points.size() < 3) {
		return; // Can't actually draw this polygon
	}

	float[] renderColour = colour;
	if (pickRay != null && getCollisionDist(pickRay, false) > 0)
		renderColour = hoverColour;

	if (renderColour[3] == 1.0) {
		// This is opaque
		return;
	}

	renderImp(contextID, renderer, cam, pickRay, gl, renderColour);
}
 
Example #4
Source File: Polygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
public static void init(Renderer r, GL2GL3 gl) {
	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	_vertBuffer = is[0];

	Shader s = r.getShader(ShaderHandle.DEBUG);
	_progHandle = s.getProgramHandle();
	gl.glUseProgram(_progHandle);

	_modelViewMatVar = gl.glGetUniformLocation(_progHandle, "modelViewMat");
	_projMatVar = gl.glGetUniformLocation(_progHandle, "projMat");
	_colorVar = gl.glGetUniformLocation(_progHandle, "color");

	_cVar = gl.glGetUniformLocation(_progHandle, "C");
	_fcVar = gl.glGetUniformLocation(_progHandle, "FC");

	_posVar = gl.glGetAttribLocation(_progHandle, "position");

	_hasInitialized = true;
}
 
Example #5
Source File: Renderer.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
@Override
public void dispose(GLAutoDrawable drawable) {
	synchronized (rendererLock) {

		GL2GL3 gl = drawable.getGL().getGL2GL3();

		ArrayList<Integer> vaoArray = window.getVAOs();

		int[] vaos = new int[vaoArray.size()];
		int index = 0;
		for (int vao : vaoArray) {
			vaos[index++] = vao;
		}
		if (vaos.length > 0) {
			gl.glDeleteVertexArrays(vaos.length, vaos, 0);
		}
	}
}
 
Example #6
Source File: Renderer.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
@Override
public void init(GLAutoDrawable drawable) {
	synchronized (rendererLock) {
		// Per window initialization
		if (USE_DEBUG_GL) {
			drawable.setGL(new DebugGL4bc((GL4bc)drawable.getGL().getGL2GL3()));
		}

		GL2GL3 gl = drawable.getGL().getGL2GL3();

		initSurfaceState(gl);

		gl.glEnable(GL.GL_MULTISAMPLE);


	}
}
 
Example #7
Source File: Polygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void renderOutline(GL2GL3 gl) {
	// The vertex list is just the closed loop of points
	if (lineWidth == 0) {
		return;
	}

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _vertBuffer);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW);

	gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	if (!gl.isGLcore())
		gl.glLineWidth((float)lineWidth);
	else
		gl.glLineWidth(1.0f);

	gl.glDrawArrays(GL2GL3.GL_LINE_LOOP, 0, _points.size());

	gl.glLineWidth(1.0f);

}
 
Example #8
Source File: Shader.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private String getShaderLog(int shaderHandle, GL2GL3 gl) {
	int[] is = new int[1];
	gl.glGetShaderiv(shaderHandle, GL2GL3.GL_INFO_LOG_LENGTH, is, 0);
	int logLength = is[0];
	if (logLength == 0) {
		return "";
	}

	byte[] bs = new byte[logLength];

	gl.glGetShaderInfoLog(shaderHandle, logLength, is, 0,  bs, 0);

	StringBuilder sb = new StringBuilder();

	for(int i = 0; i < is[0]; ++i) {
		sb.append((char)bs[i]);
	}

	return sb.toString();
}
 
Example #9
Source File: Polygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void renderFill(GL2GL3 gl) {
	if (_tessPoints == null) {
		_tessPoints = SimpleTess.tesselate(_points);

		fb = FloatBuffer.allocate(3 * _tessPoints.size());
		for (Vec3d vert : _tessPoints) {
			RenderUtils.putPointXYZ(fb, vert);
		}
		fb.flip();
	}

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _vertBuffer);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW);

	gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	gl.glDisable(GL2GL3.GL_CULL_FACE);
	gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, _tessPoints.size());
	gl.glEnable(GL2GL3.GL_CULL_FACE);

}
 
Example #10
Source File: TextureView.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void updateTexCoordBuffer(Renderer renderer) {
	GL2GL3 gl = renderer.getGL();
	int texCoordBuffSize = _texCoords.size()*2*4;
	_texCoordHandle = renderer.getTexMemManager().allocateBuffer(texCoordBuffSize, gl);
	int buffID = _texCoordHandle.bind();

	FloatBuffer texData = FloatBuffer.allocate(_texCoords.size()*2);

	for (Vec2d v : _texCoords) {
		texData.put((float)v.x); texData.put((float)v.y);
	}
	texData.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, buffID);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, texCoordBuffSize, texData, GL2GL3.GL_STATIC_DRAW);

	int texCoordVar = gl.glGetAttribLocation(progHandle, "texCoord");
	gl.glEnableVertexAttribArray(texCoordVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, buffID);
	gl.glVertexAttribPointer(texCoordVar, 2, GL2GL3.GL_FLOAT, false, 0, 0);

}
 
Example #11
Source File: OverlayPolygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private static void initStaticData(Renderer r) {
	GL2GL3 gl = r.getGL();

	// Initialize the shader variables
	progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	glBuff = is[0];

	hasTexVar = gl.glGetUniformLocation(progHandle, "useTex");
	sizeVar = gl.glGetUniformLocation(progHandle, "size");
	offsetVar = gl.glGetUniformLocation(progHandle, "offset");
	colorVar = gl.glGetUniformLocation(progHandle, "color");

	posVar = gl.glGetAttribLocation(progHandle, "position");
	staticInit = true;
}
 
Example #12
Source File: MeshProto.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void loadGPUMaterial(GL2GL3 gl, Renderer renderer, MeshData.Material dataMat) {

	Material mat = new Material();
	mat.shaderID = dataMat.getShaderID();
	mat._transType = dataMat.transType;
	mat._transColour = dataMat.transColour;

	mat._textureIndex = dataMat.texIndex;
	if (dataMat.diffuseColor != null) {
		mat._diffuseColor = new Color4d(dataMat.diffuseColor);
	}

	mat._ambientColor = new Color4d(dataMat.ambientColor);
	mat._specColor = new Color4d(dataMat.specColor);
	mat._shininess = dataMat.shininess;

	_materials.add(mat);
}
 
Example #13
Source File: OverlayLine.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private static void initStaticData(Renderer r) {
	GL2GL3 gl = r.getGL();

	// Initialize the shader variables
	progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	lineGLBuff = is[0];

	hasTexVar = gl.glGetUniformLocation(progHandle, "useTex");
	sizeVar = gl.glGetUniformLocation(progHandle, "size");
	offsetVar = gl.glGetUniformLocation(progHandle, "offset");
	colorVar = gl.glGetUniformLocation(progHandle, "color");

	posVar = gl.glGetAttribLocation(progHandle, "position");
	staticInit = true;
}
 
Example #14
Source File: DwGLTexture.java    From PixelFlow with MIT License 5 votes vote down vote up
public void getData_GL2GL3(Buffer buffer){
  int data_len = w * h * num_channel;
  
  if(buffer.remaining() < data_len){
    System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len);
    return;
  }

  GL2GL3 gl23 = gl.getGL2GL3();
  gl23.glBindTexture(target, HANDLE[0]);
  gl23.glGetTexImage(target, 0, format, type, buffer);
  gl23.glBindTexture(target, 0);
  
  DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3");
}
 
Example #15
Source File: Renderer.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public int generateVAO(int contextID, GL2GL3 gl) {
	assert(Thread.currentThread() == renderThread);

	int[] vaos = new int[1];
	gl.glGenVertexArrays(1, vaos, 0);
	int vao = vaos[0];

	synchronized(openWindows) {
		RenderWindow wind = openWindows.get(contextID);
		if (wind != null) {
			wind.addVAO(vao);
		}
	}
	return vao;
}
 
Example #16
Source File: Renderer.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void createCoreShader(ShaderHandle sh, String vert, String frag, GL2GL3 gl, String version) {
	String vertsrc = readSource(vert).replaceAll("@VERSION@", version);
	String fragsrc = readSource(frag).replaceAll("@VERSION@", version);

	Shader s = new Shader(vertsrc, fragsrc, gl);
	if (s.isGood()) {
		shaders.put(sh, s);
		return;
	}

	String failure = s.getFailureLog();
	throw new RenderException("Shader failed: " + sh.toString() + " " + failure);
}
 
Example #17
Source File: Renderer.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void createShader(ShaderHandle sh, String vert, String frag, GL2GL3 gl) {
	String vertsrc = readSource(vert);
	String fragsrc = readSource(frag);

	Shader s = new Shader(vertsrc, fragsrc, gl);
	if (s.isGood()) {
		shaders.put(sh, s);
		return;
	}

	String failure = s.getFailureLog();
	throw new RenderException("Shader failed: " + sh.toString() + " " + failure);
}
 
Example #18
Source File: Renderer.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void initSharedContext() {
	assert (Thread.currentThread() == renderThread);
	assert (drawContext == null);

	int res = sharedContext.makeCurrent();
	assert (res == GLContext.CONTEXT_CURRENT);

	if (USE_DEBUG_GL) {
		sharedContext.setGL(new DebugGL4bc((GL4bc)sharedContext.getGL().getGL2GL3()));
	}

	LogBox.formatRenderLog("Found OpenGL version: %s", sharedContext.getGLVersion());
	LogBox.formatRenderLog("Found GLSL: %s", sharedContext.getGLSLVersionString());
	VersionNumber vn = sharedContext.getGLVersionNumber();
	boolean isCore = sharedContext.isGLCoreProfile();
	LogBox.formatRenderLog("OpenGL Major: %d Minor: %d IsCore:%s", vn.getMajor(), vn.getMinor(), isCore);
	if (vn.getMajor() < 2) {
		throw new RenderException("OpenGL version is too low. OpenGL >= 2.1 is required.");
	}
	GL2GL3 gl = sharedContext.getGL().getGL2GL3();
	if (!isCore && (!gl3Supported || safeGraphics))
		initShaders(gl);
	else
		initCoreShaders(gl, sharedContext.getGLSLVersionString());

	// Sub system specific initializations
	DebugUtils.init(this, gl);
	Polygon.init(this, gl);
	MeshProto.init(this, gl);
	texCache.init(gl);

	// Load the bad mesh proto
	badData = MeshDataCache.getBadMesh();
	badProto = new MeshProto(badData, safeGraphics, false);
	badProto.loadGPUAssets(gl, this);

	skybox = new Skybox();

	sharedContext.release();
}
 
Example #19
Source File: OpenGL.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void drawCachedGeometry(final GamaGeometryFile file, final Color border) {
	if (file == null) { return; }
	final Integer index = geometryCache.get(file);
	if (index != null) {
		drawList(index);
	}
	if (border != null && !isWireframe() && index != null) {
		final Color old = swapCurrentColor(border);
		getGL().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
		drawList(index);
		setCurrentColor(old);
		getGL().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
	}
}
 
Example #20
Source File: TextureView.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void setupVAO(int contextID, Renderer renderer) {
	GL2GL3 gl = renderer.getGL();

	int vao = renderer.generateVAO(contextID, gl);
	VAOMap.put(contextID, vao);

	gl.glBindVertexArray(vao);


	// Position
	int posVar = gl.glGetAttribLocation(progHandle, "position");
	gl.glEnableVertexAttribArray(posVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff);
	gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0);

	// Normals
	int normalVar = gl.glGetAttribLocation(progHandle, "normal");
	gl.glEnableVertexAttribArray(normalVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, normalBuff);
	gl.glVertexAttribPointer(normalVar, 3, GL2GL3.GL_FLOAT, false, 0, 0);

	// TexCoords
	if (_texCoords == null) {
		// Use default buffer if custom coords have not been included
		int texCoordVar = gl.glGetAttribLocation(progHandle, "texCoord");
		gl.glEnableVertexAttribArray(texCoordVar);

		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff);
		gl.glVertexAttribPointer(texCoordVar, 2, GL2GL3.GL_FLOAT, false, 0, 0);

		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);
	}
	gl.glBindVertexArray(0);

}
 
Example #21
Source File: Skybox.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public static void loadGPUAssets(Renderer r) {

		GL2GL3 gl = r.getGL();

		int[] buffs = new int[1];
		gl.glGenBuffers(1, buffs, 0);
		vertBuff = buffs[0];

		progHandle = r.getShader(Renderer.ShaderHandle.SKYBOX).getProgramHandle();

		projMatVar = gl.glGetUniformLocation(progHandle, "projMat");
		invViewMatVar = gl.glGetUniformLocation(progHandle, "invViewMat");
		texVar = gl.glGetUniformLocation(progHandle, "tex");

		FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates
		verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f);

		verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f);
		verts.put(-0.5f); verts.put( 0.5f); verts.put(-0.5f);

		verts.flip();
		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff);
		gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW);

		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

		isLoaded = true;
	}
 
Example #22
Source File: RenderUtils.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
static void nioBuffToGL(GL2GL3 gl, Renderer r, int bufferHandle, int itemSize, Buffer buff) {

	buff.flip();
	int size = buff.limit() * itemSize;
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, bufferHandle);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, size, buff, GL2GL3.GL_STATIC_DRAW);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);
	r.usingVRAM(size);

}
 
Example #23
Source File: Shader.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
/**
 * Free the OpenGL resources used by this shader, can not be used again after
 */
public void clearProgram(GL2GL3 gl) {
	if (_status != ShaderStatus.GOOD) {
		return;
	}
	gl.glDeleteProgram(_progHandle);
}
 
Example #24
Source File: DwGLTexture3D.java    From PixelFlow with MIT License 5 votes vote down vote up
public void getData_GL2GL3(Buffer buffer){
  int data_len = w * h * num_channel;
  
  if(buffer.remaining() < data_len){
    System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len);
    return;
  }

  GL2GL3 gl23 = gl.getGL2GL3();
  gl23.glBindTexture(target, HANDLE[0]);
  gl23.glGetTexImage(target, 0, format, type, buffer);
  gl23.glBindTexture(target, 0);
  
  DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3");
}
 
Example #25
Source File: TexCache.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public void init(GL2GL3 gl) {
	LoadingEntry badLE = launchLoadImage(gl, BAD_TEXTURE, false, false);
	assert(badLE != null); // We should never fail to load the bad texture

	waitForTex(badLE);
	_loadingMap.remove(BAD_TEXTURE.toString());

	badTextureID = loadGLTexture(gl, badLE);
	assert(badTextureID != -1); // Hopefully OpenGL never naturally returns -1, but I don't think it should
}
 
Example #26
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void initUniforms(Renderer renderer, Mat4d modelViewMat, Mat4d projMat, Mat4d viewMat, Mat4d normalMat) {
	GL2GL3 gl = renderer.getGL();

	lightsDirScratch[0].mult4(viewMat, lightsDir[0]);
	lightsDirScratch[1].mult4(viewMat, lightsDir[1]);

	lightsDirFloats[0] = (float)lightsDirScratch[0].x;
	lightsDirFloats[1] = (float)lightsDirScratch[0].y;
	lightsDirFloats[2] = (float)lightsDirScratch[0].z;

	lightsDirFloats[3] = (float)lightsDirScratch[1].x;
	lightsDirFloats[4] = (float)lightsDirScratch[1].y;
	lightsDirFloats[5] = (float)lightsDirScratch[1].z;

	for (int i = 0; i < usedShaders.length; ++i) {
		int shaderID = usedShaders[i];
		ShaderInfo si = sInfos[shaderID];

		gl.glUseProgram(si.meshProgHandle);

		gl.glUniformMatrix4fv(si.modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0);
		gl.glUniformMatrix4fv(si.projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0);
		gl.glUniformMatrix4fv(si.normalMatVar, 1, false, RenderUtils.MarshalMat4d(normalMat), 0);

		gl.glUniform3fv(si.lightDirVar, 2, lightsDirFloats, 0);
		gl.glUniform1fv(si.lightIntVar, 2, lightsInt, 0);
		gl.glUniform1i(si.numLightsVar, numLights);

		gl.glUniform1f(si.cVar, Camera.C);
		gl.glUniform1f(si.fcVar, Camera.FC);

	}
}
 
Example #27
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void loadGPUTextures(GL2GL3 gl, Renderer renderer) {
	ArrayList<MeshData.Texture> textures = data.getTextures();

	assert(textures.size() <= MAX_SAMPLERS);

	for (MeshData.Texture tex: textures) {
		int texHandle = renderer.getTexCache().getTexID(gl, tex.texURI, tex.withAlpha, false, true);
		_textureHandles.add(texHandle);
	}

}
 
Example #28
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private static void initBSInfo(Renderer r, GL2GL3 gl) {
	BatchShaderInfo si = bsInfo;

	si.progHandle = r.getShader(ShaderHandle.MESH_BATCH).getProgramHandle();
	int ph = bsInfo.progHandle;

	gl.glUseProgram(ph);

	si.instSpaceMatVar = gl.glGetAttribLocation(ph, "instSpaceMat");
	si.instSpaceNorMatVar = gl.glGetAttribLocation(ph, "instSpaceNorMat");

	// Bind the shader variables
	si.modelViewMatVar = gl.glGetUniformLocation(ph, "modelViewMat");
	si.projMatVar = gl.glGetUniformLocation(ph, "projMat");
	si.normalMatVar = gl.glGetUniformLocation(ph, "normalMat");

	si.posVar = gl.glGetAttribLocation(ph, "position");
	si.norVar = gl.glGetAttribLocation(ph, "normal");
	si.texCoordVar = gl.glGetAttribLocation(ph, "texCoord");

	si.diffTexVar = gl.glGetUniformLocation(ph, "diffTexs");

	si.diffuseColorVar = gl.glGetAttribLocation(ph, "diffuseColorV");
	si.diffTexIndexVar = gl.glGetAttribLocation(ph, "diffTexIndexV");
	si.ambientColorVar = gl.glGetAttribLocation(ph, "ambientColorV");
	si.specColorVar = gl.glGetAttribLocation(ph, "specColorV");
	si.shininessVar = gl.glGetAttribLocation(ph, "shininessV");

	si.lightDirVar = gl.glGetUniformLocation(ph, "lightDir");
	si.lightIntVar = gl.glGetUniformLocation(ph, "lightIntensity");
	si.numLightsVar = gl.glGetUniformLocation(ph, "numLights");

	si.cVar = gl.glGetUniformLocation(ph, "C");
	si.fcVar = gl.glGetUniformLocation(ph, "FC");

}
 
Example #29
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void loadGPUSubLine(GL2GL3 gl, Renderer renderer, MeshData.SubLineData data) {

	Shader s = renderer.getShader(Renderer.ShaderHandle.DEBUG);

	assert (s.isGood());

	SubLine sub = new SubLine();
	sub._progHandle = s.getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	sub._vertexBuffer = is[0];

	sub._numVerts = data.verts.size();

	sub._hull = data.hull;

	// Init vertices
	FloatBuffer fb = FloatBuffer.allocate(data.verts.size() * 3); //
	for (Vec3d v : data.verts) {
		RenderUtils.putPointXYZ(fb, v);
	}
	fb.flip();

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, sub._vertexBuffer);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, sub._numVerts * 3 * 4, fb, GL2GL3.GL_STATIC_DRAW);

	// Bind the shader variables
	sub._modelViewMatVar = gl.glGetUniformLocation(sub._progHandle, "modelViewMat");
	sub._projMatVar = gl.glGetUniformLocation(sub._progHandle, "projMat");

	sub._diffuseColor = new Color4d(data.diffuseColor);
	sub._colorVar = gl.glGetUniformLocation(sub._progHandle, "color");

	sub._cVar = gl.glGetUniformLocation(sub._progHandle, "C");
	sub._fcVar = gl.glGetUniformLocation(sub._progHandle, "FC");

	_subLines.add(sub);
}
 
Example #30
Source File: GraphicsMemManager.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public BufferHandle allocateBuffer(int size, GL2GL3 gl) {
	int[] i = new int[1];
	gl.glGenBuffers(1, i, 0);
	int glBufferID = i[0];

	renderer.usingVRAM(size);

	BufferHandle h = new BufferHandle(glBufferID, size, this);
	allocatedBuffers.add(h);
	return h;

}