Java Code Examples for com.jogamp.opengl.GL2GL3#glUniform1fv()

The following examples show how to use com.jogamp.opengl.GL2GL3#glUniform1fv() . 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: 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 2
Source File: TextureView.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private void renderImp(int contextID, Renderer renderer, Camera cam, Ray pickRay) {

		if (!staticInit) {
			initStaticBuffers(renderer);
		}

		GL2GL3 gl = renderer.getGL();

		int textureID = _texLoader.getTexID(renderer);

		if (textureID == TexCache.LOADING_TEX_ID) {
			return; // This texture is not ready yet
		}

		if (!VAOMap.containsKey(contextID)) {
			setupVAO(contextID, renderer);
		}

		int vao = VAOMap.get(contextID);
		gl.glBindVertexArray(vao);

		if (	_texCoords != null &&
				(_texCoordHandle == null || !_texCoordHandle.isValid()) ) {
			updateTexCoordBuffer(renderer);
		}

		Mat4d modelViewMat = new Mat4d();

		cam.getViewMat4d(modelViewMat);
		modelViewMat.mult4(_trans.getMat4dRef());
		modelViewMat.scaleCols3(_scale);

		Mat4d normalMat = RenderUtils.getInverseWithScale(_trans, _scale);
		normalMat.transpose4();

		gl.glUseProgram(progHandle);

		gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0);
		gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(cam.getProjMat4d()), 0);
		gl.glUniformMatrix4fv(normalMatVar, 1, false, RenderUtils.MarshalMat4d(normalMat), 0);
		gl.glUniformMatrix4fv(bindSpaceMatVar, 1, false, identMat, 0);
		gl.glUniformMatrix4fv(bindSpaceNorMatVar, 1, false, identMat, 0);

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

		gl.glUniform1i(numLightsVar, 1);
		gl.glUniform3fv(lightDirVar, 1, lightDir, 0);
		gl.glUniform1fv(lightIntVar, 1, lightInt, 0);

		gl.glUniform3f(ambientColorVar, 0.0f, 0.0f, 0.0f);
		gl.glUniform3f(specColorVar, 0.0f, 0.0f, 0.0f);
		gl.glUniform1f(shininessVar, 1.0f);

		gl.glActiveTexture(GL2GL3.GL_TEXTURE0);
		gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID);
		gl.glUniform1i(texVar, 0);
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE);
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE);

		// Draw
		gl.glDisable(GL2GL3.GL_CULL_FACE);
		gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6);
		gl.glEnable(GL2GL3.GL_CULL_FACE);

		gl.glBindVertexArray(0);

	}
 
Example 3
Source File: MeshProto.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private void initBatchUniforms(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;

	BatchShaderInfo si = bsInfo;

	gl.glUseProgram(si.progHandle);

	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);

	int[] sampIDs = new int[_textureHandles.size()];
	for (int i = 0; i < sampIDs.length; ++i) {
		sampIDs[i] = i;
	}
	if (sampIDs.length > 0) {
		gl.glUniform1iv(si.diffTexVar, sampIDs.length, sampIDs, 0);
	}

	for (int i = 0; i < _textureHandles.size(); ++i) {
		gl.glActiveTexture(GL2GL3.GL_TEXTURE0+i);
		gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, _textureHandles.get(i));
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT);
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT);
	}
}