use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class InteractiveGLVisualProcessor method windowToGraphCoordinates.
@Override
public Vector3f windowToGraphCoordinates(final Camera camera, final Point point) {
final Camera originCamera = new Camera(camera);
CameraUtilities.moveEyeToOrigin(originCamera);
Matrix44f modelViewProjectionMatrix = getCameraModelViewProjectionMatrix(originCamera);
Vector3f worldPosition = new Vector3f();
final Vector3f direction = CameraUtilities.getFocusVector(originCamera);
direction.scale(10);
Graphics3DUtilities.screenToWorldCoordinates(new Vector3f(point.x, point.y, 0), direction, modelViewProjectionMatrix, getViewport(), worldPosition);
worldPosition.add(camera.lookAtEye);
return worldPosition;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class NewLineRenderable method display.
/**
* Draws the new line on the display.
* <p>
* @param drawable The OpenGL rendering target.
* @param pMatrix The model view projection matrix.
*/
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) {
final Matrix44f mvpMatrix = parent.getDisplayModelViewProjectionMatrix();
// If no endpoints are set, don't draw anything
if (model != null && !model.isClear()) {
final Vector3f startPosition = model.getStartLocation();
final Vector3f endPosition = model.getEndLocation();
final GL3 gl = drawable.getGL().getGL3();
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, batch.getBufferName(vertexTarget));
ByteBuffer bbuf = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY);
FloatBuffer fbuf = bbuf.asFloatBuffer();
// Update the line endpoints in the vertex buffer.
float[] vertices = new float[] { startPosition.getX(), startPosition.getY(), startPosition.getZ(), endPosition.getX(), endPosition.getY(), endPosition.getZ() };
fbuf.put(vertices);
gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
// Disable depth so the line is drawn over everything else.
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDepthMask(false);
// Draw the line.
gl.glLineWidth(NEW_LINE_WIDTH);
gl.glUseProgram(shader);
gl.glUniformMatrix4fv(shaderMVP, 1, false, mvpMatrix.a, 0);
batch.draw(gl);
gl.glLineWidth(1);
// Reenable depth.
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthMask(true);
// Rebind default array buffer
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class GraphRenderable method display.
/**
* Display this batch store to OpenGL.
*
* display is called in response to various events such as the move moving
* or right clicking. It isn't a continuous render call one might expect in
* an OpenGL application.
*
* @param drawable From the reference: A higher-level abstraction than
* GLDrawable which supplies an event based mechanism (GLEventListener) for
* performing OpenGL rendering. A GLAutoDrawable automatically creates a
* primary rendering context which is associated with the GLAutoDrawable for
* the lifetime of the object.
* @param pMatrix
*/
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) {
final GL3 gl = drawable.getGL().getGL3();
graphDisplayer.bindDisplayer(gl);
if (!skipRedraw) {
// Direction Indicators.
if (motion == -1) {
if (DirectionIndicatorsAction.isShowIndicators()) {
initialMotion = System.currentTimeMillis();
motion = 0;
}
} else if (DirectionIndicatorsAction.isShowIndicators()) {
motion = (System.currentTimeMillis() - initialMotion) / 100F;
} else {
motion = -1;
}
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
gl.glClearColor(graphBackgroundColor[0], graphBackgroundColor[1], graphBackgroundColor[2], graphBackgroundColor[3]);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Bind the textures to their texture units.
// This only needs to be done once.
gl.glActiveTexture(GL.GL_TEXTURE0 + TextureUnits.VERTICES);
gl.glBindTexture(GL2ES3.GL_TEXTURE_BUFFER, xyzTexturiser.getTextureName());
gl.glActiveTexture(GL.GL_TEXTURE0 + TextureUnits.ICONS);
gl.glBindTexture(GL2ES3.GL_TEXTURE_2D_ARRAY, iconTextureArray);
gl.glActiveTexture(GL.GL_TEXTURE0 + TextureUnits.VERTEX_FLAGS);
gl.glBindTexture(GL2ES3.GL_TEXTURE_BUFFER, vertexFlagsTexturiser.getTextureName());
final Matrix44f mvMatrix = parent.getDisplayModelViewMatrix();
if (AnaglyphicDisplayAction.isAnaglyphicDisplay()) {
// Draw (some parts of) the graph in anaglyph format.
// To do this, we use an AnaglyphicCamera to draw the graph twice,
// from the viewpoints of the left and right eyes.
//
// The convergence is the plane where objects appear to be at the same depth as the screen.
// Objects closer than this appear to be in front of the screen; objects further than
// this appear to be inside the screen.
//
// Ideally we want this to be some fixed distance from the camera(s), taking the size of
// the graph into consideration; for example, half the width of the graph. However,
// this would mean recalculating the physical size of the graph every time we displayed it (because
// here we don't want to keep track of which graph we're displaying).
//
// As a reasonable substitute, we'll use the distance from the eye to the centre.
// Resetting the view puts the lookAt centre in the middle of the graph anyway,
// and moving around generally seems to keep the centre at the same distance from the eye.
// As a convenient side effect, if the centre is changed to a node, then that node will be at the convergence.
//
final Vector3f eye = camera.lookAtEye;
final Vector3f centre = camera.lookAtCentre;
final float distanceToCentre = Vector3f.subtract(centre, eye).getLength();
final float convergence = Camera.PERSPECTIVE_NEAR + distanceToCentre;
// This is an arbitrary value, arrived at by experimentation.
final float eyeSeparation = 0.25F;
final float aspect = (float) graphDisplayer.getWidth() / (float) graphDisplayer.getHeight();
final AnaglyphCamera anaglyphCam = new AnaglyphCamera(convergence, eyeSeparation, aspect, Camera.FIELD_OF_VIEW, Camera.PERSPECTIVE_NEAR, Camera.PERSPECTIVE_FAR);
// The eye colors are pulled from the preferences by AnaglyphicDisplayAction when
// anaglyphic mode is turned on. A bit ugly, but it gives us quick access to the colors.
// Note that the eye glass colors go to the opposite camera.
//
final AnaglyphicDisplayAction.EyeColorMask leftEyeColor = AnaglyphicDisplayAction.getLeftColorMask();
final AnaglyphicDisplayAction.EyeColorMask rightEyeColor = AnaglyphicDisplayAction.getRightColorMask();
// Draw view from left eye.
//
Matrix44f mv = anaglyphCam.applyLeftFrustum(mvMatrix);
Matrix44f p = anaglyphCam.getProjectionMatrix();
gl.glColorMask(rightEyeColor.red, rightEyeColor.green, rightEyeColor.blue, true);
drawBatches(gl, mv, p, true);
// Draw view from right eye.
//
// Don't overwrite the other eye.
//
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
mv = anaglyphCam.applyRightFrustum(mvMatrix);
p = anaglyphCam.getProjectionMatrix();
gl.glColorMask(leftEyeColor.red, leftEyeColor.green, leftEyeColor.blue, true);
drawBatches(gl, mv, p, true);
gl.glColorMask(true, true, true, true);
} else {
drawBatches(gl, mvMatrix, pMatrix, false);
if (hitTestFboName > 0 && drawHitTest) {
// Draw the lines and icons again with unique colors on the hitTest framebuffer.
// The lines will be thicker for easier hitting.
gl.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, hitTestFboName);
// Explicitly clear the color to black: we need the default color to be 0 so elements drawn as non-zero are recognised.
gl.glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glDisable(GL.GL_LINE_SMOOTH);
// Is this the default anyway?
final int[] fboBuffers = { GL.GL_COLOR_ATTACHMENT0 };
gl.glDrawBuffers(1, fboBuffers, 0);
gl.glPolygonOffset(FURTHER_F, FURTHER_U);
if (drawFlags.drawConnections()) {
lineBatcher.setNextDrawIsHitTest();
lineBatcher.drawBatch(gl, camera, mvMatrix, pMatrix, false);
loopBatcher.setNextDrawIsHitTest();
loopBatcher.drawBatch(gl, camera, mvMatrix, pMatrix, false);
}
gl.glPolygonOffset(NEARER_F, NEARER_U);
// Draw node icons into hit test buffer
if (drawFlags.drawNodes()) {
iconBatcher.setNextDrawIsHitTest();
iconBatcher.drawBatch(gl, camera, mvMatrix, pMatrix, false);
}
gl.glPolygonOffset(0, 0);
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
gl.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, 0);
gl.glEnable(GL.GL_LINE_SMOOTH);
}
}
}
// Get the graph displayer to render its contents to the screen
graphDisplayer.display(drawable, pMatrix);
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class ShaderManager method useStockShader.
/**
* Use one of the provided shaders and set the shader-specific uniforms.
*
* @param gl the current OpenGL context.
* @param shaderId The id of the shader.
* @param args The shader-specific uniform arguments.
*
* @return the id of the shader.
*/
public int useStockShader(final GL3 gl, final int shaderId, final Object... args) {
if (shaderId >= SHADER_LAST) {
throw new RenderException("Invalid shader id.");
}
// Bind to the correct shader.
gl.glUseProgram(stockShaders[shaderId]);
// Set up the uniforms.
if (shaderId == SHADER_IDENTITY) {
// Just the color.
int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
float[] color = (float[]) args[0];
gl.glUniform4fv(colorLoc, 1, color, 0);
} else if (shaderId == SHADER_FLAT) {
// The modelview projection matrix and the color.
int transformLoc = gl.glGetUniformLocation(stockShaders[shaderId], "mvpMatrix");
Matrix44f mvpMatrix = (Matrix44f) args[0];
gl.glUniformMatrix4fv(transformLoc, 1, false, mvpMatrix.a, 0);
int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
float[] color = (float[]) args[1];
gl.glUniform4fv(colorLoc, 1, color, 0);
} else if (shaderId == SHADER_POINT_LIGHT_DIFF) {
int modelMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "mvMatrix");
Matrix44f mvMatrix = (Matrix44f) args[0];
gl.glUniformMatrix4fv(modelMatrix, 1, false, mvMatrix.a, 0);
int projMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "pMatrix");
Matrix44f pMatrix = (Matrix44f) args[1];
gl.glUniformMatrix4fv(projMatrix, 1, false, pMatrix.a, 0);
int light = gl.glGetUniformLocation(stockShaders[shaderId], "vLightPos");
Vector3f vLightPos = (Vector3f) args[2];
gl.glUniform3fv(light, 1, vLightPos.a, 0);
int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
float[] color = (float[]) args[3];
gl.glUniform4fv(colorLoc, 1, color, 0);
} else if (shaderId == SHADER_TEXTURE_POINT_LIGHT_DIFF) {
int modelMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "mvMatrix");
Matrix44f mvMatrix = (Matrix44f) args[0];
gl.glUniformMatrix4fv(modelMatrix, 1, false, mvMatrix.a, 0);
int projMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "pMatrix");
Matrix44f pMatrix = (Matrix44f) args[1];
gl.glUniformMatrix4fv(projMatrix, 1, false, pMatrix.a, 0);
int light = gl.glGetUniformLocation(stockShaders[shaderId], "vLightPos");
Vector3f lightPos = (Vector3f) args[2];
gl.glUniform3fv(light, 1, lightPos.a, 0);
int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
Vector4f color = (Vector4f) args[3];
gl.glUniform4fv(colorLoc, 1, color.a, 0);
int textureUnit = gl.glGetUniformLocation(stockShaders[shaderId], "textureUnit0");
int i = (Integer) args[4];
gl.glUniform1i(textureUnit, i);
} else {
throw new RenderException("Unimplemented shader.");
}
return stockShaders[shaderId];
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class ConnectionLabelBatcher method fillLabels.
private void fillLabels(final VisualAccess access, ConnectionGlyphStream glyphStream) throws InterruptedException {
final ConnectionGlyphStreamContext context = new ConnectionGlyphStreamContext();
for (int link = 0; link < access.getLinkCount(); link++) {
final int connectionCount = access.getLinkConnectionCount(link);
setCurrentConnection(access.getLinkLowVertex(link), access.getLinkHighVertex(link), connectionCount, context);
for (int pos = 0; pos < connectionCount; pos++) {
final int connection = access.getLinkConnection(link, pos);
nextParallelConnection((int) (LabelUtilities.NRADIUS_TO_LINE_WIDTH_UNITS * Math.min(LabelUtilities.MAX_TRANSACTION_WIDTH, access.getConnectionWidth(connection))), context);
final Matrix44f currentLabelInfo = access.isLabelSummary(connection) ? summaryLabelInfo : attributeLabelInfoReference;
bufferLabel(connection, access, glyphStream, currentLabelInfo, context);
}
}
glyphStream.trimToSize();
}
Aggregations