< prev index next > src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m
Print this page
id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
if (mtlEncoder == nil)
return;
! struct Vertex verts[2] = {
! {{x1, y1}},
! {{x2, y2}}
! };
[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2];
}
id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
if (mtlEncoder == nil)
return;
! // DrawLine implementation same as in OGLRenderer.c
! struct Vertex verts[2];
! if (y1 == y2) {
! // horizontal
+ float fx1 = (float)x1;
+ float fx2 = (float)x2;
+ float fy = ((float)y1) + 0.2f;
+
+ if (x1 > x2) {
+ float t = fx1; fx1 = fx2; fx2 = t;
+ }
+
+ struct Vertex v1 = {{fx1 + 0.2f, fy}};
+ struct Vertex v2 = {{fx2 + 1.2f, fy}};
+ verts[0] = v1;
+ verts[1] = v2;
+ } else if (x1 == x2) {
+ // vertical
+ float fx = ((float)x1) + 0.2f;
+ float fy1 = (float)y1;
+ float fy2 = (float)y2;
+
+ if (y1 > y2) {
+ float t = fy1; fy1 = fy2; fy2 = t;
+ }
+
+ struct Vertex v1 = {{fx, fy1 + 0.2f}};
+ struct Vertex v2 = {{fx, fy2 + 1.2f}};
+ verts[0] = v1;
+ verts[1] = v2;
+ } else {
+ // diagonal
+ float fx1 = (float)x1;
+ float fy1 = (float)y1;
+ float fx2 = (float)x2;
+ float fy2 = (float)y2;
+
+ if (x1 < x2) {
+ fx1 += 0.2f;
+ fx2 += 1.0f;
+ } else {
+ fx1 += 0.8f;
+ fx2 -= 0.2f;
+ }
+
+ if (y1 < y2) {
+ fy1 += 0.2f;
+ fy2 += 1.0f;
+ } else {
+ fy1 += 0.8f;
+ fy2 -= 0.2f;
+ }
+ struct Vertex v1 = {{fx1, fy1}};
+ struct Vertex v2 = {{fx2, fy2}};
+ verts[0] = v1;
+ verts[1] = v2;
+ }
[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2];
}
< prev index next >