author | aghaisas |
Wed, 20 Feb 2019 17:00:40 +0530 | |
branch | metal-prototype-branch |
changeset 57196 | a95707a39ff5 |
child 57234 | e1e5386479c4 |
permissions | -rw-r--r-- |
57196
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
1 |
/* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
4 |
* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
10 |
* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
15 |
* accompanied this code). |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
16 |
* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
20 |
* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
23 |
* questions. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
24 |
*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
25 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
26 |
#ifndef HEADLESS |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
27 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
28 |
#include <jlong.h> |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
29 |
#include <jni_util.h> |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
30 |
#include <math.h> |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
31 |
#include <Foundation/NSObjCRuntime.h> |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
32 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
33 |
#include "sun_java2d_metal_MetalRenderer.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
34 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
35 |
#include "MetalRenderer.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
36 |
#include "MetalRenderQueue.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
37 |
#include "MetalSurfaceData.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
38 |
#import "shaders/MetalShaderTypes.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
39 |
#include "Trace.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
40 |
#include "MetalLayer.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
41 |
#import "VertexDataManager.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
42 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
43 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
44 |
// TODO : Current Color, Gradient etc should have its own class |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
45 |
static float drawColor[4] = {0.0, 0.0, 0.0, 0.0}; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
46 |
static int ClipRectangle[4] = {0, 0, 0, 0}; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
47 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
48 |
void |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
49 |
MetalRenderer_DrawLine(MetalContext *mtlc, jint x1, jint y1, jint x2, jint y2) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
50 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
51 |
//J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawLine"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
52 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
53 |
//RETURN_IF_NULL(mtlc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
54 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
55 |
//CHECK_PREVIOUS_OP(GL_LINES); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
56 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
57 |
float P1_X, P1_Y; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
58 |
float P2_X, P2_Y; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
59 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
60 |
if (y1 == y2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
61 |
// horizontal |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
62 |
float fx1 = (float)x1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
63 |
float fx2 = (float)x2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
64 |
float fy = ((float)y1) + 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
65 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
66 |
if (x1 > x2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
67 |
float t = fx1; fx1 = fx2; fx2 = t; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
68 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
69 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
70 |
P1_X = fx1+0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
71 |
P1_Y = fy; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
72 |
P2_X = fx2+1.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
73 |
P2_Y = fy; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
74 |
} else if (x1 == x2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
75 |
// vertical |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
76 |
float fx = ((float)x1) + 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
77 |
float fy1 = (float)y1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
78 |
float fy2 = (float)y2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
79 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
80 |
if (y1 > y2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
81 |
float t = fy1; fy1 = fy2; fy2 = t; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
82 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
83 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
84 |
P1_X = fx; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
85 |
P1_Y = fy1+0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
86 |
P2_X = fx; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
87 |
P2_Y = fy2+1.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
88 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
89 |
// diagonal |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
90 |
float fx1 = (float)x1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
91 |
float fy1 = (float)y1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
92 |
float fx2 = (float)x2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
93 |
float fy2 = (float)y2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
94 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
95 |
if (x1 < x2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
96 |
fx1 += 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
97 |
fx2 += 1.0f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
98 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
99 |
fx1 += 0.8f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
100 |
fx2 -= 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
101 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
102 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
103 |
if (y1 < y2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
104 |
fy1 += 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
105 |
fy2 += 1.0f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
106 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
107 |
fy1 += 0.8f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
108 |
fy2 -= 0.2f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
109 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
110 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
111 |
P1_X = fx1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
112 |
P1_Y = fy1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
113 |
P2_X = fx2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
114 |
P2_Y = fy2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
115 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
116 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
117 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
118 |
MetalSDOps* dstOps = MetalRenderQueue_GetCurrentDestination(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
119 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
120 |
MetalLayer* layer = dstOps->layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
121 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
122 |
// The (x1, y1) & (x2, y2) are in coordinate system : |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
123 |
// Top Left (0, 0) : Bottom Right (width and height) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
124 |
// |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
125 |
// Metal rendering coordinate system is : |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
126 |
// Top Left (-1.0, 1.0) : Bottom Right (1.0, -1.0) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
127 |
// |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
128 |
// Todo : This coordinate transformation should be moved to shader code. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
129 |
float halfWidth = layer.textureWidth / 2.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
130 |
float halfHeight = layer.textureHeight / 2.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
131 |
if (x1 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
132 |
x1 = -1 * (halfWidth - x1); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
133 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
134 |
x1 = x1 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
135 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
136 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
137 |
if (x2 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
138 |
x2 = -1 * (halfWidth - x2); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
139 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
140 |
x2 = x2 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
141 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
142 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
143 |
if (y1 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
144 |
y1 = -1 * (y1 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
145 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
146 |
y1 = halfHeight - y1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
147 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
148 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
149 |
if (y2 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
150 |
y2 = -1 * (y2 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
151 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
152 |
y2 = halfHeight - y2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
153 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
154 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
155 |
MetalVertex lineVertexData[] = |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
156 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
157 |
{ {x1/halfWidth, y1/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} }, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
158 |
{ {x2/halfWidth, y2/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} } |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
159 |
}; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
160 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
161 |
//NSLog(@"Drawline ----- x1 : %f, y1 : %f------ x2 : %f, y2 = %f", x1/halfWidth, y1/halfHeight, x2/halfWidth, y2/halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
162 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
163 |
VertexDataManager_addLineVertexData(lineVertexData[0], lineVertexData[1]); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
164 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
165 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
166 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
167 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
168 |
void |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
169 |
MetalRenderer_DrawParallelogram(MetalContext *mtlc, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
170 |
jfloat fx11, jfloat fy11, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
171 |
jfloat dx21, jfloat dy21, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
172 |
jfloat dx12, jfloat dy12, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
173 |
jfloat lwr21, jfloat lwr12) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
174 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
175 |
// dx,dy for line width in the "21" and "12" directions. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
176 |
jfloat ldx21 = dx21 * lwr21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
177 |
jfloat ldy21 = dy21 * lwr21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
178 |
jfloat ldx12 = dx12 * lwr12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
179 |
jfloat ldy12 = dy12 * lwr12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
180 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
181 |
// calculate origin of the outer parallelogram |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
182 |
jfloat ox11 = fx11 - (ldx21 + ldx12) / 2.0f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
183 |
jfloat oy11 = fy11 - (ldy21 + ldy12) / 2.0f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
184 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
185 |
/*J2dTraceLn8(J2D_TRACE_INFO, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
186 |
"OGLRenderer_DrawParallelogram " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
187 |
"(x=%6.2f y=%6.2f " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
188 |
"dx1=%6.2f dy1=%6.2f lwr1=%6.2f " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
189 |
"dx2=%6.2f dy2=%6.2f lwr2=%6.2f)", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
190 |
fx11, fy11, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
191 |
dx21, dy21, lwr21, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
192 |
dx12, dy12, lwr12);*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
193 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
194 |
// RETURN_IF_NULL(oglc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
195 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
196 |
// CHECK_PREVIOUS_OP(GL_QUADS); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
197 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
198 |
// Only need to generate 4 quads if the interior still |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
199 |
// has a hole in it (i.e. if the line width ratio was |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
200 |
// less than 1.0) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
201 |
if (lwr21 < 1.0f && lwr12 < 1.0f) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
202 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
203 |
// Note: "TOP", "BOTTOM", "LEFT" and "RIGHT" here are |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
204 |
// relative to whether the dxNN variables are positive |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
205 |
// and negative. The math works fine regardless of |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
206 |
// their signs, but for conceptual simplicity the |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
207 |
// comments will refer to the sides as if the dxNN |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
208 |
// were all positive. "TOP" and "BOTTOM" segments |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
209 |
// are defined by the dxy21 deltas. "LEFT" and "RIGHT" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
210 |
// segments are defined by the dxy12 deltas. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
211 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
212 |
// Each segment includes its starting corner and comes |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
213 |
// to just short of the following corner. Thus, each |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
214 |
// corner is included just once and the only lengths |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
215 |
// needed are the original parallelogram delta lengths |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
216 |
// and the "line width deltas". The sides will cover |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
217 |
// the following relative territories: |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
218 |
// |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
219 |
// T T T T T R |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
220 |
// L R |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
221 |
// L R |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
222 |
// L R |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
223 |
// L R |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
224 |
// L B B B B B |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
225 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
226 |
// TOP segment, to left side of RIGHT edge |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
227 |
// "width" of original pgram, "height" of hor. line size |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
228 |
fx11 = ox11; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
229 |
fy11 = oy11; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
230 |
FILL_PGRAM(fx11, fy11, dx21, dy21, ldx12, ldy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
231 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
232 |
// RIGHT segment, to top of BOTTOM edge |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
233 |
// "width" of vert. line size , "height" of original pgram |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
234 |
fx11 = ox11 + dx21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
235 |
fy11 = oy11 + dy21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
236 |
FILL_PGRAM(fx11, fy11, ldx21, ldy21, dx12, dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
237 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
238 |
// BOTTOM segment, from right side of LEFT edge |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
239 |
// "width" of original pgram, "height" of hor. line size |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
240 |
fx11 = ox11 + dx12 + ldx21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
241 |
fy11 = oy11 + dy12 + ldy21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
242 |
FILL_PGRAM(fx11, fy11, dx21, dy21, ldx12, ldy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
243 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
244 |
// LEFT segment, from bottom of TOP edge |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
245 |
// "width" of vert. line size , "height" of inner pgram |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
246 |
fx11 = ox11 + ldx12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
247 |
fy11 = oy11 + ldy12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
248 |
FILL_PGRAM(fx11, fy11, ldx21, ldy21, dx12, dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
249 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
250 |
// The line width ratios were large enough to consume |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
251 |
// the entire hole in the middle of the parallelogram |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
252 |
// so we can just issue one large quad for the outer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
253 |
// parallelogram. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
254 |
dx21 += ldx21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
255 |
dy21 += ldy21; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
256 |
dx12 += ldx12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
257 |
dy12 += ldy12; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
258 |
FILL_PGRAM(ox11, oy11, dx21, dy21, dx12, dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
259 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
260 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
261 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
262 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
263 |
void |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
264 |
MetalRenderer_FillParallelogram(MetalContext *mtlc, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
265 |
jfloat fx11, jfloat fy11, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
266 |
jfloat dx21, jfloat dy21, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
267 |
jfloat dx12, jfloat dy12) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
268 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
269 |
/*J2dTraceLn6(J2D_TRACE_INFO, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
270 |
"OGLRenderer_FillParallelogram " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
271 |
"(x=%6.2f y=%6.2f " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
272 |
"dx1=%6.2f dy1=%6.2f " |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
273 |
"dx2=%6.2f dy2=%6.2f)", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
274 |
fx11, fy11, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
275 |
dx21, dy21, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
276 |
dx12, dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
277 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
278 |
RETURN_IF_NULL(oglc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
279 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
280 |
CHECK_PREVIOUS_OP(GL_QUADS);*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
281 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
282 |
FILL_PGRAM(fx11, fy11, dx21, dy21, dx12, dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
283 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
284 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
285 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
286 |
void FILL_PGRAM(float fx11, float fy11, float dx21, float dy21, float dx12, float dy12) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
287 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
288 |
MetalRenderer_DrawQuad(fx11, fy11, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
289 |
fx11 + dx21, fy11 + dy21, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
290 |
fx11 + dx21 + dx12, fy11 + dy21 + dy12, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
291 |
fx11 + dx12, fy11 + dy12); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
292 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
293 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
294 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
295 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
296 |
void MetalRenderer_DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
297 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
298 |
// Draw two triangles with given 4 vertices |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
299 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
300 |
MetalSDOps* dstOps = MetalRenderQueue_GetCurrentDestination(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
301 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
302 |
MetalLayer* layer = dstOps->layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
303 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
304 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
305 |
// The (x1, y1) & (x2, y2) are in coordinate system : |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
306 |
// Top Left (0, 0) : Bottom Right (width and height) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
307 |
// |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
308 |
// Metal rendering coordinate system is : |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
309 |
// Top Left (-1.0, 1.0) : Bottom Right (1.0, -1.0) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
310 |
// |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
311 |
// Todo : This coordinate transformation should be moved to shader code. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
312 |
float halfWidth = layer.textureWidth / 2.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
313 |
float halfHeight = layer.textureHeight / 2.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
314 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
315 |
if (x1 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
316 |
x1 = -1 * (halfWidth - x1); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
317 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
318 |
x1 = x1 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
319 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
320 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
321 |
if (x2 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
322 |
x2 = -1 * (halfWidth - x2); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
323 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
324 |
x2 = x2 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
325 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
326 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
327 |
if (y1 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
328 |
y1 = -1 * (y1 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
329 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
330 |
y1 = halfHeight - y1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
331 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
332 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
333 |
if (y2 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
334 |
y2 = -1 * (y2 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
335 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
336 |
y2 = halfHeight - y2; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
337 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
338 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
339 |
if (x3 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
340 |
x3 = -1 * (halfWidth - x3); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
341 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
342 |
x3 = x3 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
343 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
344 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
345 |
if (x4 <= halfWidth) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
346 |
x4 = -1 * (halfWidth - x4); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
347 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
348 |
x4 = x4 - halfWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
349 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
350 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
351 |
if (y3 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
352 |
y3 = -1 * (y3 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
353 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
354 |
y3 = halfHeight - y3; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
355 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
356 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
357 |
if (y4 >= halfHeight) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
358 |
y4 = -1 * (y4 - halfHeight); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
359 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
360 |
y4 = halfHeight - y4; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
361 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
362 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
363 |
MetalVertex QuadVertexData[] = |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
364 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
365 |
{ {x1/halfWidth, y1/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} }, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
366 |
{ {x2/halfWidth, y2/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} }, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
367 |
{ {x3/halfWidth, y3/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} }, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
368 |
{ {x4/halfWidth, y4/halfHeight, 0.0, 1.0}, {drawColor[0], drawColor[1], drawColor[2], drawColor[3]} }, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
369 |
}; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
370 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
371 |
VertexDataManager_addQuadVertexData(QuadVertexData[0], QuadVertexData[1], QuadVertexData[2], QuadVertexData[3]); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
372 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
373 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
374 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
375 |
void MetalRenderer_SetColor(MetalContext *mtlc, jint color) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
376 |
//J2dTraceLn(J2D_TRACE_INFO, "MetalRenderer_SetColor"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
377 |
unsigned char r = (unsigned char)(color >> 16); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
378 |
unsigned char g = (unsigned char)(color >> 8); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
379 |
unsigned char b = (unsigned char)(color >> 0); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
380 |
unsigned char a = 0xff; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
381 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
382 |
drawColor[0] = r/255.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
383 |
drawColor[1] = g/255.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
384 |
drawColor[2] = b/255.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
385 |
drawColor[3] = 1.0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
386 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
387 |
NSLog(@"MetalRenderer SetColor ----- (%d, %d, %d, %d)", r, g, b, a); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
388 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
389 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
390 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
391 |
void MetalRenderer_DrawRect(MetalContext *mtlc, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
392 |
jint x, jint y, jint w, jint h) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
393 |
//J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawRect"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
394 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
395 |
if (w < 0 || h < 0) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
396 |
return; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
397 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
398 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
399 |
//RETURN_IF_NULL(oglc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
400 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
401 |
if (w < 2 || h < 2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
402 |
// If one dimension is less than 2 then there is no |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
403 |
// gap in the middle - draw a solid filled rectangle. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
404 |
//CHECK_PREVIOUS_OP(GL_QUADS); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
405 |
//GLRECT_BODY_XYWH(x, y, w+1, h+1); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
406 |
MetalRenderer_FillRect(mtlc, x, y, w+1, h+1); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
407 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
408 |
jint fx1 = (jint) (((float)x) + 0.2f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
409 |
jint fy1 = (jint) (((float)y) + 0.2f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
410 |
jint fx2 = fx1 + w; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
411 |
jint fy2 = fy1 + h; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
412 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
413 |
// Avoid drawing the endpoints twice. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
414 |
// Also prefer including the endpoints in the |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
415 |
// horizontal sections which draw pixels faster. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
416 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
417 |
// top |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
418 |
MetalRenderer_DrawLine(mtlc, fx1, fy1, fx2+1, fy1); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
419 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
420 |
// right |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
421 |
MetalRenderer_DrawLine(mtlc, fx2, fy1+1, fx2, fy2); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
422 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
423 |
// bottom |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
424 |
MetalRenderer_DrawLine(mtlc, fx1, fy2, fx2+1, fy2); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
425 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
426 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
427 |
// left |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
428 |
MetalRenderer_DrawLine(mtlc, fx1, fy1+1, fx1, fy2); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
429 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
430 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
431 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
432 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
433 |
void |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
434 |
MetalRenderer_FillRect(MetalContext *mtlc, jint x, jint y, jint w, jint h) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
435 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
436 |
//J2dTraceLn(J2D_TRACE_INFO, "MetalRenderer_FillRect"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
437 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
438 |
if (w <= 0 || h <= 0) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
439 |
return; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
440 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
441 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
442 |
//RETURN_IF_NULL(oglc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
443 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
444 |
//CHECK_PREVIOUS_OP(GL_QUADS); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
445 |
//GLRECT_BODY_XYWH(x, y, w, h); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
446 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
447 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
448 |
MetalRenderer_DrawQuad(x, y, x, y+h, x+w, y+h, x+w, y); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
449 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
450 |
//NSLog(@"MetalRenderer_FillRect: X, Y(%f, %f) with width, height(%f, %f)", (float)x, (float)y, (float)w, (float)h); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
451 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
452 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
453 |
// TODO : I think, this should go to metal context |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
454 |
void MetalRenderer_SetRectClip(MetalContext *mtlc, jint x1, jint y1, jint x2, jint y2) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
455 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
456 |
jint width = x2 - x1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
457 |
jint height = y2 - y1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
458 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
459 |
J2dTraceLn4(J2D_TRACE_INFO, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
460 |
"MetalRenderer_SetRectClip: x=%d y=%d w=%d h=%d", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
461 |
x1, y1, width, height); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
462 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
463 |
//RETURN_IF_NULL(dstOps); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
464 |
//RETURN_IF_NULL(oglc); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
465 |
//CHECK_PREVIOUS_OP(OGL_STATE_CHANGE); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
466 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
467 |
if ((width < 0) || (height < 0)) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
468 |
// use an empty scissor rectangle when the region is empty |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
469 |
width = 0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
470 |
height = 0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
471 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
472 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
473 |
//j2d_glDisable(GL_DEPTH_TEST); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
474 |
//j2d_glEnable(GL_SCISSOR_TEST); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
475 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
476 |
// the scissor rectangle is specified using the lower-left |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
477 |
// origin of the clip region (in the framebuffer's coordinate |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
478 |
// space), so we must account for the x/y offsets of the |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
479 |
// destination surface |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
480 |
/*j2d_glScissor(dstOps->xOffset + x1, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
481 |
dstOps->yOffset + dstOps->height - (y1 + height), |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
482 |
width, height);*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
483 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
484 |
MetalSDOps *dstOps = MetalRenderQueue_GetCurrentDestination(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
485 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
486 |
ClipRectangle[0] = x1;//dstOps->xOffset + x1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
487 |
ClipRectangle[1] = y1;//dstOps->yOffset + dstOps->height - (y1 + height); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
488 |
ClipRectangle[2] = width; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
489 |
ClipRectangle[3] = height; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
490 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
491 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
492 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
493 |
void MetalRenderer_Flush() { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
494 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
495 |
MetalSDOps* dstOps = MetalRenderQueue_GetCurrentDestination(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
496 |
MetalLayer* mtlLayer = dstOps->layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
497 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
498 |
//Create a render pass descriptor |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
499 |
MTLRenderPassDescriptor* mtlRenderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
500 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
501 |
//Set the SurfaceData offscreen texture as target texture for the rendering pipeline |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
502 |
mtlRenderPassDescriptor.colorAttachments[0].texture = dstOps->mtlTexture; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
503 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
504 |
mtlRenderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
505 |
mtlRenderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.8, 0.8, 0.8, 1.0); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
506 |
mtlRenderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
507 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
508 |
id<MTLCommandBuffer> mtlCommandBuffer = [dstOps->configInfo->commandQueue commandBuffer]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
509 |
id<MTLRenderCommandEncoder> renderEncoder = [mtlCommandBuffer renderCommandEncoderWithDescriptor:mtlRenderPassDescriptor]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
510 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
511 |
// Configure render enconder with the pipeline state |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
512 |
[renderEncoder setRenderPipelineState:mtlLayer.renderPipelineState]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
513 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
514 |
// Whatever outside this rectangle won't be drawn |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
515 |
// TODO : ClipRectangle should be part of MetalContext or some state maintaining class |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
516 |
NSLog(@"Setting Rect Clip : %d, %d, %d, %d", ClipRectangle[0], ClipRectangle[1], ClipRectangle[2], ClipRectangle[3]); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
517 |
MTLScissorRect clip = {ClipRectangle[0], ClipRectangle[1], ClipRectangle[2], ClipRectangle[3]}; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
518 |
[renderEncoder setScissorRect:clip]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
519 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
520 |
// --------------------------------------------------------- |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
521 |
// DRAW primitives from VertexDataManager |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
522 |
// --------------------------------------------------------- |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
523 |
[renderEncoder setVertexBuffer:VertexDataManager_getVertexBuffer() offset:0 atIndex:0]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
524 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
525 |
MetalPrimitiveData** allPrimitives = VertexDataManager_getAllPrimitives(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
526 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
527 |
int totalPrimitives = VertexDataManager_getNoOfPrimitives(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
528 |
for (int i = 0; i < totalPrimitives; i++ ) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
529 |
MetalPrimitiveData* p = allPrimitives[i]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
530 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
531 |
NSLog(@"----------------------------------------------"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
532 |
NSLog(@"Encoding primitive %d", i); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
533 |
NSLog(@"indexCount %d", p->no_of_indices); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
534 |
NSLog(@"indexBufferOffset %d", p->offset_in_index_buffer); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
535 |
NSLog(@"primitiveInstances %d", p->primitiveInstances); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
536 |
NSLog(@"----------------------------------------------"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
537 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
538 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
539 |
[renderEncoder drawIndexedPrimitives: p->type |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
540 |
indexCount: (NSUInteger)p->no_of_indices |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
541 |
indexType: (MTLIndexType)MTLIndexTypeUInt16 |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
542 |
indexBuffer: (id<MTLBuffer>)VertexDataManager_getIndexBuffer() |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
543 |
indexBufferOffset: (NSUInteger)p->offset_in_index_buffer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
544 |
instanceCount: (NSUInteger)p->primitiveInstances]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
545 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
546 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
547 |
//-------------------------------------------------- |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
548 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
549 |
[renderEncoder endEncoding]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
550 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
551 |
[mtlCommandBuffer commit]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
552 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
553 |
[mtlCommandBuffer waitUntilCompleted]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
554 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
555 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
556 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
557 |
void MetalRenderer_blitToScreenDrawable() { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
558 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
559 |
MetalSDOps* dstOps = MetalRenderQueue_GetCurrentDestination(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
560 |
MetalLayer* mtlLayer = dstOps->layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
561 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
562 |
@autoreleasepool { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
563 |
id <CAMetalDrawable> frameDrawable = [mtlLayer nextDrawable]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
564 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
565 |
id<MTLCommandBuffer> commandBuffer = [dstOps->configInfo->commandQueue commandBuffer]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
566 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
567 |
id<MTLBlitCommandEncoder> blitEncoder = [commandBuffer blitCommandEncoder]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
568 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
569 |
//[blitEncoder synchronizeResource:_texture]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
570 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
571 |
[blitEncoder copyFromTexture:dstOps->mtlTexture |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
572 |
sourceSlice:0 |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
573 |
sourceLevel:0 |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
574 |
sourceOrigin:MTLOriginMake(ClipRectangle[0], ClipRectangle[1], 0) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
575 |
sourceSize:MTLSizeMake(dstOps->mtlTexture.width - ClipRectangle[0], dstOps->mtlTexture.height - ClipRectangle[1], 1) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
576 |
toTexture:frameDrawable.texture |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
577 |
destinationSlice:0 |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
578 |
destinationLevel:0 |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
579 |
destinationOrigin:MTLOriginMake(0, 0, 0)]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
580 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
581 |
[blitEncoder endEncoding]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
582 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
583 |
[commandBuffer presentDrawable:frameDrawable]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
584 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
585 |
[commandBuffer commit]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
586 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
587 |
[commandBuffer waitUntilCompleted]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
588 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
589 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
590 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
591 |
#endif |