author | aghaisas |
Wed, 20 Feb 2019 17:00:40 +0530 | |
branch | metal-prototype-branch |
changeset 57196 | a95707a39ff5 |
child 57206 | 77a160ad0db7 |
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 |
#import "MetalGraphicsConfig.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
27 |
#import "MetalLayer.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
28 |
#import "shaders/MetalShaderTypes.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
29 |
#import "ThreadUtilities.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
30 |
#import "LWCToolkit.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
31 |
#import "MetalSurfaceData.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
32 |
#import "VertexDataManager.h" |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
33 |
|
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 |
//extern NSOpenGLPixelFormat *sharedPixelFormat; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
36 |
//extern NSOpenGLContext *sharedContext; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
37 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
38 |
@implementation MetalLayer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
39 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
40 |
@synthesize javaLayer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
41 |
@synthesize mtlTexture; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
42 |
//@synthesize target; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
43 |
@synthesize textureWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
44 |
@synthesize textureHeight; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
45 |
@synthesize mtlLibrary; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
46 |
@synthesize mtlRenderPipelineDescriptor; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
47 |
@synthesize renderPipelineState; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
48 |
//@synthesize LineVertexBuffer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
49 |
//@synthesize QuadVertexBuffer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
50 |
#ifdef REMOTELAYER |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
51 |
//@synthesize parentLayer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
52 |
//@synthesize remoteLayer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
53 |
//@synthesize jrsRemoteLayer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
54 |
#endif |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
55 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
56 |
- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
57 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
58 |
AWT_ASSERT_APPKIT_THREAD; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
59 |
// Initialize ourselves |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
60 |
self = [super init]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
61 |
if (self == nil) return self; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
62 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
63 |
self.javaLayer = layer; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
64 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
65 |
// NOTE: async=YES means that the layer is re-cached periodically |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
66 |
//self.displaySyncEnabled = NO; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
67 |
self.contentsGravity = kCAGravityTopLeft; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
68 |
//Layer backed view |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
69 |
//self.needsDisplayOnBoundsChange = YES; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
70 |
//self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
71 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
72 |
//fprintf(stdout, "MetalLayer_initWithJavaLayer\n");fflush(stdout); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
73 |
//Disable CALayer's default animation |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
74 |
NSMutableDictionary * actions = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
75 |
[NSNull null], @"anchorPoint", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
76 |
[NSNull null], @"bounds", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
77 |
[NSNull null], @"contents", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
78 |
[NSNull null], @"contentsScale", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
79 |
[NSNull null], @"onOrderIn", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
80 |
[NSNull null], @"onOrderOut", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
81 |
[NSNull null], @"position", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
82 |
[NSNull null], @"sublayers", |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
83 |
nil]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
84 |
self.actions = actions; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
85 |
[actions release]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
86 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
87 |
//textureID = 0; // texture will be created by rendering pipe |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
88 |
mtlTexture = NULL; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
89 |
//target = 0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
90 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
91 |
return self; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
92 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
93 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
94 |
- (void) dealloc { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
95 |
self.javaLayer = nil; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
96 |
[super dealloc]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
97 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
98 |
VertexDataManager_freeAllPrimitives(); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
99 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
100 |
|
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 |
- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
103 |
return CGLRetainPixelFormat(sharedPixelFormat.CGLPixelFormatObj); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
104 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
105 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
106 |
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
107 |
CGLContextObj contextObj = NULL; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
108 |
CGLCreateContext(pixelFormat, sharedContext.CGLContextObj, &contextObj); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
109 |
return contextObj; |
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 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
112 |
// use texture (intermediate buffer) as src and blit it to the layer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
113 |
/*- (void) blitTexture |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
114 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
115 |
if (textureID == 0) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
116 |
return; |
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 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
119 |
glEnable(target); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
120 |
glBindTexture(target, textureID); |
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 |
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // srccopy |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
123 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
124 |
float swid = 1.0f, shgt = 1.0f; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
125 |
if (target == GL_TEXTURE_RECTANGLE_ARB) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
126 |
swid = textureWidth; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
127 |
shgt = textureHeight; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
128 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
129 |
glBegin(GL_QUADS); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
130 |
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
131 |
glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
132 |
glTexCoord2f(swid, shgt); glVertex2f( 1.0f, 1.0f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
133 |
glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f, 1.0f); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
134 |
glEnd(); |
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 |
glBindTexture(target, 0); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
137 |
glDisable(target); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
138 |
}*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
139 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
140 |
/*-(BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
141 |
return textureID == 0 ? NO : YES; |
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 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
144 |
-(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
145 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
146 |
AWT_ASSERT_APPKIT_THREAD; |
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 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
149 |
static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
150 |
static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V"); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
151 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
152 |
jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
153 |
if ((*env)->IsSameObject(env, javaLayerLocalRef, NULL)) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
154 |
return; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
155 |
} |
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 |
// Set the current context to the one given to us. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
158 |
CGLSetCurrentContext(glContext); |
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 |
// Should clear the whole CALayer, because it can be larger than our texture. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
161 |
glClearColor(0.0, 0.0, 0.0, 0.0); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
162 |
glClear(GL_COLOR_BUFFER_BIT); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
163 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
164 |
glViewport(0, 0, textureWidth, textureHeight); |
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 |
JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
167 |
(*env)->DeleteLocalRef(env, javaLayerLocalRef); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
168 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
169 |
// Call super to finalize the drawing. By default all it does is call glFlush(). |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
170 |
[super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
171 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
172 |
CGLSetCurrentContext(NULL); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
173 |
}*/ |
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 |
@end |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
176 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
177 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
178 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
179 |
static jlong cachedLayer = 0; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
180 |
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
|
181 |
/* |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
182 |
* Class: sun_java2d_metal_MetalLayer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
183 |
* Method: nativeCreateLayer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
184 |
* Signature: ()J |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
185 |
*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
186 |
JNIEXPORT jlong JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
187 |
Java_sun_java2d_metal_MetalLayer_nativeCreateLayer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
188 |
(JNIEnv *env, jobject obj) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
189 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
190 |
__block MetalLayer *layer = nil; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
191 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
192 |
//fprintf(stdout, "MetalLayer_nativeCreateLayer\n");fflush(stdout); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
193 |
JNF_COCOA_ENTER(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
194 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
195 |
JNFWeakJObjectWrapper *javaLayer = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
196 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
197 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
198 |
AWT_ASSERT_APPKIT_THREAD; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
199 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
200 |
layer = [[MetalLayer alloc] initWithJavaLayer: javaLayer]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
201 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
202 |
//cachedLayer = ptr_to_jlong(layer); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
203 |
}]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
204 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
205 |
JNF_COCOA_EXIT(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
206 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
207 |
return ptr_to_jlong(layer); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
208 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
209 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
210 |
|
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 |
JNIEXPORT jlong JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
213 |
Java_sun_java2d_metal_MetalLayer_nativeInitLayer |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
214 |
(JNIEnv *env, jobject obj, jlong configInfo, jlong layer) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
215 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
216 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
217 |
JNF_COCOA_ENTER(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
218 |
MetalGraphicsConfigInfo *pInfo = |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
219 |
(MetalGraphicsConfigInfo *)jlong_to_ptr(configInfo); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
220 |
if ((pInfo == NULL)) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
221 |
return -1; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
222 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
223 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
224 |
MetalLayer *mtlLayer = jlong_to_ptr(layer); |
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 |
mtlLayer.device = pInfo->device; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
227 |
mtlLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
228 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
229 |
//mtlLayer.commandQueue = pInfo->commandQueue; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
230 |
|
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 |
// TODO : Currently we manually compile and copy the shader library to /tmp. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
233 |
// Need to complete build changes - to build it and read from some other location within jdk |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
234 |
// ------------------------------------------------------------------------------------------------ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
235 |
// Load shader library |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
236 |
NSError *error = nil; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
237 |
mtlLayer.mtlLibrary = [mtlLayer.device newLibraryWithFile: @"/tmp/MyShader.metallib" error:&error]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
238 |
if (!mtlLayer.mtlLibrary) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
239 |
NSLog(@"Failed to load library. error %@", error); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
240 |
//exit(0); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
241 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
242 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
243 |
//create a vertex and fragment objects |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
244 |
id<MTLFunction> vertexProgram = [mtlLayer.mtlLibrary newFunctionWithName:@"vertexShader"]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
245 |
id<MTLFunction> fragmentProgram = [mtlLayer.mtlLibrary newFunctionWithName:@"fragmentShader"]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
246 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
247 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
248 |
mtlLayer.mtlRenderPipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
249 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
250 |
[mtlLayer.mtlRenderPipelineDescriptor setVertexFunction:vertexProgram]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
251 |
[mtlLayer.mtlRenderPipelineDescriptor setFragmentFunction:fragmentProgram]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
252 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
253 |
//specify the target-texture pixel format |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
254 |
mtlLayer.mtlRenderPipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
255 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
256 |
//create the Rendering Pipeline Object |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
257 |
mtlLayer.renderPipelineState = [mtlLayer.device newRenderPipelineStateWithDescriptor:mtlLayer.mtlRenderPipelineDescriptor error:nil]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
258 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
259 |
VertexDataManager_init(mtlLayer.device); |
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 |
JNF_COCOA_EXIT(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
263 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
264 |
return ptr_to_jlong(layer); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
265 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
266 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
267 |
|
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 |
// Must be called under the RQ lock. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
270 |
/*JNIEXPORT void JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
271 |
Java_sun_java2d_metal_MetalLayer_nativeValidate |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
272 |
(JNIEnv *env, jclass cls, jlong layer, jlong view) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
273 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
274 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
275 |
JNF_COCOA_ENTER(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
276 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
277 |
MetalLayer *mtlLayer = jlong_to_ptr(layer); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
278 |
NSView *nsView = jlong_to_ptr(view); |
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 |
mtlLayer.frame = nsView.bounds; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
281 |
[mtlLayer setDrawableSize: nsView.bounds.size]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
282 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
283 |
mtlLayer.textureWidth = nsView.bounds.size.width; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
284 |
mtlLayer.textureHeight = nsView.bounds.size.height; |
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 |
NSLog(@"Validate : Width : %f", nsView.bounds.size.width); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
287 |
NSLog(@"Validate : Height : %f", nsView.bounds.size.height); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
288 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
289 |
JNF_COCOA_EXIT(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
290 |
}*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
291 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
292 |
// Must be called under the RQ lock. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
293 |
JNIEXPORT void JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
294 |
Java_sun_java2d_metal_MetalLayer_validate |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
295 |
(JNIEnv *env, jclass cls, jlong layerPtr, jobject surfaceData) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
296 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
297 |
MetalLayer *layer = OBJC(layerPtr); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
298 |
//fprintf(stdout, "MetalLayer_validate\n");fflush(stdout); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
299 |
if (surfaceData != NULL) { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
300 |
MetalSDOps *metalsdo = (MetalSDOps*) SurfaceData_GetOps(env, surfaceData); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
301 |
// TODO : Check whether we have to use pointer or instance variable |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
302 |
//fprintf(stdout, "MetalLayer_validate replace mtlTexture\n");fflush(stdout); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
303 |
layer.mtlTexture = metalsdo->mtlTexture; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
304 |
//layer.target = GL_TEXTURE_2D; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
305 |
layer.textureWidth = metalsdo->width; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
306 |
layer.textureHeight = metalsdo->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 |
NSLog(@"Validate : Width : %f", layer.textureWidth); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
309 |
NSLog(@"Validate : height : %f", layer.textureHeight); |
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 |
} else { |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
312 |
//fprintf(stdout, "MetalLayer_validate Null SD \n");fflush(stdout); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
313 |
//layer.textureID = 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 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
316 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
317 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
318 |
|
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 |
// Must be called on the AppKit thread and under the RQ lock. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
321 |
JNIEXPORT void JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
322 |
Java_sun_java2d_opengl_CGLLayer_blitTexture |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
323 |
(JNIEnv *env, jclass cls, jlong layerPtr) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
324 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
325 |
CGLLayer *layer = jlong_to_ptr(layerPtr); |
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 |
[layer blitTexture]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
328 |
}*/ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
329 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
330 |
JNIEXPORT void JNICALL |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
331 |
Java_sun_java2d_metal_MetalLayer_nativeSetScale |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
332 |
(JNIEnv *env, jclass cls, jlong layerPtr, jdouble scale) |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
333 |
{ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
334 |
JNF_COCOA_ENTER(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
335 |
MetalLayer *layer = jlong_to_ptr(layerPtr); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
336 |
// We always call all setXX methods asynchronously, exception is only in |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
337 |
// this method where we need to change native texture size and layer's scale |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
338 |
// in one call on appkit, otherwise we'll get window's contents blinking, |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
339 |
// during screen-2-screen moving. |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
340 |
[ThreadUtilities performOnMainThreadWaiting:[NSThread isMainThread] block:^(){ |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
341 |
layer.contentsScale = scale; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
342 |
}]; |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
343 |
JNF_COCOA_EXIT(env); |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
diff
changeset
|
344 |
} |