< prev index next >

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

Print this page

 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 

 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         verts[0].position[0] = fx1 + 0.2f;
 92         verts[0].position[1] = fy;
 93         verts[1].position[0] = fx2 + 1.2f;
 94         verts[1].position[1] = fy;
 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         verts[0].position[0] = fx;
106         verts[0].position[1] = fy1 + 0.2f;
107         verts[1].position[0] = fx;
108         verts[1].position[1] = fy2 + 1.2f;
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         verts[0].position[0] = fx1;
132         verts[0].position[1] = fy1;
133         verts[1].position[0] = fx2;
134         verts[1].position[1] = fy2;
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 
< prev index next >