< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m

Print this page

 59  * important thing is that these magic numbers ensure that all MTL lines
 60  * hit the same endpoints as our software loops.
 61  *
 62  * If you find it necessary to change any of these magic numbers in the
 63  * future, just be sure that you test the changes across a variety of
 64  * hardware to ensure consistent rendering everywhere.
 65  */
 66 
 67 void MTLRenderer_DrawLine(MTLContext *mtlc, BMTLSDOps * dstOps, jint x1, jint y1, jint x2, jint y2) {
 68     if (mtlc == NULL || dstOps == NULL || dstOps->pTexture == NULL) {
 69         J2dTraceLn(J2D_TRACE_ERROR, "MTLRenderer_DrawLine: dest is null");
 70         return;
 71     }
 72 
 73     J2dTraceLn5(J2D_TRACE_INFO, "MTLRenderer_DrawLine (x1=%1.2f y1=%1.2f x2=%1.2f y2=%1.2f), dst tex=%p", x1, y1, x2, y2, dstOps->pTexture);
 74 
 75     id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
 76     if (mtlEncoder == nil)
 77         return;
 78 
 79     struct Vertex verts[2] = {
 80             {{x1, y1}},
 81             {{x2, y2}}
 82     };





















































 83 
 84     [mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
 85     [mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2];
 86 }
 87 
 88 void MTLRenderer_DrawRect(MTLContext *mtlc, BMTLSDOps * dstOps, jint x, jint y, jint w, jint h) {
 89     if (mtlc == NULL || dstOps == NULL || dstOps->pTexture == NULL) {
 90         J2dTraceLn(J2D_TRACE_ERROR, "MTLRenderer_DrawRect: dest is null");
 91         return;
 92     }
 93 
 94     id<MTLTexture> dest = dstOps->pTexture;
 95     J2dTraceLn5(J2D_TRACE_INFO, "MTLRenderer_DrawRect (x=%d y=%d w=%d h=%d), dst tex=%p", x, y, w, h, dest);
 96 
 97     // TODO: use DrawParallelogram(x, y, w, h, lw=1, lh=1)
 98     id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
 99     if (mtlEncoder == nil)
100         return;
101 
102     const int verticesCount = 5;

 59  * important thing is that these magic numbers ensure that all MTL lines
 60  * hit the same endpoints as our software loops.
 61  *
 62  * If you find it necessary to change any of these magic numbers in the
 63  * future, just be sure that you test the changes across a variety of
 64  * hardware to ensure consistent rendering everywhere.
 65  */
 66 
 67 void MTLRenderer_DrawLine(MTLContext *mtlc, BMTLSDOps * dstOps, jint x1, jint y1, jint x2, jint y2) {
 68     if (mtlc == NULL || dstOps == NULL || dstOps->pTexture == NULL) {
 69         J2dTraceLn(J2D_TRACE_ERROR, "MTLRenderer_DrawLine: dest is null");
 70         return;
 71     }
 72 
 73     J2dTraceLn5(J2D_TRACE_INFO, "MTLRenderer_DrawLine (x1=%1.2f y1=%1.2f x2=%1.2f y2=%1.2f), dst tex=%p", x1, y1, x2, y2, dstOps->pTexture);
 74 
 75     id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
 76     if (mtlEncoder == nil)
 77         return;
 78 
 79     // DrawLine implementation same as in OGLRenderer.c
 80     struct Vertex verts[2];
 81     if (y1 == y2) {
 82         // horizontal
 83         float fx1 = (float)x1;
 84         float fx2 = (float)x2;
 85         float fy  = ((float)y1) + 0.2f;
 86 
 87         if (x1 > x2) {
 88             float t = fx1; fx1 = fx2; fx2 = t;
 89         }
 90 
 91         struct Vertex v1 = {{fx1 + 0.2f, fy}};
 92         struct Vertex v2 = {{fx2 + 1.2f, fy}};
 93         verts[0] = v1;
 94         verts[1] = v2;
 95     } else if (x1 == x2) {
 96         // vertical
 97         float fx  = ((float)x1) + 0.2f;
 98         float fy1 = (float)y1;
 99         float fy2 = (float)y2;
100 
101         if (y1 > y2) {
102             float t = fy1; fy1 = fy2; fy2 = t;
103         }
104 
105         struct Vertex v1 = {{fx, fy1 + 0.2f}};
106         struct Vertex v2 = {{fx, fy2 + 1.2f}};
107         verts[0] = v1;
108         verts[1] = v2;
109     } else {
110         // diagonal
111         float fx1 = (float)x1;
112         float fy1 = (float)y1;
113         float fx2 = (float)x2;
114         float fy2 = (float)y2;
115 
116         if (x1 < x2) {
117             fx1 += 0.2f;
118             fx2 += 1.0f;
119         } else {
120             fx1 += 0.8f;
121             fx2 -= 0.2f;
122         }
123 
124         if (y1 < y2) {
125             fy1 += 0.2f;
126             fy2 += 1.0f;
127         } else {
128             fy1 += 0.8f;
129             fy2 -= 0.2f;
130         }
131         struct Vertex v1 = {{fx1, fy1}};
132         struct Vertex v2 = {{fx2, fy2}};
133         verts[0] = v1;
134         verts[1] = v2;
135     }
136 
137     [mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
138     [mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2];
139 }
140 
141 void MTLRenderer_DrawRect(MTLContext *mtlc, BMTLSDOps * dstOps, jint x, jint y, jint w, jint h) {
142     if (mtlc == NULL || dstOps == NULL || dstOps->pTexture == NULL) {
143         J2dTraceLn(J2D_TRACE_ERROR, "MTLRenderer_DrawRect: dest is null");
144         return;
145     }
146 
147     id<MTLTexture> dest = dstOps->pTexture;
148     J2dTraceLn5(J2D_TRACE_INFO, "MTLRenderer_DrawRect (x=%d y=%d w=%d h=%d), dst tex=%p", x, y, w, h, dest);
149 
150     // TODO: use DrawParallelogram(x, y, w, h, lw=1, lh=1)
151     id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];
152     if (mtlEncoder == nil)
153         return;
154 
155     const int verticesCount = 5;
< prev index next >