├── .gitignore ├── BoingRenderer.h ├── BoingRenderer.m ├── ClientController.h ├── ClientController.m ├── ClientInfo.plist ├── ClientOpenGLView.h ├── ClientOpenGLView.m ├── English.lproj ├── ClientMainMenu.nib │ ├── designable.nib │ └── keyedobjects.nib ├── InfoPlist.strings └── ServerMainMenu.nib │ ├── designable.nib │ └── keyedobjects.nib ├── Info.plist ├── MultiGPU.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── MultiGPU.xccheckout ├── MultiGPUMig.defs ├── MultiGPU_Prefix.pch ├── PatternOpenGLView.m ├── Readme.txt ├── ServerController.h ├── ServerController.m ├── ServerInfo.plist ├── ServerOpenGLView.h ├── ServerOpenGLView.m ├── ServerShaderDefs.h ├── Shaders ├── color.fsh ├── color.vsh ├── gecko.fsh ├── gecko.vsh ├── lighting.vsh ├── pattern.fsh ├── pattern.vsh ├── texture.vsh └── textureRect.fsh ├── UtilSrc ├── debug.h ├── fileUtil.h ├── fileUtil.m ├── shaderUtil.c └── shaderUtil.h └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | /build 4 | -------------------------------------------------------------------------------- /BoingRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: BoingRenderer.h 3 | Abstract: 4 | This class handles the rendering of a Boing ball using Core Profile. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import "ServerShaderDefs.h" 51 | 52 | @interface BoingRenderer : NSObject 53 | 54 | - (void)update; 55 | - (void)render:(programInfo_t *)program; 56 | - (void)makeOrthographicForWidth:(CGFloat)width height:(CGFloat)height; 57 | - (void)initShaders:(programInfo_t *)program; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /BoingRenderer.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: BoingRenderer.m 3 | Abstract: 4 | This class handles the rendering of a Boing ball using Core Profile. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import "BoingRenderer.h" 51 | #import 52 | 53 | typedef struct 54 | { 55 | float x; 56 | float y; 57 | float z; 58 | float nx; 59 | float ny; 60 | float nz; 61 | float r; 62 | float g; 63 | float b; 64 | float a; 65 | } Vertex; 66 | 67 | static float lightDir[3] = { 0.8, 4.0, 1.0 }; 68 | static float ambient[4] = { 0.35, 0.35, 0.35, 0.35 }; 69 | static float diffuse[4] = { 1.0-0.35, 1.0-0.35, 1.0-0.35, 1.0 }; 70 | static float specular[4] = { 0.8, 0.8, 0.8, 1.0 }; 71 | static float shininess = 10.0; 72 | 73 | 74 | @interface BoingRenderer() 75 | { 76 | // Cribbed from BoingX 77 | float angle; 78 | float angleDelta; 79 | float r; 80 | float xPos, yPos; 81 | float xVelocity, yVelocity; 82 | float scaleFactor; 83 | 84 | GLKVector3 lightDirNormalized; 85 | GLKMatrix4 projectionMatrix; 86 | GLuint vboId, vaoId; 87 | } 88 | @end 89 | 90 | @implementation BoingRenderer 91 | 92 | -(void)generateBoingData 93 | { 94 | int x; 95 | int index = 0; 96 | 97 | float v1x, v1y, v1z; 98 | float v2x, v2y, v2z; 99 | float d; 100 | 101 | int theta, phi; 102 | 103 | float theta0, theta1; 104 | float phi0, phi1; 105 | 106 | Vertex quad[4]; 107 | 108 | Vertex *boingData = malloc(8 * 16 * 6 * sizeof(Vertex)); 109 | 110 | float delta = M_PI / 8.0f; 111 | 112 | // 8 vertical segments 113 | for(theta = 0; theta < 8; theta++) 114 | { 115 | theta0 = theta*delta; 116 | theta1 = (theta+1)*delta; 117 | 118 | // 16 horizontal segments 119 | for(phi = 0; phi < 16; phi++) 120 | { 121 | phi0 = phi*delta; 122 | phi1 = (phi+1)*delta; 123 | 124 | // Generate 4 points per quad 125 | quad[0].x = r * sin(theta0)*cos(phi0); 126 | quad[0].y = r * cos(theta0); 127 | quad[0].z = r * sin(theta0)*sin(phi0); 128 | 129 | quad[1].x = r * sin(theta0)*cos(phi1); 130 | quad[1].y = r * cos(theta0); 131 | quad[1].z = r * sin(theta0)*sin(phi1); 132 | 133 | quad[2].x = r * sin(theta1)*cos(phi1); 134 | quad[2].y = r * cos(theta1); 135 | quad[2].z = r * sin(theta1)*sin(phi1); 136 | 137 | quad[3].x = r * sin(theta1)*cos(phi0); 138 | quad[3].y = r * cos(theta1); 139 | quad[3].z = r * sin(theta1)*sin(phi0); 140 | 141 | // Generate normal 142 | if(theta >= 4) 143 | { 144 | v1x = quad[1].x - quad[0].x; 145 | v1y = quad[1].y - quad[0].y; 146 | v1z = quad[1].z - quad[0].z; 147 | 148 | v2x = quad[3].x - quad[0].x; 149 | v2y = quad[3].y - quad[0].y; 150 | v2z = quad[3].z - quad[0].z; 151 | } 152 | else 153 | { 154 | v1x = quad[0].x - quad[3].x; 155 | v1y = quad[0].y - quad[3].y; 156 | v1z = quad[0].z - quad[3].z; 157 | 158 | v2x = quad[2].x - quad[3].x; 159 | v2y = quad[2].y - quad[3].y; 160 | v2z = quad[2].z - quad[3].z; 161 | } 162 | 163 | quad[0].nx = (v1y * v2z) - (v2y * v1z); 164 | quad[0].ny = (v1z * v2x) - (v2z * v1x); 165 | quad[0].nz = (v1x * v2y) - (v2x * v1y); 166 | 167 | d = 1.0f/sqrt(quad[0].nx*quad[0].nx + 168 | quad[0].ny*quad[0].ny + 169 | quad[0].nz*quad[0].nz); 170 | 171 | quad[0].nx *= d; 172 | quad[0].ny *= d; 173 | quad[0].nz *= d; 174 | 175 | // Generate color 176 | if((theta ^ phi) & 1) 177 | { 178 | quad[0].r = 1.0f; 179 | quad[0].g = 1.0f; 180 | quad[0].b = 1.0f; 181 | quad[0].a = 1.0f; 182 | } 183 | else 184 | { 185 | quad[0].r = 1.0f; 186 | quad[0].g = 0.0f; 187 | quad[0].b = 0.0f; 188 | quad[0].a = 1.0f; 189 | } 190 | 191 | // Replicate vertex info 192 | for(x = 1; x < 4; x++) 193 | { 194 | quad[x].nx = quad[0].nx; 195 | quad[x].ny = quad[0].ny; 196 | quad[x].nz = quad[0].nz; 197 | quad[x].r = quad[0].r; 198 | quad[x].g = quad[0].g; 199 | quad[x].b = quad[0].b; 200 | quad[x].a = quad[0].a; 201 | } 202 | 203 | // OpenGL draws triangles under the hood. Core Profile officially drops support 204 | // of the GL_QUADS mode in the glDrawArrays/Elements calls. 205 | // Store vertices as in two consisting triangles 206 | boingData[index++] = quad[0]; 207 | boingData[index++] = quad[1]; 208 | boingData[index++] = quad[2]; 209 | 210 | boingData[index++] = quad[2]; 211 | boingData[index++] = quad[3]; 212 | boingData[index++] = quad[0]; 213 | } 214 | } 215 | 216 | // Create a VAO (vertex array object). 217 | glGenVertexArrays(1, &vaoId); 218 | glBindVertexArray(vaoId); 219 | 220 | // Create a VBO (vertex buffer object) to hold our data. 221 | glGenBuffers(1, &vboId); 222 | glBindBuffer(GL_ARRAY_BUFFER, vboId); 223 | glBufferData(GL_ARRAY_BUFFER, 8 * 16 * 6 * sizeof(Vertex), boingData, GL_STATIC_DRAW); 224 | 225 | // positions 226 | glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLubyte *)(uintptr_t)offsetof(Vertex,x)); 227 | // colors 228 | glVertexAttribPointer(ATTRIB_COLOR, 4, GL_FLOAT, GL_TRUE, sizeof(Vertex), (GLubyte *)(uintptr_t)offsetof(Vertex,r)); 229 | // normals 230 | glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLubyte *)(uintptr_t)offsetof(Vertex,nx)); 231 | 232 | // At this point the VAO is set up with three vertex attributes referencing the same buffer object. 233 | 234 | free(boingData); 235 | } 236 | 237 | - (void)initShaders:(programInfo_t *)program 238 | { 239 | for (int i = 0; i < NUM_PROGRAMS; i++) 240 | { 241 | // set constant uniforms 242 | glUseProgram(program[i].id); 243 | 244 | if (i == PROGRAM_LIGHTING) 245 | { 246 | // Set up lighting stuff used by the shaders 247 | glUniform3fv(program[i].uniform[UNIFORM_LIGHTDIR], 1, lightDirNormalized.v); 248 | glUniform4fv(program[i].uniform[UNIFORM_AMBIENT], 1, ambient); 249 | glUniform4fv(program[i].uniform[UNIFORM_DIFFUSE], 1, diffuse); 250 | glUniform4fv(program[i].uniform[UNIFORM_SPECULAR], 1, specular); 251 | glUniform1f(program[i].uniform[UNIFORM_SHININESS], shininess); 252 | } 253 | else if (i == PROGRAM_PASSTHRU) 254 | { 255 | glUniform4f(program[i].uniform[UNIFORM_CONSTANT_COLOR], 0.0f,0.0f,0.0f,0.4f); 256 | } 257 | } 258 | } 259 | 260 | - (instancetype)init 261 | { 262 | if (self = [super init]) 263 | { 264 | angleDelta = -0.05f; 265 | scaleFactor = 1.6; 266 | r = scaleFactor * 48.0f; 267 | 268 | xVelocity = 1.5f; 269 | yVelocity = 0.0f; 270 | xPos = r*2.0f; 271 | yPos = r*5.0f; 272 | 273 | // normalize light dir 274 | lightDirNormalized = GLKVector3Normalize(GLKVector3MakeWithArray(lightDir)); 275 | 276 | projectionMatrix = GLKMatrix4Identity; 277 | 278 | [self generateBoingData]; 279 | } 280 | return self; 281 | } 282 | 283 | - (void)makeOrthographicForWidth:(CGFloat)width height:(CGFloat)height 284 | { 285 | projectionMatrix = GLKMatrix4MakeOrtho(0, width, 0, height, 0.0f, 2000.0); 286 | } 287 | 288 | - (void)update 289 | { 290 | // Do "physics" stuff 291 | yVelocity -= 0.05f; 292 | 293 | xPos += xVelocity*scaleFactor; 294 | yPos += yVelocity*scaleFactor; 295 | 296 | if(xPos < (r+10.0f)) 297 | { 298 | xPos = r+10.f; 299 | xVelocity = -xVelocity; 300 | angleDelta = -angleDelta; 301 | } 302 | else if(xPos > (310*scaleFactor-r)) 303 | { 304 | xPos = 310*scaleFactor-r; 305 | xVelocity = -xVelocity; 306 | angleDelta = -angleDelta; 307 | } 308 | if(yPos < r) 309 | { 310 | yPos = r; 311 | yVelocity = -yVelocity; 312 | } 313 | 314 | angle += angleDelta; 315 | if(angle < 0.0f) 316 | angle += 360.0f; 317 | else if(angle > 360.0f) 318 | angle -= 360.0f; 319 | } 320 | 321 | - (void)render:(programInfo_t *)program 322 | { 323 | GLKMatrix4 modelViewMatrix, MVPMatrix, modelViewMatrixIT; 324 | GLKMatrix3 normalMatrix; 325 | 326 | glBindVertexArray(vaoId); 327 | 328 | // Draw "shadow" 329 | glUseProgram(program[PROGRAM_PASSTHRU].id); 330 | 331 | glEnable(GL_CULL_FACE); 332 | glDisable(GL_DEPTH_TEST); 333 | glDepthMask(GL_FALSE); 334 | glEnable(GL_BLEND); 335 | glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA); 336 | 337 | // Make the "shadow" move around a bit. This is not a real shadow projection. 338 | GLKVector3 pos = GLKVector3Normalize(GLKVector3Make(xPos, yPos, -100.0f)); 339 | modelViewMatrix = GLKMatrix4MakeTranslation(xPos + (pos.v[0]-lightDirNormalized.v[0])*20.0, 340 | yPos + (pos.v[1]-lightDirNormalized.v[1])*10.0, 341 | -800.0f); 342 | modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, -16.0f, 0.0f, 0.0f, 1.0f); 343 | modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, angle, 0.0f, 1.0f, 0.0f); 344 | modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, 1.05f, 1.05f, 1.05f); 345 | 346 | MVPMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); 347 | glUniformMatrix4fv(program[PROGRAM_PASSTHRU].uniform[UNIFORM_MVP], 1, GL_FALSE, MVPMatrix.m); 348 | 349 | glEnableVertexAttribArray(ATTRIB_VERTEX); 350 | glEnableVertexAttribArray(ATTRIB_COLOR); 351 | 352 | glDrawArrays(GL_TRIANGLES, 0, 8*16*6); 353 | 354 | // Draw real Boing 355 | glUseProgram(program[PROGRAM_LIGHTING].id); 356 | 357 | glEnable(GL_DEPTH_TEST); 358 | glDepthMask(GL_TRUE); 359 | glDepthFunc(GL_LESS); 360 | glDisable(GL_BLEND); 361 | 362 | // ModelView 363 | modelViewMatrix = GLKMatrix4MakeTranslation(xPos, yPos, -100.0f); 364 | modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, -16.0f, 0.0f, 0.0f, 1.0f); 365 | modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, angle, 0.0f, 1.0f, 0.0f); 366 | glUniformMatrix4fv(program[PROGRAM_LIGHTING].uniform[UNIFORM_MODELVIEW], 1, GL_FALSE, modelViewMatrix.m); 367 | 368 | // MVP 369 | MVPMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); 370 | glUniformMatrix4fv(program[PROGRAM_LIGHTING].uniform[UNIFORM_MVP], 1, GL_FALSE, MVPMatrix.m); 371 | 372 | // ModelViewIT (normal matrix) 373 | bool success; 374 | modelViewMatrixIT = GLKMatrix4InvertAndTranspose(modelViewMatrix, &success); 375 | if (success) { 376 | normalMatrix = GLKMatrix4GetMatrix3(modelViewMatrixIT); 377 | glUniformMatrix3fv(program[PROGRAM_LIGHTING].uniform[UNIFORM_MODELVIEWIT], 1, GL_FALSE, normalMatrix.m); 378 | } 379 | 380 | glEnableVertexAttribArray(ATTRIB_NORMAL); 381 | 382 | glDrawArrays(GL_TRIANGLES, 0, 8*16*6); 383 | 384 | glDisableVertexAttribArray(ATTRIB_VERTEX); 385 | glDisableVertexAttribArray(ATTRIB_COLOR); 386 | glDisableVertexAttribArray(ATTRIB_NORMAL); 387 | 388 | glUseProgram(0); 389 | } 390 | 391 | - (void)dealloc 392 | { 393 | if (vboId) { 394 | glDeleteBuffers(1, &vboId); 395 | vboId = 0; 396 | } 397 | if (vaoId) { 398 | glDeleteVertexArrays(1, &vaoId); 399 | vaoId = 0; 400 | } 401 | 402 | [super dealloc]; 403 | } 404 | 405 | @end 406 | -------------------------------------------------------------------------------- /ClientController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ClientController.h 3 | Abstract: 4 | This class implements the controller object for the client application. It is 5 | responsible for looking up the server application, and responding to frame 6 | rendering requests from the server. 7 | 8 | Version: 1.2 9 | 10 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 11 | Inc. ("Apple") in consideration of your agreement to the following 12 | terms, and your use, installation, modification or redistribution of 13 | this Apple software constitutes acceptance of these terms. If you do 14 | not agree with these terms, please do not use, install, modify or 15 | redistribute this Apple software. 16 | 17 | In consideration of your agreement to abide by the following terms, and 18 | subject to these terms, Apple grants you a personal, non-exclusive 19 | license, under Apple's copyrights in this original Apple software (the 20 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 21 | Software, with or without modifications, in source and/or binary forms; 22 | provided that if you redistribute the Apple Software in its entirety and 23 | without modifications, you must retain this notice and the following 24 | text and disclaimers in all such redistributions of the Apple Software. 25 | Neither the name, trademarks, service marks or logos of Apple Inc. may 26 | be used to endorse or promote products derived from the Apple Software 27 | without specific prior written permission from Apple. Except as 28 | expressly stated in this notice, no other rights or licenses, express or 29 | implied, are granted by Apple herein, including but not limited to any 30 | patent rights that may be infringed by your derivative works or by other 31 | works in which the Apple Software may be incorporated. 32 | 33 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 34 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 35 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 36 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 37 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 38 | 39 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 40 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 41 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 42 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 43 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 44 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 45 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 46 | POSSIBILITY OF SUCH DAMAGE. 47 | 48 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 49 | 50 | */ 51 | 52 | #import 53 | #import 54 | #import 55 | 56 | #define NUM_IOSURFACE_BUFFERS 1 57 | 58 | @interface ClientController : NSObject 59 | 60 | @property (NS_NONATOMIC_IOSONLY, readonly) GLuint currentTextureName; 61 | - (void)portDied:(NSNotification *)notification; 62 | - (IBAction)setRenderer:(id)sender; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /ClientController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ClientController.m 3 | Abstract: 4 | This class implements the controller object for the client application. It is 5 | responsible for looking up the server application, and responding to frame 6 | rendering requests from the server. 7 | 8 | Version: 1.2 9 | 10 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 11 | Inc. ("Apple") in consideration of your agreement to the following 12 | terms, and your use, installation, modification or redistribution of 13 | this Apple software constitutes acceptance of these terms. If you do 14 | not agree with these terms, please do not use, install, modify or 15 | redistribute this Apple software. 16 | 17 | In consideration of your agreement to abide by the following terms, and 18 | subject to these terms, Apple grants you a personal, non-exclusive 19 | license, under Apple's copyrights in this original Apple software (the 20 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 21 | Software, with or without modifications, in source and/or binary forms; 22 | provided that if you redistribute the Apple Software in its entirety and 23 | without modifications, you must retain this notice and the following 24 | text and disclaimers in all such redistributions of the Apple Software. 25 | Neither the name, trademarks, service marks or logos of Apple Inc. may 26 | be used to endorse or promote products derived from the Apple Software 27 | without specific prior written permission from Apple. Except as 28 | expressly stated in this notice, no other rights or licenses, express or 29 | implied, are granted by Apple herein, including but not limited to any 30 | patent rights that may be infringed by your derivative works or by other 31 | works in which the Apple Software may be incorporated. 32 | 33 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 34 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 35 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 36 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 37 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 38 | 39 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 40 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 41 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 42 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 43 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 44 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 45 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 46 | POSSIBILITY OF SUCH DAMAGE. 47 | 48 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 49 | 50 | */ 51 | 52 | #import "ClientController.h" 53 | #import "MultiGPUMig.h" 54 | #import "MultiGPUMigServer.h" 55 | #import "ClientOpenGLView.h" 56 | 57 | @interface ClientController() 58 | { 59 | IBOutlet NSWindow *_window; 60 | IBOutlet ClientOpenGLView *_view; 61 | IBOutlet NSPopUpButton *_rendererPopup; 62 | 63 | NSTimer *_timer; 64 | NSMachPort *serverPort; 65 | NSMachPort *localPort; 66 | 67 | uint32_t serverPortName; 68 | uint32_t localPortName; 69 | 70 | int32_t clientIndex; 71 | uint32_t nextFrameIndex; 72 | 73 | IOSurfaceRef _ioSurfaceBuffers[NUM_IOSURFACE_BUFFERS]; 74 | GLuint _textureNames[NUM_IOSURFACE_BUFFERS]; 75 | uint32_t _lastSeed[NUM_IOSURFACE_BUFFERS]; 76 | 77 | uint32_t rendererIndex; 78 | } 79 | @end 80 | 81 | @implementation ClientController 82 | 83 | - (void)applicationWillFinishLaunching:(NSNotification *)note 84 | { 85 | [[NSNotificationCenter defaultCenter] addObserver:self 86 | selector:@selector(portDied:) name:NSPortDidBecomeInvalidNotification object:nil]; 87 | 88 | [_rendererPopup removeAllItems]; 89 | [_rendererPopup addItemsWithTitles:[_view rendererNames]]; 90 | 91 | [_view setRendererIndex:0]; 92 | [_rendererPopup selectItemAtIndex:0]; 93 | } 94 | 95 | - (void)applicationDidFinishLaunching:(NSNotification *)note 96 | { 97 | // Fire up animation timer. 98 | _timer = [[NSTimer timerWithTimeInterval:1.0f/60.0f target:self selector:@selector(animate:) userInfo:nil repeats:YES] retain]; 99 | [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; 100 | } 101 | 102 | 103 | - (void)animate:(NSTimer *)timer 104 | { 105 | [(ClientController *)[NSApp delegate] displayFrame:0 surfaceid:0x9]; 106 | } 107 | 108 | - (void)portDied:(NSNotification *)notification 109 | { 110 | NSPort *port = [notification object]; 111 | if(port == serverPort) 112 | { 113 | [NSApp terminate:self]; 114 | } 115 | } 116 | 117 | - (void)handleMachMessage:(void *)msg 118 | { 119 | union __ReplyUnion___MGCMGSServer_subsystem reply; 120 | 121 | mach_msg_header_t *reply_header = (void *)&reply; 122 | kern_return_t kr; 123 | 124 | if(MGSServer_server(msg, reply_header) && reply_header->msgh_remote_port != MACH_PORT_NULL) 125 | { 126 | kr = mach_msg(reply_header, MACH_SEND_MSG, reply_header->msgh_size, 0, MACH_PORT_NULL, 127 | 0, MACH_PORT_NULL); 128 | if(kr != 0) 129 | [NSApp terminate:nil]; 130 | } 131 | } 132 | 133 | - (kern_return_t)displayFrame:(int32_t)frameIndex surfaceid:(uint32_t)iosurface_id 134 | { 135 | 136 | nextFrameIndex = frameIndex; 137 | 138 | if(!_ioSurfaceBuffers[frameIndex]) 139 | { 140 | fprintf(stderr, "IOSurface: 0x%x\n", iosurface_id); 141 | _ioSurfaceBuffers[frameIndex] = IOSurfaceLookup(iosurface_id); 142 | IOSurfaceRef surface = _ioSurfaceBuffers[frameIndex]; 143 | IOSurfaceIncrementUseCount(surface); 144 | fprintf(stderr, "Use: %u, Count: %u, Size: %u x %u, Format: %u\n", 145 | IOSurfaceIsInUse(surface), 146 | IOSurfaceGetUseCount(surface), 147 | IOSurfaceGetWidth(surface), IOSurfaceGetHeight(surface), 148 | IOSurfaceGetPixelFormat(surface)); 149 | 150 | CGFloat width = IOSurfaceGetWidth(surface); 151 | CGFloat height = IOSurfaceGetHeight(surface); 152 | // NSSize textureSize = NSMakeSize(width, height); 153 | // [_view setBoundsSize:[_view convertSizeFromBacking:textureSize]]; 154 | 155 | NSSize frameSize = [_view frame].size; 156 | NSSize boundsSize = [_view bounds].size; 157 | NSSize backingSize = [_view convertSizeToBacking:[_view bounds].size]; 158 | fprintf(stderr, "Frame: %u x %u, Bounds: %u x %u, Backing: %u x %u\n", 159 | (uint)frameSize.width, (uint)frameSize.height, 160 | (uint)boundsSize.width, (uint)boundsSize.height, 161 | (uint)backingSize.width, (uint)backingSize.height); 162 | 163 | const GLubyte* strVersion = glGetString(GL_VERSION); 164 | fprintf(stderr, "%s\n", strVersion); 165 | } 166 | 167 | IOSurfaceRef surface = _ioSurfaceBuffers[frameIndex]; 168 | uint32_t seed = IOSurfaceGetSeed(surface); 169 | if (_lastSeed[frameIndex] == seed) { 170 | // Surface is unchanged, nothing to do 171 | return 0; 172 | } 173 | _lastSeed[frameIndex] = seed; 174 | 175 | if(!_textureNames[frameIndex]) 176 | _textureNames[frameIndex] = [_view setupIOSurfaceTexture:surface]; 177 | 178 | [_view setNeedsDisplay:YES]; 179 | [_view display]; 180 | 181 | return 0; 182 | } 183 | 184 | // For the clients, this is a no-op. 185 | kern_return_t _MGSCheckinClient(mach_port_t server_port, mach_port_t client_port, 186 | int32_t *client_index) 187 | { 188 | return 0; 189 | } 190 | 191 | kern_return_t _MGSDisplayFrame(mach_port_t server_port, int32_t frame_index, uint32_t iosurface_id) 192 | { 193 | return [(ClientController *)[NSApp delegate] displayFrame:frame_index surfaceid:iosurface_id]; 194 | } 195 | 196 | - (GLuint)currentTextureName 197 | { 198 | return _textureNames[nextFrameIndex]; 199 | } 200 | 201 | - (IBAction)setRenderer:(id)sender 202 | { 203 | [_view setRendererIndex:(rendererIndex = [sender indexOfSelectedItem])]; 204 | } 205 | 206 | @end 207 | -------------------------------------------------------------------------------- /ClientInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.1 23 | NSMainNibFile 24 | ClientMainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /ClientOpenGLView.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ClientOpenGLView.h 3 | Abstract: 4 | This class implements the client specific subclass of NSOpenGLView. 5 | It handles the client side rendering, which calls into the GLUT-based 6 | BluePony rendering code, substituting the contents of an IOSurface from 7 | the server application instead of the OpenGL logo. 8 | 9 | It also shows how to bind IOSurface objects to OpenGL textures. 10 | 11 | Version: 1.2 12 | 13 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 14 | Inc. ("Apple") in consideration of your agreement to the following 15 | terms, and your use, installation, modification or redistribution of 16 | this Apple software constitutes acceptance of these terms. If you do 17 | not agree with these terms, please do not use, install, modify or 18 | redistribute this Apple software. 19 | 20 | In consideration of your agreement to abide by the following terms, and 21 | subject to these terms, Apple grants you a personal, non-exclusive 22 | license, under Apple's copyrights in this original Apple software (the 23 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 24 | Software, with or without modifications, in source and/or binary forms; 25 | provided that if you redistribute the Apple Software in its entirety and 26 | without modifications, you must retain this notice and the following 27 | text and disclaimers in all such redistributions of the Apple Software. 28 | Neither the name, trademarks, service marks or logos of Apple Inc. may 29 | be used to endorse or promote products derived from the Apple Software 30 | without specific prior written permission from Apple. Except as 31 | expressly stated in this notice, no other rights or licenses, express or 32 | implied, are granted by Apple herein, including but not limited to any 33 | patent rights that may be infringed by your derivative works or by other 34 | works in which the Apple Software may be incorporated. 35 | 36 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 37 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 38 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 39 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 40 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 41 | 42 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 43 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 46 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 47 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 48 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 49 | POSSIBILITY OF SUCH DAMAGE. 50 | 51 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 52 | 53 | */ 54 | 55 | #import 56 | #import 57 | 58 | @interface ClientOpenGLView : NSOpenGLView 59 | 60 | - (GLuint)setupIOSurfaceTexture:(IOSurfaceRef)ioSurfaceBuffer; 61 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *rendererNames; 62 | - (void)setRendererIndex:(uint32_t)index; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /ClientOpenGLView.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ClientOpenGLView.m 3 | Abstract: 4 | This class implements the client specific subclass of NSOpenGLView. 5 | It handles the client side rendering, which calls into the GLUT-based 6 | BluePony rendering code, substituting the contents of an IOSurface from 7 | the server application instead of the OpenGL logo. 8 | 9 | It also shows how to bind IOSurface objects to OpenGL textures. 10 | 11 | Version: 1.2 12 | 13 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 14 | Inc. ("Apple") in consideration of your agreement to the following 15 | terms, and your use, installation, modification or redistribution of 16 | this Apple software constitutes acceptance of these terms. If you do 17 | not agree with these terms, please do not use, install, modify or 18 | redistribute this Apple software. 19 | 20 | In consideration of your agreement to abide by the following terms, and 21 | subject to these terms, Apple grants you a personal, non-exclusive 22 | license, under Apple's copyrights in this original Apple software (the 23 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 24 | Software, with or without modifications, in source and/or binary forms; 25 | provided that if you redistribute the Apple Software in its entirety and 26 | without modifications, you must retain this notice and the following 27 | text and disclaimers in all such redistributions of the Apple Software. 28 | Neither the name, trademarks, service marks or logos of Apple Inc. may 29 | be used to endorse or promote products derived from the Apple Software 30 | without specific prior written permission from Apple. Except as 31 | expressly stated in this notice, no other rights or licenses, express or 32 | implied, are granted by Apple herein, including but not limited to any 33 | patent rights that may be infringed by your derivative works or by other 34 | works in which the Apple Software may be incorporated. 35 | 36 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 37 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 38 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 39 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 40 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 41 | 42 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 43 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 46 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 47 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 48 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 49 | POSSIBILITY OF SUCH DAMAGE. 50 | 51 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 52 | 53 | */ 54 | 55 | #import "ClientOpenGLView.h" 56 | #import "ClientController.h" 57 | 58 | #include "shaderUtil.h" 59 | #include "fileUtil.h" 60 | 61 | #import 62 | #import 63 | #import 64 | #import 65 | 66 | // shader info 67 | enum { 68 | PROGRAM_GECKO, 69 | NUM_PROGRAMS 70 | }; 71 | 72 | enum { 73 | UNIFORM_MATRIX_PROJ, 74 | UNIFORM_LAYER_RECTS, 75 | UNIFORM_LAYER_TRANSFORM, 76 | UNIFORM_RENDER_TARGET_OFFSET, 77 | UNIFORM_TEXTURE_TRANSFORM, 78 | UNIFORM_TEXTURE_RECTS, 79 | UNIFORM_TEX_COORD_MULTIPLIER, 80 | UNIFORM_TEXTURE, 81 | NUM_UNIFORMS 82 | }; 83 | 84 | enum { 85 | ATTRIB_COORD, 86 | NUM_ATTRIBS 87 | }; 88 | 89 | typedef struct { 90 | char *vert, *frag; 91 | GLint uniform[NUM_UNIFORMS]; 92 | GLuint id; 93 | } programInfo_t; 94 | 95 | programInfo_t program[NUM_PROGRAMS] = { 96 | { "gecko.vsh", "gecko.fsh" }, // PROGRAM_GECKO 97 | }; 98 | 99 | @interface ClientOpenGLView() 100 | { 101 | GLuint quadVAOId, quadVBOId; 102 | BOOL quadInit; 103 | } 104 | @end 105 | 106 | @implementation ClientOpenGLView 107 | 108 | - (instancetype)initWithFrame:(NSRect)frame 109 | { 110 | NSOpenGLPixelFormat *pix_fmt; 111 | 112 | NSOpenGLPixelFormatAttribute attribs[] = 113 | { 114 | NSOpenGLPFAAllowOfflineRenderers, 115 | NSOpenGLPFAAccelerated, 116 | NSOpenGLPFADoubleBuffer, 117 | // NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 118 | 0 119 | }; 120 | 121 | pix_fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 122 | if(!pix_fmt) 123 | { 124 | [NSApp terminate:nil]; 125 | } 126 | 127 | self = [super initWithFrame:frame pixelFormat:pix_fmt]; 128 | [pix_fmt release]; 129 | 130 | [self setWantsBestResolutionOpenGLSurface:YES]; 131 | 132 | [[self openGLContext] makeCurrentContext]; 133 | 134 | return self; 135 | } 136 | 137 | - (void)prepareOpenGL 138 | { 139 | [super prepareOpenGL]; 140 | 141 | glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, 142 | GL_ONE, GL_ONE); 143 | glEnable(GL_BLEND); 144 | 145 | glGenVertexArrays(1, &quadVAOId); 146 | glGenBuffers(1, &quadVBOId); 147 | 148 | glBindVertexArray(quadVAOId); 149 | 150 | [self setupShaders]; 151 | 152 | glBindVertexArray(0); 153 | } 154 | 155 | - (void)update 156 | { 157 | // Override to do nothing. 158 | } 159 | 160 | - (NSArray *)rendererNames 161 | { 162 | NSMutableArray *rendererNames; 163 | GLint i, numScreens; 164 | 165 | rendererNames = [[NSMutableArray alloc] init]; 166 | 167 | numScreens = [[self pixelFormat] numberOfVirtualScreens]; 168 | for(i = 0; i < numScreens; i++) 169 | { 170 | [[self openGLContext] setCurrentVirtualScreen:i]; 171 | [rendererNames addObject:@((const char *)glGetString(GL_RENDERER))]; 172 | } 173 | 174 | return [rendererNames autorelease]; 175 | } 176 | 177 | - (void)setRendererIndex:(uint32_t)index 178 | { 179 | [[self openGLContext] setCurrentVirtualScreen:index]; 180 | } 181 | 182 | // Create an IOSurface backed texture 183 | - (GLuint)setupIOSurfaceTexture:(IOSurfaceRef)ioSurfaceBuffer 184 | { 185 | NSSize backingSize = [self convertSizeToBacking:[self bounds].size]; 186 | 187 | GLuint name; 188 | CGLContextObj cgl_ctx = (CGLContextObj)[[self openGLContext] CGLContextObj]; 189 | 190 | glGenTextures(1, &name); 191 | 192 | glBindTexture(GL_TEXTURE_RECTANGLE, name); 193 | // At the moment, CGLTexImageIOSurface2D requires the GL_TEXTURE_RECTANGLE target 194 | CGLTexImageIOSurface2D(cgl_ctx, GL_TEXTURE_RECTANGLE, GL_RGBA, 195 | backingSize.width, backingSize.height, GL_BGRA, 196 | GL_UNSIGNED_INT_8_8_8_8_REV, ioSurfaceBuffer, 0); 197 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 198 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 199 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 200 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 201 | 202 | return name; 203 | } 204 | 205 | - (BOOL)isOpaque 206 | { 207 | return YES; 208 | } 209 | 210 | // Render a quad with the the IOSurface backed texture 211 | - (void)renderTextureFromIOSurface 212 | { 213 | NSSize backingSize = [self convertSizeToBacking:[self bounds].size]; 214 | 215 | GLfloat vertices[] = { 216 | 0.0f, 0.0f, 0.0f, 0.0f, 217 | 1.0f, 0.0f, 0.0f, 0.0f, 218 | 0.0f, 1.0f, 0.0f, 0.0f, 219 | 1.0f, 0.0f, 0.0f, 0.0f, 220 | 0.0f, 1.0f, 0.0f, 0.0f, 221 | 1.0f, 1.0f, 0.0f, 0.0f, 222 | 223 | 0.0f, 0.0f, 0.0f, 1.0f, 224 | 1.0f, 0.0f, 0.0f, 1.0f, 225 | 0.0f, 1.0f, 0.0f, 1.0f, 226 | 1.0f, 0.0f, 0.0f, 1.0f, 227 | 0.0f, 1.0f, 0.0f, 1.0f, 228 | 1.0f, 1.0f, 0.0f, 1.0f, 229 | 230 | 0.0f, 0.0f, 0.0f, 2.0f, 231 | 1.0f, 0.0f, 0.0f, 2.0f, 232 | 0.0f, 1.0f, 0.0f, 2.0f, 233 | 1.0f, 0.0f, 0.0f, 2.0f, 234 | 0.0f, 1.0f, 0.0f, 2.0f, 235 | 1.0f, 1.0f, 0.0f, 2.0f, 236 | 237 | 0.0f, 0.0f, 0.0f, 3.0f, 238 | 1.0f, 0.0f, 0.0f, 3.0f, 239 | 0.0f, 1.0f, 0.0f, 3.0f, 240 | 1.0f, 0.0f, 0.0f, 3.0f, 241 | 0.0f, 1.0f, 0.0f, 3.0f, 242 | 1.0f, 1.0f, 0.0f, 3.0f, 243 | }; 244 | 245 | if (!quadInit) { 246 | glBindVertexArray(quadVAOId); 247 | glBindBuffer(GL_ARRAY_BUFFER, quadVBOId); 248 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 249 | quadInit = YES; 250 | } 251 | 252 | glUseProgram(program[PROGRAM_GECKO].id); 253 | 254 | glBindTexture(GL_TEXTURE_RECTANGLE, [(ClientController *)[NSApp delegate] currentTextureName]); 255 | glEnable(GL_TEXTURE_RECTANGLE); 256 | 257 | glBindVertexArray(quadVAOId); 258 | glVertexAttribPointer(ATTRIB_COORD, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*) 0); 259 | glEnableVertexAttribArray(ATTRIB_COORD); 260 | 261 | float layerRects[16] = { 262 | 0, 0, backingSize.width, backingSize.height, 263 | 0, 0, 0, 0, 264 | 0, 0, 0, 0, 265 | 0, 0, 0, 0, 266 | }; 267 | glUniform4fv(program[PROGRAM_GECKO].uniform[UNIFORM_LAYER_RECTS], 4, layerRects); 268 | 269 | float textureRects[16] = { 270 | 0, 0, 1, 1, 271 | 0, 0, 0, 0, 272 | 0, 0, 0, 0, 273 | 0, 0, 0, 0, 274 | }; 275 | glUniform4fv(program[PROGRAM_GECKO].uniform[UNIFORM_TEXTURE_RECTS], 4, textureRects); 276 | 277 | float renderOffset[4] = { 278 | 0, 0, 0, 0, 279 | }; 280 | glUniform4fv(program[PROGRAM_GECKO].uniform[UNIFORM_RENDER_TARGET_OFFSET], 1, renderOffset); 281 | 282 | float textureTransformVals[16] = { 283 | 1, 0, 0, 0, 284 | 0, -1, 0, 0, 285 | 0, 0, 1, 0, 286 | 0, 1, 0, 1, 287 | }; 288 | GLKMatrix4 textureTransform = GLKMatrix4MakeWithArray(textureTransformVals); 289 | glUniformMatrix4fv(program[PROGRAM_GECKO].uniform[UNIFORM_TEXTURE_TRANSFORM], 1, GL_FALSE, textureTransform.m); 290 | 291 | float layerTransformVals[16] = { 292 | 1, 0, 0, 0, 293 | 0, 1, 0, 0, 294 | 0, 0, 1, 0, 295 | 0, 0, 0, 1, 296 | }; 297 | GLKMatrix4 layerTransform = GLKMatrix4MakeWithArray(layerTransformVals); 298 | glUniformMatrix4fv(program[PROGRAM_GECKO].uniform[UNIFORM_LAYER_TRANSFORM], 1, GL_FALSE, layerTransform.m); 299 | 300 | float texCoordMultiplier[2] = { 301 | backingSize.width, backingSize.height, 302 | }; 303 | glUniform2fv(program[PROGRAM_GECKO].uniform[UNIFORM_TEX_COORD_MULTIPLIER], 1, texCoordMultiplier); 304 | 305 | float projectionVals[16] = { 306 | 2 / backingSize.width, 0, 0, 0, 307 | 0, -2 / backingSize.height, 0, 0, 308 | 0, 0, 0, 0, 309 | -1, 1, 0, 1, 310 | }; 311 | GLKMatrix4 projection = GLKMatrix4MakeWithArray(projectionVals); 312 | glUniformMatrix4fv(program[PROGRAM_GECKO].uniform[UNIFORM_MATRIX_PROJ], 1, GL_FALSE, projection.m); 313 | 314 | glUniform1i(program[PROGRAM_GECKO].uniform[UNIFORM_TEXTURE], 0); 315 | 316 | glDrawArrays(GL_TRIANGLES, 0, 6); 317 | 318 | glDisableVertexAttribArray(ATTRIB_COORD); 319 | glDisable(GL_TEXTURE_RECTANGLE); 320 | } 321 | 322 | - (void)drawRect:(NSRect)theRect 323 | { 324 | NSSize backingSize = [self convertSizeToBacking:[self bounds].size]; 325 | glViewport(0, 0, (GLint)backingSize.width, (GLint)backingSize.height); 326 | 327 | [self renderTextureFromIOSurface]; 328 | 329 | [[self openGLContext] flushBuffer]; 330 | } 331 | 332 | - (void)setupShaders 333 | { 334 | for (int i = 0; i < NUM_PROGRAMS; i++) 335 | { 336 | char *vsrc = readFile(pathForResource(program[i].vert)); 337 | char *fsrc = readFile(pathForResource(program[i].frag)); 338 | GLsizei attribCt = 0; 339 | GLchar *attribUsed[NUM_ATTRIBS]; 340 | GLint attrib[NUM_ATTRIBS]; 341 | GLchar *attribName[NUM_ATTRIBS] = { 342 | "aCoord", 343 | }; 344 | const GLchar *uniformName[NUM_UNIFORMS] = { 345 | "uMatrixProj", 346 | "uLayerRects", 347 | "uLayerTransform", 348 | "uRenderTargetOffset", 349 | "uTextureTransform", 350 | "uTextureRects", 351 | "uTexCoordMultiplier", 352 | "uTexture", 353 | }; 354 | 355 | // auto-assign known attribs 356 | for (int j = 0; j < NUM_ATTRIBS; j++) 357 | { 358 | if (strstr(vsrc, attribName[j])) 359 | { 360 | attrib[attribCt] = j; 361 | attribUsed[attribCt++] = attribName[j]; 362 | } 363 | } 364 | 365 | glueCreateProgram(vsrc, fsrc, 366 | attribCt, (const GLchar **)&attribUsed[0], attrib, 367 | NUM_UNIFORMS, &uniformName[0], program[i].uniform, 368 | &program[i].id); 369 | free(vsrc); 370 | free(fsrc); 371 | } 372 | } 373 | 374 | @end 375 | -------------------------------------------------------------------------------- /English.lproj/ClientMainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jryans/iosurface-example/260feee70acbba472b151ccddf9a672ace2364bf/English.lproj/ClientMainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jryans/iosurface-example/260feee70acbba472b151ccddf9a672ace2364bf/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /English.lproj/ServerMainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jryans/iosurface-example/260feee70acbba472b151ccddf9a672ace2364bf/English.lproj/ServerMainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MultiGPU.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXAggregateTarget section */ 10 | 4F0934CC11BEC75E00897344 /* MultiGPUApps */ = { 11 | isa = PBXAggregateTarget; 12 | buildConfigurationList = 4F0934D311BEC78300897344 /* Build configuration list for PBXAggregateTarget "MultiGPUApps" */; 13 | buildPhases = ( 14 | ); 15 | dependencies = ( 16 | 4F0934D211BEC76500897344 /* PBXTargetDependency */, 17 | 4F0934D011BEC76300897344 /* PBXTargetDependency */, 18 | ); 19 | name = MultiGPUApps; 20 | productName = MultiGPUApps; 21 | }; 22 | /* End PBXAggregateTarget section */ 23 | 24 | /* Begin PBXBuildFile section */ 25 | 4F0934B611BEC6EB00897344 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 26 | 4F0934B811BEC6EB00897344 /* MultiGPUMig.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4F0A38480DDE41BB0081E0D7 /* MultiGPUMig.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; }; 27 | 4F0934B911BEC6EB00897344 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 28 | 4F0934C311BEC6EB00897344 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 29 | 4F0934C411BEC6EB00897344 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F0A38780DDE436A0081E0D7 /* OpenGL.framework */; }; 30 | 4F0934C511BEC6EB00897344 /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FD5FEBF0E36D44F0048611E /* IOSurface.framework */; }; 31 | 4F0934EF11BEC7E500897344 /* ServerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F0934EC11BEC7E500897344 /* ServerController.m */; }; 32 | 4F0934F011BEC7E500897344 /* ServerOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F0934EE11BEC7E500897344 /* ServerOpenGLView.m */; }; 33 | 4F09350B11BEC8BB00897344 /* ClientMainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 4F09350911BEC8BB00897344 /* ClientMainMenu.nib */; }; 34 | 4F09352211BEC97600897344 /* ClientController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F09350411BEC85500897344 /* ClientController.m */; }; 35 | 4F09352311BEC97600897344 /* ClientOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F09350611BEC85500897344 /* ClientOpenGLView.m */; }; 36 | 4F0A38790DDE436A0081E0D7 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F0A38780DDE436A0081E0D7 /* OpenGL.framework */; }; 37 | 4FD5FE9A0E36D37A0048611E /* MultiGPUMig.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4F0A38480DDE41BB0081E0D7 /* MultiGPUMig.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; }; 38 | 4FD5FEC00E36D44F0048611E /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FD5FEBF0E36D44F0048611E /* IOSurface.framework */; }; 39 | 8D11072A0486CEB800E47090 /* ServerMainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* ServerMainMenu.nib */; }; 40 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 41 | 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 42 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 43 | AF40202A19A7EBB700C3897E /* textureRect.fsh in Resources */ = {isa = PBXBuildFile; fileRef = AF40202819A7EBB700C3897E /* textureRect.fsh */; }; 44 | AF40202B19A7EBB700C3897E /* texture.vsh in Resources */ = {isa = PBXBuildFile; fileRef = AF40202919A7EBB700C3897E /* texture.vsh */; }; 45 | AF7DA64819AFD3AD0012507E /* shaderUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0619A6787D006767EF /* shaderUtil.c */; }; 46 | AF7DA64919AFD3AD0012507E /* fileUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0519A6787D006767EF /* fileUtil.m */; }; 47 | AF7DA64A19AFD3C30012507E /* textureRect.fsh in Resources */ = {isa = PBXBuildFile; fileRef = AF40202819A7EBB700C3897E /* textureRect.fsh */; }; 48 | AF7DA64B19AFD3C30012507E /* texture.vsh in Resources */ = {isa = PBXBuildFile; fileRef = AF40202919A7EBB700C3897E /* texture.vsh */; }; 49 | AFBA475019A682530075254B /* BoingRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0919A678AE006767EF /* BoingRenderer.m */; }; 50 | AFBA475119A682860075254B /* shaderUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0619A6787D006767EF /* shaderUtil.c */; }; 51 | AFBA475219A682860075254B /* fileUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0519A6787D006767EF /* fileUtil.m */; }; 52 | AFBA475619A696D90075254B /* color.fsh in Resources */ = {isa = PBXBuildFile; fileRef = AFBA475319A693330075254B /* color.fsh */; }; 53 | AFBA475719A696D90075254B /* color.vsh in Resources */ = {isa = PBXBuildFile; fileRef = AFBA475419A693330075254B /* color.vsh */; }; 54 | AFBA475819A696D90075254B /* lighting.vsh in Resources */ = {isa = PBXBuildFile; fileRef = AFBA475519A693330075254B /* lighting.vsh */; }; 55 | AFF7EB1219A67D39006767EF /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1119A67D39006767EF /* GLKit.framework */; }; 56 | AFF7EB1319A67D6E006767EF /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1119A67D39006767EF /* GLKit.framework */; }; 57 | AFF7EB1519A67DB2006767EF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1419A67DB2006767EF /* Foundation.framework */; }; 58 | AFF7EB1619A67DBB006767EF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1419A67DB2006767EF /* Foundation.framework */; }; 59 | BF48664A1AFB103E004BC0CD /* pattern.vsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866481AFB1013004BC0CD /* pattern.vsh */; }; 60 | BF48664B1AFB103E004BC0CD /* pattern.fsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866491AFB1020004BC0CD /* pattern.fsh */; }; 61 | BF48664C1AFB1190004BC0CD /* pattern.vsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866481AFB1013004BC0CD /* pattern.vsh */; }; 62 | BF48664D1AFB1190004BC0CD /* pattern.fsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866491AFB1020004BC0CD /* pattern.fsh */; }; 63 | BF4866511AFB1A7A004BC0CD /* pattern.vsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866481AFB1013004BC0CD /* pattern.vsh */; }; 64 | BF4866521AFB1A7A004BC0CD /* pattern.fsh in Resources */ = {isa = PBXBuildFile; fileRef = BF4866491AFB1020004BC0CD /* pattern.fsh */; }; 65 | BF4866571AFB1A7A004BC0CD /* ServerMainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* ServerMainMenu.nib */; }; 66 | BF4866581AFB1A7A004BC0CD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 67 | BF48665B1AFB1A7A004BC0CD /* shaderUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0619A6787D006767EF /* shaderUtil.c */; }; 68 | BF48665C1AFB1A7A004BC0CD /* fileUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF7EB0519A6787D006767EF /* fileUtil.m */; }; 69 | BF48665E1AFB1A7A004BC0CD /* MultiGPUMig.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4F0A38480DDE41BB0081E0D7 /* MultiGPUMig.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; }; 70 | BF48665F1AFB1A7A004BC0CD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 71 | BF4866601AFB1A7A004BC0CD /* ServerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F0934EC11BEC7E500897344 /* ServerController.m */; }; 72 | BF4866631AFB1A7A004BC0CD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1419A67DB2006767EF /* Foundation.framework */; }; 73 | BF4866641AFB1A7A004BC0CD /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFF7EB1119A67D39006767EF /* GLKit.framework */; }; 74 | BF4866651AFB1A7A004BC0CD /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 75 | BF4866661AFB1A7A004BC0CD /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F0A38780DDE436A0081E0D7 /* OpenGL.framework */; }; 76 | BF4866671AFB1A7A004BC0CD /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FD5FEBF0E36D44F0048611E /* IOSurface.framework */; }; 77 | BF48666F1AFB1CA8004BC0CD /* PatternOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = BF48666E1AFB1C2B004BC0CD /* PatternOpenGLView.m */; }; 78 | BFFFF7B51AF9238E0022A0C6 /* gecko.vsh in Resources */ = {isa = PBXBuildFile; fileRef = BFFFF7B31AF91E580022A0C6 /* gecko.vsh */; }; 79 | BFFFF7B61AF9238E0022A0C6 /* gecko.fsh in Resources */ = {isa = PBXBuildFile; fileRef = BFFFF7B41AF91E840022A0C6 /* gecko.fsh */; }; 80 | /* End PBXBuildFile section */ 81 | 82 | /* Begin PBXContainerItemProxy section */ 83 | 4F0934CF11BEC76300897344 /* PBXContainerItemProxy */ = { 84 | isa = PBXContainerItemProxy; 85 | containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; 86 | proxyType = 1; 87 | remoteGlobalIDString = 8D1107260486CEB800E47090; 88 | remoteInfo = MultiGPUServer; 89 | }; 90 | 4F0934D111BEC76500897344 /* PBXContainerItemProxy */ = { 91 | isa = PBXContainerItemProxy; 92 | containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; 93 | proxyType = 1; 94 | remoteGlobalIDString = 4F0934B311BEC6EB00897344; 95 | remoteInfo = MultiGPUClient; 96 | }; 97 | /* End PBXContainerItemProxy section */ 98 | 99 | /* Begin PBXFileReference section */ 100 | 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 101 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 102 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 103 | 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/ServerMainMenu.nib; sourceTree = ""; }; 104 | 32CA4F630368D1EE00C91783 /* MultiGPU_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultiGPU_Prefix.pch; sourceTree = ""; }; 105 | 4F0934C911BEC6EB00897344 /* MultiGPUClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultiGPUClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; 106 | 4F0934EB11BEC7E500897344 /* ServerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerController.h; sourceTree = ""; }; 107 | 4F0934EC11BEC7E500897344 /* ServerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ServerController.m; sourceTree = ""; }; 108 | 4F0934ED11BEC7E500897344 /* ServerOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerOpenGLView.h; sourceTree = ""; }; 109 | 4F0934EE11BEC7E500897344 /* ServerOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ServerOpenGLView.m; sourceTree = ""; }; 110 | 4F09350311BEC85500897344 /* ClientController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClientController.h; sourceTree = ""; }; 111 | 4F09350411BEC85500897344 /* ClientController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ClientController.m; sourceTree = ""; }; 112 | 4F09350511BEC85500897344 /* ClientOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClientOpenGLView.h; sourceTree = ""; }; 113 | 4F09350611BEC85500897344 /* ClientOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ClientOpenGLView.m; sourceTree = ""; }; 114 | 4F09350A11BEC8BB00897344 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/ClientMainMenu.nib; sourceTree = ""; }; 115 | 4F0935A111BECAAA00897344 /* ClientInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ClientInfo.plist; sourceTree = ""; }; 116 | 4F0A38480DDE41BB0081E0D7 /* MultiGPUMig.defs */ = {isa = PBXFileReference; explicitFileType = sourcecode.mig; fileEncoding = 4; path = MultiGPUMig.defs; sourceTree = ""; }; 117 | 4F0A38780DDE436A0081E0D7 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = ""; }; 118 | 4FD5FEBF0E36D44F0048611E /* IOSurface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOSurface.framework; path = /System/Library/Frameworks/IOSurface.framework; sourceTree = ""; }; 119 | 8D1107310486CEB800E47090 /* ServerInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ServerInfo.plist; sourceTree = ""; }; 120 | 8D1107320486CEB800E47090 /* MultiGPUServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultiGPUServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 121 | AF40202819A7EBB700C3897E /* textureRect.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = textureRect.fsh; path = Shaders/textureRect.fsh; sourceTree = ""; }; 122 | AF40202919A7EBB700C3897E /* texture.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = texture.vsh; path = Shaders/texture.vsh; sourceTree = ""; }; 123 | AF88AD9A19A8342F008AD99D /* ServerShaderDefs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerShaderDefs.h; sourceTree = ""; }; 124 | AFBA475319A693330075254B /* color.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = color.fsh; path = Shaders/color.fsh; sourceTree = ""; }; 125 | AFBA475419A693330075254B /* color.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = color.vsh; path = Shaders/color.vsh; sourceTree = ""; }; 126 | AFBA475519A693330075254B /* lighting.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = lighting.vsh; path = Shaders/lighting.vsh; sourceTree = ""; }; 127 | AFF7EB0319A6787D006767EF /* debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = debug.h; sourceTree = ""; }; 128 | AFF7EB0419A6787D006767EF /* fileUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fileUtil.h; sourceTree = ""; }; 129 | AFF7EB0519A6787D006767EF /* fileUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = fileUtil.m; sourceTree = ""; }; 130 | AFF7EB0619A6787D006767EF /* shaderUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = shaderUtil.c; sourceTree = ""; }; 131 | AFF7EB0719A6787D006767EF /* shaderUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shaderUtil.h; sourceTree = ""; }; 132 | AFF7EB0819A678AE006767EF /* BoingRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoingRenderer.h; sourceTree = ""; }; 133 | AFF7EB0919A678AE006767EF /* BoingRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BoingRenderer.m; sourceTree = ""; }; 134 | AFF7EB1119A67D39006767EF /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; 135 | AFF7EB1419A67DB2006767EF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 136 | BF4866481AFB1013004BC0CD /* pattern.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = pattern.vsh; path = Shaders/pattern.vsh; sourceTree = ""; }; 137 | BF4866491AFB1020004BC0CD /* pattern.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = pattern.fsh; path = Shaders/pattern.fsh; sourceTree = ""; }; 138 | BF48666B1AFB1A7A004BC0CD /* MultiGPUPattern.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultiGPUPattern.app; sourceTree = BUILT_PRODUCTS_DIR; }; 139 | BF48666E1AFB1C2B004BC0CD /* PatternOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PatternOpenGLView.m; sourceTree = ""; }; 140 | BFFFF7B31AF91E580022A0C6 /* gecko.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = gecko.vsh; path = Shaders/gecko.vsh; sourceTree = ""; }; 141 | BFFFF7B41AF91E840022A0C6 /* gecko.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = gecko.fsh; path = Shaders/gecko.fsh; sourceTree = ""; }; 142 | /* End PBXFileReference section */ 143 | 144 | /* Begin PBXFrameworksBuildPhase section */ 145 | 4F0934C211BEC6EB00897344 /* Frameworks */ = { 146 | isa = PBXFrameworksBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | AFF7EB1619A67DBB006767EF /* Foundation.framework in Frameworks */, 150 | AFF7EB1319A67D6E006767EF /* GLKit.framework in Frameworks */, 151 | 4F0934C311BEC6EB00897344 /* Cocoa.framework in Frameworks */, 152 | 4F0934C411BEC6EB00897344 /* OpenGL.framework in Frameworks */, 153 | 4F0934C511BEC6EB00897344 /* IOSurface.framework in Frameworks */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 158 | isa = PBXFrameworksBuildPhase; 159 | buildActionMask = 2147483647; 160 | files = ( 161 | AFF7EB1519A67DB2006767EF /* Foundation.framework in Frameworks */, 162 | AFF7EB1219A67D39006767EF /* GLKit.framework in Frameworks */, 163 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 164 | 4F0A38790DDE436A0081E0D7 /* OpenGL.framework in Frameworks */, 165 | 4FD5FEC00E36D44F0048611E /* IOSurface.framework in Frameworks */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | BF4866621AFB1A7A004BC0CD /* Frameworks */ = { 170 | isa = PBXFrameworksBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | BF4866631AFB1A7A004BC0CD /* Foundation.framework in Frameworks */, 174 | BF4866641AFB1A7A004BC0CD /* GLKit.framework in Frameworks */, 175 | BF4866651AFB1A7A004BC0CD /* Cocoa.framework in Frameworks */, 176 | BF4866661AFB1A7A004BC0CD /* OpenGL.framework in Frameworks */, 177 | BF4866671AFB1A7A004BC0CD /* IOSurface.framework in Frameworks */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXFrameworksBuildPhase section */ 182 | 183 | /* Begin PBXGroup section */ 184 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 185 | isa = PBXGroup; 186 | children = ( 187 | AFF7EB1119A67D39006767EF /* GLKit.framework */, 188 | 4FD5FEBF0E36D44F0048611E /* IOSurface.framework */, 189 | 4F0A38780DDE436A0081E0D7 /* OpenGL.framework */, 190 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, 191 | AFF7EB1419A67DB2006767EF /* Foundation.framework */, 192 | ); 193 | name = "Linked Frameworks"; 194 | sourceTree = ""; 195 | }; 196 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 197 | isa = PBXGroup; 198 | children = ( 199 | 8D1107320486CEB800E47090 /* MultiGPUServer.app */, 200 | 4F0934C911BEC6EB00897344 /* MultiGPUClient.app */, 201 | BF48666B1AFB1A7A004BC0CD /* MultiGPUPattern.app */, 202 | ); 203 | name = Products; 204 | sourceTree = ""; 205 | }; 206 | 29B97314FDCFA39411CA2CEA /* MultiGPU */ = { 207 | isa = PBXGroup; 208 | children = ( 209 | 4F09350211BEC83E00897344 /* ClientClasses */, 210 | 4F0934EA11BEC7C600897344 /* ServerClasses */, 211 | AF7DA64C19AFE0990012507E /* Shaders */, 212 | 4F0934A611BEC5EC00897344 /* Common */, 213 | 29B97317FDCFA39411CA2CEA /* Resources */, 214 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 215 | 19C28FACFE9D520D11CA2CBB /* Products */, 216 | ); 217 | name = MultiGPU; 218 | sourceTree = ""; 219 | }; 220 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 221 | isa = PBXGroup; 222 | children = ( 223 | 4F0935A111BECAAA00897344 /* ClientInfo.plist */, 224 | 4F09350911BEC8BB00897344 /* ClientMainMenu.nib */, 225 | 8D1107310486CEB800E47090 /* ServerInfo.plist */, 226 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 227 | 29B97318FDCFA39411CA2CEA /* ServerMainMenu.nib */, 228 | ); 229 | name = Resources; 230 | sourceTree = ""; 231 | }; 232 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 233 | isa = PBXGroup; 234 | children = ( 235 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 236 | ); 237 | name = Frameworks; 238 | sourceTree = ""; 239 | }; 240 | 4F0934A611BEC5EC00897344 /* Common */ = { 241 | isa = PBXGroup; 242 | children = ( 243 | AFF7EB0219A6787D006767EF /* UtilSrc */, 244 | 4F0A38480DDE41BB0081E0D7 /* MultiGPUMig.defs */, 245 | 29B97316FDCFA39411CA2CEA /* main.m */, 246 | 32CA4F630368D1EE00C91783 /* MultiGPU_Prefix.pch */, 247 | ); 248 | name = Common; 249 | sourceTree = ""; 250 | }; 251 | 4F0934EA11BEC7C600897344 /* ServerClasses */ = { 252 | isa = PBXGroup; 253 | children = ( 254 | 4F0934EB11BEC7E500897344 /* ServerController.h */, 255 | 4F0934EC11BEC7E500897344 /* ServerController.m */, 256 | 4F0934ED11BEC7E500897344 /* ServerOpenGLView.h */, 257 | 4F0934EE11BEC7E500897344 /* ServerOpenGLView.m */, 258 | AFF7EB0819A678AE006767EF /* BoingRenderer.h */, 259 | AFF7EB0919A678AE006767EF /* BoingRenderer.m */, 260 | AF88AD9A19A8342F008AD99D /* ServerShaderDefs.h */, 261 | BF48666E1AFB1C2B004BC0CD /* PatternOpenGLView.m */, 262 | ); 263 | name = ServerClasses; 264 | sourceTree = ""; 265 | }; 266 | 4F09350211BEC83E00897344 /* ClientClasses */ = { 267 | isa = PBXGroup; 268 | children = ( 269 | 4F09350311BEC85500897344 /* ClientController.h */, 270 | 4F09350411BEC85500897344 /* ClientController.m */, 271 | 4F09350511BEC85500897344 /* ClientOpenGLView.h */, 272 | 4F09350611BEC85500897344 /* ClientOpenGLView.m */, 273 | ); 274 | name = ClientClasses; 275 | sourceTree = ""; 276 | }; 277 | AF7DA64C19AFE0990012507E /* Shaders */ = { 278 | isa = PBXGroup; 279 | children = ( 280 | AF40202819A7EBB700C3897E /* textureRect.fsh */, 281 | AF40202919A7EBB700C3897E /* texture.vsh */, 282 | AFBA475319A693330075254B /* color.fsh */, 283 | AFBA475419A693330075254B /* color.vsh */, 284 | AFBA475519A693330075254B /* lighting.vsh */, 285 | BFFFF7B31AF91E580022A0C6 /* gecko.vsh */, 286 | BFFFF7B41AF91E840022A0C6 /* gecko.fsh */, 287 | BF4866481AFB1013004BC0CD /* pattern.vsh */, 288 | BF4866491AFB1020004BC0CD /* pattern.fsh */, 289 | ); 290 | name = Shaders; 291 | sourceTree = ""; 292 | }; 293 | AFF7EB0219A6787D006767EF /* UtilSrc */ = { 294 | isa = PBXGroup; 295 | children = ( 296 | AFF7EB0719A6787D006767EF /* shaderUtil.h */, 297 | AFF7EB0619A6787D006767EF /* shaderUtil.c */, 298 | AFF7EB0419A6787D006767EF /* fileUtil.h */, 299 | AFF7EB0519A6787D006767EF /* fileUtil.m */, 300 | AFF7EB0319A6787D006767EF /* debug.h */, 301 | ); 302 | path = UtilSrc; 303 | sourceTree = ""; 304 | }; 305 | /* End PBXGroup section */ 306 | 307 | /* Begin PBXNativeTarget section */ 308 | 4F0934B311BEC6EB00897344 /* MultiGPUClient */ = { 309 | isa = PBXNativeTarget; 310 | buildConfigurationList = 4F0934C611BEC6EB00897344 /* Build configuration list for PBXNativeTarget "MultiGPUClient" */; 311 | buildPhases = ( 312 | 4F0934B411BEC6EB00897344 /* Resources */, 313 | 4F0934B711BEC6EB00897344 /* Sources */, 314 | 4F0934C211BEC6EB00897344 /* Frameworks */, 315 | ); 316 | buildRules = ( 317 | ); 318 | dependencies = ( 319 | ); 320 | name = MultiGPUClient; 321 | productInstallPath = "$(HOME)/Applications"; 322 | productName = MultiGPU; 323 | productReference = 4F0934C911BEC6EB00897344 /* MultiGPUClient.app */; 324 | productType = "com.apple.product-type.application"; 325 | }; 326 | 8D1107260486CEB800E47090 /* MultiGPUServer */ = { 327 | isa = PBXNativeTarget; 328 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "MultiGPUServer" */; 329 | buildPhases = ( 330 | 8D1107290486CEB800E47090 /* Resources */, 331 | 8D11072C0486CEB800E47090 /* Sources */, 332 | 8D11072E0486CEB800E47090 /* Frameworks */, 333 | ); 334 | buildRules = ( 335 | ); 336 | dependencies = ( 337 | ); 338 | name = MultiGPUServer; 339 | productInstallPath = "$(HOME)/Applications"; 340 | productName = MultiGPU; 341 | productReference = 8D1107320486CEB800E47090 /* MultiGPUServer.app */; 342 | productType = "com.apple.product-type.application"; 343 | }; 344 | BF48664F1AFB1A7A004BC0CD /* MultiGPUPattern */ = { 345 | isa = PBXNativeTarget; 346 | buildConfigurationList = BF4866681AFB1A7A004BC0CD /* Build configuration list for PBXNativeTarget "MultiGPUPattern" */; 347 | buildPhases = ( 348 | BF4866501AFB1A7A004BC0CD /* Resources */, 349 | BF48665A1AFB1A7A004BC0CD /* Sources */, 350 | BF4866621AFB1A7A004BC0CD /* Frameworks */, 351 | ); 352 | buildRules = ( 353 | ); 354 | dependencies = ( 355 | ); 356 | name = MultiGPUPattern; 357 | productInstallPath = "$(HOME)/Applications"; 358 | productName = MultiGPU; 359 | productReference = BF48666B1AFB1A7A004BC0CD /* MultiGPUPattern.app */; 360 | productType = "com.apple.product-type.application"; 361 | }; 362 | /* End PBXNativeTarget section */ 363 | 364 | /* Begin PBXProject section */ 365 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 366 | isa = PBXProject; 367 | attributes = { 368 | LastUpgradeCheck = 0610; 369 | }; 370 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MultiGPU" */; 371 | compatibilityVersion = "Xcode 3.2"; 372 | developmentRegion = English; 373 | hasScannedForEncodings = 1; 374 | knownRegions = ( 375 | English, 376 | Japanese, 377 | French, 378 | German, 379 | ); 380 | mainGroup = 29B97314FDCFA39411CA2CEA /* MultiGPU */; 381 | projectDirPath = ""; 382 | projectRoot = ""; 383 | targets = ( 384 | 4F0934CC11BEC75E00897344 /* MultiGPUApps */, 385 | 8D1107260486CEB800E47090 /* MultiGPUServer */, 386 | 4F0934B311BEC6EB00897344 /* MultiGPUClient */, 387 | BF48664F1AFB1A7A004BC0CD /* MultiGPUPattern */, 388 | ); 389 | }; 390 | /* End PBXProject section */ 391 | 392 | /* Begin PBXResourcesBuildPhase section */ 393 | 4F0934B411BEC6EB00897344 /* Resources */ = { 394 | isa = PBXResourcesBuildPhase; 395 | buildActionMask = 2147483647; 396 | files = ( 397 | BF48664A1AFB103E004BC0CD /* pattern.vsh in Resources */, 398 | BF48664B1AFB103E004BC0CD /* pattern.fsh in Resources */, 399 | BFFFF7B51AF9238E0022A0C6 /* gecko.vsh in Resources */, 400 | BFFFF7B61AF9238E0022A0C6 /* gecko.fsh in Resources */, 401 | AF7DA64A19AFD3C30012507E /* textureRect.fsh in Resources */, 402 | AF7DA64B19AFD3C30012507E /* texture.vsh in Resources */, 403 | 4F0934B611BEC6EB00897344 /* InfoPlist.strings in Resources */, 404 | 4F09350B11BEC8BB00897344 /* ClientMainMenu.nib in Resources */, 405 | ); 406 | runOnlyForDeploymentPostprocessing = 0; 407 | }; 408 | 8D1107290486CEB800E47090 /* Resources */ = { 409 | isa = PBXResourcesBuildPhase; 410 | buildActionMask = 2147483647; 411 | files = ( 412 | BF48664C1AFB1190004BC0CD /* pattern.vsh in Resources */, 413 | BF48664D1AFB1190004BC0CD /* pattern.fsh in Resources */, 414 | AFBA475619A696D90075254B /* color.fsh in Resources */, 415 | AFBA475719A696D90075254B /* color.vsh in Resources */, 416 | AFBA475819A696D90075254B /* lighting.vsh in Resources */, 417 | AF40202A19A7EBB700C3897E /* textureRect.fsh in Resources */, 418 | 8D11072A0486CEB800E47090 /* ServerMainMenu.nib in Resources */, 419 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 420 | AF40202B19A7EBB700C3897E /* texture.vsh in Resources */, 421 | ); 422 | runOnlyForDeploymentPostprocessing = 0; 423 | }; 424 | BF4866501AFB1A7A004BC0CD /* Resources */ = { 425 | isa = PBXResourcesBuildPhase; 426 | buildActionMask = 2147483647; 427 | files = ( 428 | BF4866511AFB1A7A004BC0CD /* pattern.vsh in Resources */, 429 | BF4866521AFB1A7A004BC0CD /* pattern.fsh in Resources */, 430 | BF4866571AFB1A7A004BC0CD /* ServerMainMenu.nib in Resources */, 431 | BF4866581AFB1A7A004BC0CD /* InfoPlist.strings in Resources */, 432 | ); 433 | runOnlyForDeploymentPostprocessing = 0; 434 | }; 435 | /* End PBXResourcesBuildPhase section */ 436 | 437 | /* Begin PBXSourcesBuildPhase section */ 438 | 4F0934B711BEC6EB00897344 /* Sources */ = { 439 | isa = PBXSourcesBuildPhase; 440 | buildActionMask = 2147483647; 441 | files = ( 442 | AF7DA64819AFD3AD0012507E /* shaderUtil.c in Sources */, 443 | AF7DA64919AFD3AD0012507E /* fileUtil.m in Sources */, 444 | 4F0934B811BEC6EB00897344 /* MultiGPUMig.defs in Sources */, 445 | 4F0934B911BEC6EB00897344 /* main.m in Sources */, 446 | 4F09352211BEC97600897344 /* ClientController.m in Sources */, 447 | 4F09352311BEC97600897344 /* ClientOpenGLView.m in Sources */, 448 | ); 449 | runOnlyForDeploymentPostprocessing = 0; 450 | }; 451 | 8D11072C0486CEB800E47090 /* Sources */ = { 452 | isa = PBXSourcesBuildPhase; 453 | buildActionMask = 2147483647; 454 | files = ( 455 | AFBA475119A682860075254B /* shaderUtil.c in Sources */, 456 | AFBA475219A682860075254B /* fileUtil.m in Sources */, 457 | AFBA475019A682530075254B /* BoingRenderer.m in Sources */, 458 | 4FD5FE9A0E36D37A0048611E /* MultiGPUMig.defs in Sources */, 459 | 8D11072D0486CEB800E47090 /* main.m in Sources */, 460 | 4F0934EF11BEC7E500897344 /* ServerController.m in Sources */, 461 | 4F0934F011BEC7E500897344 /* ServerOpenGLView.m in Sources */, 462 | ); 463 | runOnlyForDeploymentPostprocessing = 0; 464 | }; 465 | BF48665A1AFB1A7A004BC0CD /* Sources */ = { 466 | isa = PBXSourcesBuildPhase; 467 | buildActionMask = 2147483647; 468 | files = ( 469 | BF48666F1AFB1CA8004BC0CD /* PatternOpenGLView.m in Sources */, 470 | BF48665B1AFB1A7A004BC0CD /* shaderUtil.c in Sources */, 471 | BF48665C1AFB1A7A004BC0CD /* fileUtil.m in Sources */, 472 | BF48665E1AFB1A7A004BC0CD /* MultiGPUMig.defs in Sources */, 473 | BF48665F1AFB1A7A004BC0CD /* main.m in Sources */, 474 | BF4866601AFB1A7A004BC0CD /* ServerController.m in Sources */, 475 | ); 476 | runOnlyForDeploymentPostprocessing = 0; 477 | }; 478 | /* End PBXSourcesBuildPhase section */ 479 | 480 | /* Begin PBXTargetDependency section */ 481 | 4F0934D011BEC76300897344 /* PBXTargetDependency */ = { 482 | isa = PBXTargetDependency; 483 | target = 8D1107260486CEB800E47090 /* MultiGPUServer */; 484 | targetProxy = 4F0934CF11BEC76300897344 /* PBXContainerItemProxy */; 485 | }; 486 | 4F0934D211BEC76500897344 /* PBXTargetDependency */ = { 487 | isa = PBXTargetDependency; 488 | target = 4F0934B311BEC6EB00897344 /* MultiGPUClient */; 489 | targetProxy = 4F0934D111BEC76500897344 /* PBXContainerItemProxy */; 490 | }; 491 | /* End PBXTargetDependency section */ 492 | 493 | /* Begin PBXVariantGroup section */ 494 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { 495 | isa = PBXVariantGroup; 496 | children = ( 497 | 089C165DFE840E0CC02AAC07 /* English */, 498 | ); 499 | name = InfoPlist.strings; 500 | sourceTree = ""; 501 | }; 502 | 29B97318FDCFA39411CA2CEA /* ServerMainMenu.nib */ = { 503 | isa = PBXVariantGroup; 504 | children = ( 505 | 29B97319FDCFA39411CA2CEA /* English */, 506 | ); 507 | name = ServerMainMenu.nib; 508 | sourceTree = ""; 509 | }; 510 | 4F09350911BEC8BB00897344 /* ClientMainMenu.nib */ = { 511 | isa = PBXVariantGroup; 512 | children = ( 513 | 4F09350A11BEC8BB00897344 /* English */, 514 | ); 515 | name = ClientMainMenu.nib; 516 | sourceTree = ""; 517 | }; 518 | /* End PBXVariantGroup section */ 519 | 520 | /* Begin XCBuildConfiguration section */ 521 | 4F0934C711BEC6EB00897344 /* Debug */ = { 522 | isa = XCBuildConfiguration; 523 | buildSettings = { 524 | COMBINE_HIDPI_IMAGES = YES; 525 | COPY_PHASE_STRIP = NO; 526 | GCC_DYNAMIC_NO_PIC = NO; 527 | GCC_MODEL_TUNING = G5; 528 | GCC_OPTIMIZATION_LEVEL = 0; 529 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 530 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 531 | INFOPLIST_FILE = ClientInfo.plist; 532 | INSTALL_PATH = "$(HOME)/Applications"; 533 | MACOSX_DEPLOYMENT_TARGET = 10.9; 534 | PRODUCT_NAME = MultiGPUClient; 535 | SDKROOT = macosx; 536 | WRAPPER_EXTENSION = app; 537 | ZERO_LINK = YES; 538 | }; 539 | name = Debug; 540 | }; 541 | 4F0934C811BEC6EB00897344 /* Release */ = { 542 | isa = XCBuildConfiguration; 543 | buildSettings = { 544 | COMBINE_HIDPI_IMAGES = YES; 545 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 546 | GCC_MODEL_TUNING = G5; 547 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 548 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 549 | INFOPLIST_FILE = ClientInfo.plist; 550 | INSTALL_PATH = "$(HOME)/Applications"; 551 | MACOSX_DEPLOYMENT_TARGET = 10.9; 552 | OTHER_MIGFLAGS = "-sheader MultiGPUMigServer.h"; 553 | PRODUCT_NAME = MultiGPUClient; 554 | SDKROOT = macosx; 555 | WRAPPER_EXTENSION = app; 556 | }; 557 | name = Release; 558 | }; 559 | 4F0934CD11BEC75E00897344 /* Debug */ = { 560 | isa = XCBuildConfiguration; 561 | buildSettings = { 562 | COPY_PHASE_STRIP = NO; 563 | GCC_DYNAMIC_NO_PIC = NO; 564 | GCC_OPTIMIZATION_LEVEL = 0; 565 | MACOSX_DEPLOYMENT_TARGET = 10.7; 566 | PRODUCT_NAME = MultiGPUApps; 567 | SDKROOT = macosx; 568 | }; 569 | name = Debug; 570 | }; 571 | 4F0934CE11BEC75E00897344 /* Release */ = { 572 | isa = XCBuildConfiguration; 573 | buildSettings = { 574 | COPY_PHASE_STRIP = YES; 575 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 576 | MACOSX_DEPLOYMENT_TARGET = 10.7; 577 | PRODUCT_NAME = MultiGPUApps; 578 | SDKROOT = macosx; 579 | ZERO_LINK = NO; 580 | }; 581 | name = Release; 582 | }; 583 | BF4866691AFB1A7A004BC0CD /* Debug */ = { 584 | isa = XCBuildConfiguration; 585 | buildSettings = { 586 | COMBINE_HIDPI_IMAGES = YES; 587 | COPY_PHASE_STRIP = NO; 588 | GCC_DYNAMIC_NO_PIC = NO; 589 | GCC_MODEL_TUNING = G5; 590 | GCC_OPTIMIZATION_LEVEL = 0; 591 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 592 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 593 | INFOPLIST_FILE = ServerInfo.plist; 594 | INSTALL_PATH = "$(HOME)/Applications"; 595 | MACOSX_DEPLOYMENT_TARGET = 10.9; 596 | PRODUCT_NAME = MultiGPUPattern; 597 | SDKROOT = macosx; 598 | WRAPPER_EXTENSION = app; 599 | ZERO_LINK = YES; 600 | }; 601 | name = Debug; 602 | }; 603 | BF48666A1AFB1A7A004BC0CD /* Release */ = { 604 | isa = XCBuildConfiguration; 605 | buildSettings = { 606 | COMBINE_HIDPI_IMAGES = YES; 607 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 608 | GCC_MODEL_TUNING = G5; 609 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 610 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 611 | INFOPLIST_FILE = ServerInfo.plist; 612 | INSTALL_PATH = "$(HOME)/Applications"; 613 | MACOSX_DEPLOYMENT_TARGET = 10.9; 614 | OTHER_MIGFLAGS = "-sheader MultiGPUMigServer.h"; 615 | PRODUCT_NAME = MultiGPUPattern; 616 | SDKROOT = macosx; 617 | WRAPPER_EXTENSION = app; 618 | }; 619 | name = Release; 620 | }; 621 | C01FCF4B08A954540054247B /* Debug */ = { 622 | isa = XCBuildConfiguration; 623 | buildSettings = { 624 | COMBINE_HIDPI_IMAGES = YES; 625 | COPY_PHASE_STRIP = NO; 626 | GCC_DYNAMIC_NO_PIC = NO; 627 | GCC_MODEL_TUNING = G5; 628 | GCC_OPTIMIZATION_LEVEL = 0; 629 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 630 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 631 | INFOPLIST_FILE = ServerInfo.plist; 632 | INSTALL_PATH = "$(HOME)/Applications"; 633 | MACOSX_DEPLOYMENT_TARGET = 10.9; 634 | PRODUCT_NAME = MultiGPUServer; 635 | SDKROOT = macosx; 636 | WRAPPER_EXTENSION = app; 637 | ZERO_LINK = YES; 638 | }; 639 | name = Debug; 640 | }; 641 | C01FCF4C08A954540054247B /* Release */ = { 642 | isa = XCBuildConfiguration; 643 | buildSettings = { 644 | COMBINE_HIDPI_IMAGES = YES; 645 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 646 | GCC_MODEL_TUNING = G5; 647 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 648 | GCC_PREFIX_HEADER = MultiGPU_Prefix.pch; 649 | INFOPLIST_FILE = ServerInfo.plist; 650 | INSTALL_PATH = "$(HOME)/Applications"; 651 | MACOSX_DEPLOYMENT_TARGET = 10.9; 652 | OTHER_MIGFLAGS = "-sheader MultiGPUMigServer.h"; 653 | PRODUCT_NAME = MultiGPUServer; 654 | SDKROOT = macosx; 655 | WRAPPER_EXTENSION = app; 656 | }; 657 | name = Release; 658 | }; 659 | C01FCF4F08A954540054247B /* Debug */ = { 660 | isa = XCBuildConfiguration; 661 | buildSettings = { 662 | GCC_VERSION = ""; 663 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 664 | GCC_WARN_UNUSED_VARIABLE = YES; 665 | ONLY_ACTIVE_ARCH = YES; 666 | RUN_CLANG_STATIC_ANALYZER = YES; 667 | SDKROOT = macosx; 668 | VALID_ARCHS = "i386 x86_64"; 669 | }; 670 | name = Debug; 671 | }; 672 | C01FCF5008A954540054247B /* Release */ = { 673 | isa = XCBuildConfiguration; 674 | buildSettings = { 675 | GCC_VERSION = ""; 676 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 677 | GCC_WARN_UNUSED_VARIABLE = YES; 678 | RUN_CLANG_STATIC_ANALYZER = YES; 679 | SDKROOT = macosx; 680 | VALID_ARCHS = "i386 x86_64"; 681 | }; 682 | name = Release; 683 | }; 684 | /* End XCBuildConfiguration section */ 685 | 686 | /* Begin XCConfigurationList section */ 687 | 4F0934C611BEC6EB00897344 /* Build configuration list for PBXNativeTarget "MultiGPUClient" */ = { 688 | isa = XCConfigurationList; 689 | buildConfigurations = ( 690 | 4F0934C711BEC6EB00897344 /* Debug */, 691 | 4F0934C811BEC6EB00897344 /* Release */, 692 | ); 693 | defaultConfigurationIsVisible = 0; 694 | defaultConfigurationName = Release; 695 | }; 696 | 4F0934D311BEC78300897344 /* Build configuration list for PBXAggregateTarget "MultiGPUApps" */ = { 697 | isa = XCConfigurationList; 698 | buildConfigurations = ( 699 | 4F0934CD11BEC75E00897344 /* Debug */, 700 | 4F0934CE11BEC75E00897344 /* Release */, 701 | ); 702 | defaultConfigurationIsVisible = 0; 703 | defaultConfigurationName = Release; 704 | }; 705 | BF4866681AFB1A7A004BC0CD /* Build configuration list for PBXNativeTarget "MultiGPUPattern" */ = { 706 | isa = XCConfigurationList; 707 | buildConfigurations = ( 708 | BF4866691AFB1A7A004BC0CD /* Debug */, 709 | BF48666A1AFB1A7A004BC0CD /* Release */, 710 | ); 711 | defaultConfigurationIsVisible = 0; 712 | defaultConfigurationName = Release; 713 | }; 714 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "MultiGPUServer" */ = { 715 | isa = XCConfigurationList; 716 | buildConfigurations = ( 717 | C01FCF4B08A954540054247B /* Debug */, 718 | C01FCF4C08A954540054247B /* Release */, 719 | ); 720 | defaultConfigurationIsVisible = 0; 721 | defaultConfigurationName = Release; 722 | }; 723 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MultiGPU" */ = { 724 | isa = XCConfigurationList; 725 | buildConfigurations = ( 726 | C01FCF4F08A954540054247B /* Debug */, 727 | C01FCF5008A954540054247B /* Release */, 728 | ); 729 | defaultConfigurationIsVisible = 0; 730 | defaultConfigurationName = Release; 731 | }; 732 | /* End XCConfigurationList section */ 733 | }; 734 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 735 | } 736 | -------------------------------------------------------------------------------- /MultiGPU.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MultiGPU.xcodeproj/project.xcworkspace/xcshareddata/MultiGPU.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 01D97196-6B06-4CDE-8949-42E80CF21D46 9 | IDESourceControlProjectName 10 | project 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 591EE3EEA8B72C24C83F399552F692DD480AF39A 14 | github.com:jryans/iosurface-example.git 15 | 16 | IDESourceControlProjectPath 17 | MultiGPU.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 591EE3EEA8B72C24C83F399552F692DD480AF39A 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | github.com:jryans/iosurface-example.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 591EE3EEA8B72C24C83F399552F692DD480AF39A 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 591EE3EEA8B72C24C83F399552F692DD480AF39A 36 | IDESourceControlWCCName 37 | iosurface-example 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /MultiGPUMig.defs: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | subsystem MGSServer 29000; 4 | userprefix _MGC; /* Routine prefixes for user access. */ 5 | serverprefix _MGS; /* Routine prefixes for internal server access. */ 6 | 7 | /* Client -> Server */ 8 | routine CheckinClient( 9 | server_port : mach_port_t; 10 | in client_port : mach_port_t; 11 | out client_index : int32_t 12 | ); 13 | 14 | /* Master -> Slave */ 15 | routine DisplayFrame( 16 | server_port : mach_port_t; 17 | frame_index : int32_t; 18 | iosurface_id : uint32_t 19 | ); 20 | -------------------------------------------------------------------------------- /MultiGPU_Prefix.pch: -------------------------------------------------------------------------------- 1 | /* 2 | File: MultiGPU_Prefix.pch 3 | Abstract: Prefix header for all source files of the 'MultiGPU' target in the 'MultiGPU' project 4 | 5 | Version: 1.2 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | #ifdef __OBJC__ 50 | #import 51 | #endif 52 | -------------------------------------------------------------------------------- /PatternOpenGLView.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerOpenGLView.m 3 | Abstract: 4 | This class implements the server specific subclass of NSOpenGLView. 5 | It handles the server side rendering, which calls into the GLUT-based 6 | Atlantis rendering code to draw into an IOSurface using an FBO. It 7 | also performs local rendering of each frame for display purposes. 8 | 9 | It also shows how to bind IOSurface objects to OpenGL textures, and 10 | how to use those for rendering with FBOs. 11 | 12 | Version: 1.2 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | #import "ServerOpenGLView.h" 57 | #import "ServerController.h" 58 | 59 | #import 60 | #import 61 | #import 62 | #import 63 | 64 | #include "shaderUtil.h" 65 | #include "fileUtil.h" 66 | 67 | enum { 68 | PROGRAM_PATTERN, 69 | NUM_PROGRAMS 70 | }; 71 | 72 | enum { 73 | UNIFORM_MVP, 74 | UNIFORM_MODELVIEW, 75 | UNIFORM_MODELVIEWIT, 76 | UNIFORM_LIGHTDIR, 77 | UNIFORM_AMBIENT, 78 | UNIFORM_DIFFUSE, 79 | UNIFORM_SPECULAR, 80 | UNIFORM_SHININESS, 81 | UNIFORM_CONSTANT_COLOR, 82 | UNIFORM_TEXTURE, 83 | UNIFORM_RESOLUTION, 84 | NUM_UNIFORMS 85 | }; 86 | 87 | enum { 88 | ATTRIB_VERTEX, 89 | ATTRIB_COLOR, 90 | ATTRIB_NORMAL, 91 | ATTRIB_TEXCOORD, 92 | NUM_ATTRIBS 93 | }; 94 | 95 | typedef struct { 96 | char *vert, *frag; 97 | GLint uniform[NUM_UNIFORMS]; 98 | GLuint id; 99 | } programInfo_t; 100 | 101 | programInfo_t program[NUM_PROGRAMS] = { 102 | { "pattern.vsh", "pattern.fsh" }, // PROGRAM_PATTERN 103 | }; 104 | 105 | @interface ServerOpenGLView() 106 | { 107 | GLuint quadVAOId, quadVBOId; 108 | BOOL quadInit; 109 | GLuint depthBufferName; 110 | } 111 | @end 112 | 113 | @implementation ServerOpenGLView 114 | 115 | - (instancetype)initWithFrame:(NSRect)frame 116 | { 117 | NSOpenGLPixelFormat *pix_fmt; 118 | 119 | NSOpenGLPixelFormatAttribute attribs[] = 120 | { 121 | NSOpenGLPFAAllowOfflineRenderers, 122 | NSOpenGLPFAAccelerated, 123 | NSOpenGLPFADoubleBuffer, 124 | // NSOpenGLPFAColorSize, 32, 125 | // NSOpenGLPFADepthSize, 24, 126 | // NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, // Core Profile is the future 127 | 0 128 | }; 129 | 130 | pix_fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 131 | if(!pix_fmt) 132 | { 133 | NSLog(@"couldn't create pixel format\n"); 134 | [NSApp terminate:nil]; 135 | } 136 | 137 | self = [super initWithFrame:frame pixelFormat:pix_fmt]; 138 | [pix_fmt release]; 139 | 140 | [self setWantsBestResolutionOpenGLSurface:YES]; 141 | 142 | [[self openGLContext] makeCurrentContext]; 143 | 144 | return self; 145 | } 146 | 147 | - (void)prepareOpenGL 148 | { 149 | [super prepareOpenGL]; 150 | 151 | glGenVertexArrays(1, &quadVAOId); 152 | glGenBuffers(1, &quadVBOId); 153 | glBindVertexArray(quadVAOId); 154 | 155 | [self setupShaders]; 156 | 157 | glBindVertexArray(0); 158 | } 159 | 160 | - (void)update 161 | { 162 | // Override to do nothing. 163 | } 164 | 165 | - (NSArray *)rendererNames 166 | { 167 | NSMutableArray *rendererNames; 168 | GLint i, numScreens; 169 | 170 | rendererNames = [[NSMutableArray alloc] init]; 171 | 172 | numScreens = [[self pixelFormat] numberOfVirtualScreens]; 173 | for(i = 0; i < numScreens; i++) 174 | { 175 | [[self openGLContext] setCurrentVirtualScreen:i]; 176 | [rendererNames addObject:@((const char *)glGetString(GL_RENDERER))]; 177 | } 178 | 179 | return [rendererNames autorelease]; 180 | } 181 | 182 | - (void)setRendererIndex:(uint32_t)index 183 | { 184 | [[self openGLContext] setCurrentVirtualScreen:index]; 185 | } 186 | 187 | // Create an IOSurface backed texture 188 | // Create an FBO using the name of this texture and bind the texture to the color attachment of the FBO 189 | - (GLuint)setupIOSurfaceTexture:(IOSurfaceRef)ioSurfaceBuffer fboName:(GLuint *)fboName 190 | { 191 | GLuint name, namef; 192 | CGLContextObj cgl_ctx = (CGLContextObj)[[self openGLContext] CGLContextObj]; 193 | 194 | glGenTextures(1, &name); 195 | 196 | glBindTexture(GL_TEXTURE_RECTANGLE, name); 197 | // At the moment, CGLTexImageIOSurface2D requires the GL_TEXTURE_RECTANGLE target 198 | // CGLTexImageIOSurface2D(cgl_ctx, GL_TEXTURE_RECTANGLE, GL_RGBA, 512, 512, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 199 | // ioSurfaceBuffer, 0); 200 | 201 | glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 512, 512, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); 202 | 203 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 204 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 205 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 206 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 207 | 208 | // Generate an FBO and bind the texture to it as a render target. 209 | 210 | glBindTexture(GL_TEXTURE_RECTANGLE, 0); 211 | 212 | glGenFramebuffers(1, &namef); 213 | glBindFramebuffer(GL_FRAMEBUFFER, namef); 214 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, name, 0); 215 | 216 | if(!depthBufferName) 217 | { 218 | glGenRenderbuffers(1, &depthBufferName); 219 | glRenderbufferStorage(GL_TEXTURE_RECTANGLE, GL_DEPTH, 512, 512); 220 | } 221 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, depthBufferName); 222 | 223 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 224 | 225 | *fboName = namef; 226 | 227 | return name; 228 | } 229 | 230 | // Fill the view with the IOSurface backed texture 231 | - (void)renderTextureFromCurrentIOSurface 232 | { 233 | GLfloat vertices[] = { 234 | -1.0, -1.0, 235 | 1.0, -1.0, 236 | -1.0, 1.0, 237 | 1.0, -1.0, 238 | 1.0, 1.0, 239 | -1.0, 1.0 240 | }; 241 | 242 | if (!quadInit) { 243 | glBindVertexArray(quadVAOId); 244 | glBindBuffer(GL_ARRAY_BUFFER, quadVBOId); 245 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 246 | // positions 247 | glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, 0); 248 | // texture coordinates 249 | // glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (const GLvoid*)(2*sizeof(GLfloat))); 250 | 251 | quadInit = YES; 252 | } 253 | 254 | NSSize backingSize = [self convertSizeToBacking:[self bounds].size]; 255 | glViewport(0, 0, (GLint)backingSize.width, (GLint)backingSize.height); 256 | 257 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 258 | glClear(GL_COLOR_BUFFER_BIT); 259 | 260 | glUseProgram(program[PROGRAM_PATTERN].id); 261 | 262 | glUniform3f(program[PROGRAM_PATTERN].uniform[UNIFORM_RESOLUTION], 512.0f, 512.0f, 1.0f); 263 | 264 | glBindVertexArray(quadVAOId); 265 | glEnableVertexAttribArray(ATTRIB_VERTEX); 266 | 267 | glDrawArrays(GL_TRIANGLES, 0, 6); 268 | 269 | glDisableVertexAttribArray(ATTRIB_VERTEX); 270 | } 271 | 272 | - (BOOL)isOpaque 273 | { 274 | return YES; 275 | } 276 | 277 | - (void)drawRect:(NSRect)theRect 278 | { 279 | // Render a view size quad with the IOSurface backed texture 280 | glDisable(GL_DEPTH_TEST); 281 | [self renderTextureFromCurrentIOSurface]; 282 | 283 | [[self openGLContext] flushBuffer]; 284 | 285 | // This flush is necessary to ensure proper behavior if the MT engine is enabled. 286 | glFlush(); 287 | } 288 | 289 | - (void)setupShaders 290 | { 291 | for (int i = 0; i < NUM_PROGRAMS; i++) 292 | { 293 | char *vsrc = readFile(pathForResource(program[i].vert)); 294 | char *fsrc = readFile(pathForResource(program[i].frag)); 295 | GLsizei attribCt = 0; 296 | GLchar *attribUsed[NUM_ATTRIBS]; 297 | GLint attrib[NUM_ATTRIBS]; 298 | GLchar *attribName[NUM_ATTRIBS] = { 299 | "inVertex", "inColor", "inNormal", "inTexCoord", 300 | }; 301 | const GLchar *uniformName[NUM_UNIFORMS] = { 302 | "MVP", "ModelView", "ModelViewIT", "lightDir", "ambient", "diffuse", "specular", "shininess", "constantColor", "tex", "iResolution", 303 | }; 304 | 305 | // auto-assign known attribs 306 | for (int j = 0; j < NUM_ATTRIBS; j++) 307 | { 308 | if (strstr(vsrc, attribName[j])) 309 | { 310 | attrib[attribCt] = j; 311 | attribUsed[attribCt++] = attribName[j]; 312 | } 313 | } 314 | 315 | glueCreateProgram(vsrc, fsrc, 316 | attribCt, (const GLchar **)&attribUsed[0], attrib, 317 | NUM_UNIFORMS, &uniformName[0], program[i].uniform, 318 | &program[i].id); 319 | free(vsrc); 320 | free(fsrc); 321 | } 322 | } 323 | 324 | @end 325 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | MultiGPUIOSurface 2 | 3 | ================================================================================ 4 | DESCRIPTION: 5 | 6 | MutiGPUIOSurface shows how to create IOSurfaces and bind them to OpenGL textures 7 | for both reading and writing. It demonstrates one way of passing IOSurfaces from 8 | one process to another via Mach RPC calls. It also demonstrates the system's 9 | ability to track IOSurface changes across process and GPU boundaries. 10 | 11 | To test, after building the integrated target "MultiGPUApps", first run the server 12 | application "MultiGPUServer" and then the client application "MultiGPUClient". 13 | 14 | ================================================================================ 15 | BUILD REQUIREMENTS: 16 | 17 | OS X 10.9 or later, Xcode 5.1 or later 18 | 19 | ================================================================================ 20 | RUNTIME REQUIREMENTS: 21 | 22 | OS X 10.7 or later 23 | 24 | ================================================================================ 25 | PACKAGING LIST: 26 | 27 | ClientController.h 28 | ClientController.m 29 | This class implements the controller object for the client application. It is 30 | responsible for looking up the server application, and responding to frame 31 | rendering requests from the server. 32 | 33 | ClientOpenGLView.h 34 | ClientOpenGLView.m 35 | This class implements the client specific subclass of NSOpenGLView. 36 | It handles the client side rendering, which calls into the GLUT-based 37 | BluePony rendering code, substituting the contents of an IOSurface from 38 | the server application instead of the OpenGL logo. 39 | 40 | It also shows how to bind IOSurface objects to OpenGL textures. 41 | 42 | ServerController.h 43 | ServerController.m 44 | This class implements the controller object for the server application. It is 45 | responsible for setting up public Mach port for the server and listening for 46 | client applications to start up. It also sends frame display update requests 47 | to all clients after every frame update. 48 | 49 | It is also responsible for creating the initial set of IOSurfaces used to send 50 | rendered frames to the client applications. 51 | 52 | ServerOpenGLView.h 53 | ServerOpenGLView.m 54 | This class implements the server specific subclass of NSOpenGLView. 55 | It handles the server side rendering, which calls into the GLUT-based 56 | Atlantis rendering code to draw into an IOSurface using an FBO. It 57 | also performs local rendering of each frame for display purposes. 58 | 59 | It also shows how to bind IOSurface objects to OpenGL textures, and 60 | how to use those for rendering with FBOs. 61 | 62 | ================================================================================ 63 | CHANGES FROM PREVIOUS VERSIONS: 64 | 65 | Version 1.2 66 | - Updated with Core Profile. Cleaned up code. Removed deprecated calls. 67 | 68 | Version 1.1 69 | - First public release. 70 | 71 | ================================================================================ 72 | Copyright (C) 2010~2014 Apple Inc. All rights reserved. -------------------------------------------------------------------------------- /ServerController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerController.h 3 | Abstract: 4 | This class implements the controller object for the server application. It is 5 | responsible for setting up public Mach port for the server and listening for 6 | client applications to start up. It also sends frame display update requests 7 | to all clients after every frame update. 8 | 9 | It is also responsible for creating the initial set of IOSurfaces used to send 10 | rendered frames to the client applications. 11 | 12 | Version: 1.2 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | #import 57 | #import 58 | #import 59 | 60 | #define NUM_IOSURFACE_BUFFERS 2 61 | 62 | @interface ServerController : NSObject 63 | 64 | - (kern_return_t)checkInClient:(mach_port_t)client_port index:(int32_t *)client_index; 65 | @property (NS_NONATOMIC_IOSONLY, readonly) GLuint currentTextureName; 66 | @property (NS_NONATOMIC_IOSONLY, readonly) GLuint currentFBOName; 67 | - (void)portDied:(NSNotification *)notification; 68 | - (IBAction)setRenderer:(id)sender; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /ServerController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerController.m 3 | Abstract: 4 | This class implements the controller object for the server application. It is 5 | responsible for setting up public Mach port for the server and listening for 6 | client applications to start up. It also sends frame display update requests 7 | to all clients after every frame update. 8 | 9 | It is also responsible for creating the initial set of IOSurfaces used to send 10 | rendered frames to the client applications. 11 | 12 | Version: 1.2 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | #import "ServerController.h" 57 | #import "MultiGPUMig.h" 58 | #import "MultiGPUMigServer.h" 59 | #import "ServerOpenGLView.h" 60 | 61 | @interface ServerController() 62 | { 63 | IBOutlet NSWindow *_window; 64 | IBOutlet ServerOpenGLView *_view; 65 | IBOutlet NSPopUpButton *_rendererPopup; 66 | 67 | NSTimer *_timer; 68 | NSMachPort *serverPort; 69 | NSMachPort *localPort; 70 | 71 | uint32_t serverPortName; 72 | uint32_t localPortName; 73 | 74 | NSMachPort *clientPort[16]; 75 | uint32_t clientPortNames[16]; 76 | uint32_t clientPortCount; 77 | 78 | int32_t clientIndex; 79 | uint32_t nextFrameIndex; 80 | 81 | IOSurfaceRef _ioSurfaceBuffers[NUM_IOSURFACE_BUFFERS]; 82 | GLuint _textureNames[NUM_IOSURFACE_BUFFERS]; 83 | GLuint _fboNames[NUM_IOSURFACE_BUFFERS]; 84 | 85 | uint32_t rendererIndex; 86 | } 87 | @end 88 | 89 | @implementation ServerController 90 | 91 | - (void)applicationWillFinishLaunching:(NSNotification *)note 92 | { 93 | [[NSNotificationCenter defaultCenter] addObserver:self 94 | selector:@selector(portDied:) name:NSPortDidBecomeInvalidNotification object:nil]; 95 | 96 | [_rendererPopup removeAllItems]; 97 | [_rendererPopup addItemsWithTitles:[_view rendererNames]]; 98 | 99 | [_view setRendererIndex:0]; 100 | [_rendererPopup selectItemAtIndex:0]; 101 | 102 | serverPort = [(NSMachPort *)([[NSMachBootstrapServer sharedInstance] servicePortWithName:@"com.apple.MultiGPUServer"]) retain]; 103 | 104 | // Create a local dummy reply port to use with the mig reply stuff 105 | localPort = [[NSMachPort alloc] init]; 106 | 107 | // Retrieve raw mach port names. 108 | serverPortName = [serverPort machPort]; 109 | localPortName = [localPort machPort]; 110 | 111 | [serverPort setDelegate:self]; 112 | [serverPort scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; 113 | 114 | // Set up all of our iosurface buffers 115 | int i; 116 | for(i = 0; i < NUM_IOSURFACE_BUFFERS; i++) 117 | _ioSurfaceBuffers[i] = IOSurfaceCreate((CFDictionaryRef)@{(id)kIOSurfaceWidth: @512, 118 | (id)kIOSurfaceHeight: @512, 119 | (id)kIOSurfaceBytesPerElement: @4, 120 | (id)kIOSurfaceIsGlobal: @YES}); 121 | } 122 | 123 | - (void)applicationDidFinishLaunching:(NSNotification *)note 124 | { 125 | // Fire up animation timer. 126 | _timer = [[NSTimer timerWithTimeInterval:1.0f/60.0f target:self selector:@selector(animate:) userInfo:nil repeats:YES] retain]; 127 | [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; 128 | } 129 | 130 | - (void)portDied:(NSNotification *)notification 131 | { 132 | NSPort *port = [notification object]; 133 | if(port == serverPort) 134 | { 135 | [NSApp terminate:self]; 136 | } 137 | else 138 | { 139 | int i; 140 | for(i = 0; i < clientPortCount+1; i++) 141 | { 142 | if([clientPort[i] isEqual:port]) 143 | { 144 | [clientPort[i] release]; 145 | clientPort[i] = nil; 146 | clientPortNames[i] = 0; 147 | } 148 | } 149 | } 150 | } 151 | 152 | - (void)handleMachMessage:(void *)msg 153 | { 154 | union __ReplyUnion___MGCMGSServer_subsystem reply; 155 | 156 | mach_msg_header_t *reply_header = (void *)&reply; 157 | kern_return_t kr; 158 | 159 | if(MGSServer_server(msg, reply_header) && reply_header->msgh_remote_port != MACH_PORT_NULL) 160 | { 161 | kr = mach_msg(reply_header, MACH_SEND_MSG, reply_header->msgh_size, 0, MACH_PORT_NULL, 162 | 0, MACH_PORT_NULL); 163 | if(kr != 0) 164 | [NSApp terminate:nil]; 165 | } 166 | } 167 | 168 | - (kern_return_t)checkInClient:(mach_port_t)client_port index:(int32_t *)client_index 169 | { 170 | clientPortCount++; // clients always start at index 1 171 | clientPortNames[clientPortCount] = client_port; 172 | clientPort[clientPortCount] = [[NSMachPort alloc] initWithMachPort:client_port]; 173 | 174 | *client_index = clientPortCount; 175 | return 0; 176 | } 177 | 178 | kern_return_t _MGSCheckinClient(mach_port_t server_port, mach_port_t client_port, 179 | int32_t *client_index) 180 | { 181 | return [(ServerController *)[NSApp delegate] checkInClient:client_port index:client_index]; 182 | } 183 | 184 | // For the server, this is a no-op 185 | kern_return_t _MGSDisplayFrame(mach_port_t server_port, int32_t frame_index, uint32_t iosurface_id) 186 | { 187 | return 0; 188 | } 189 | 190 | - (GLuint)currentTextureName 191 | { 192 | return _textureNames[nextFrameIndex]; 193 | } 194 | 195 | - (GLuint)currentFBOName 196 | { 197 | return _fboNames[nextFrameIndex]; 198 | } 199 | 200 | - (void)animate:(NSTimer *)timer 201 | { 202 | if(!_textureNames[nextFrameIndex]) 203 | { 204 | _textureNames[nextFrameIndex] = [_view setupIOSurfaceTexture:_ioSurfaceBuffers[nextFrameIndex] fboName:&_fboNames[nextFrameIndex]]; 205 | } 206 | 207 | [_view setNeedsDisplay:YES]; 208 | [_view display]; 209 | 210 | int i; 211 | for(i = 0; i < clientPortCount+1; i++) 212 | { 213 | if(clientPortNames[i]) 214 | { 215 | _MGCDisplayFrame(clientPortNames[i], 216 | nextFrameIndex, 217 | IOSurfaceGetID(_ioSurfaceBuffers[nextFrameIndex])); 218 | } 219 | } 220 | 221 | nextFrameIndex = (nextFrameIndex + 1) % NUM_IOSURFACE_BUFFERS; 222 | } 223 | 224 | - (IBAction)setRenderer:(id)sender 225 | { 226 | [_view setRendererIndex:(rendererIndex = [sender indexOfSelectedItem])]; 227 | } 228 | 229 | @end 230 | -------------------------------------------------------------------------------- /ServerInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.2 23 | NSMainNibFile 24 | ServerMainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /ServerOpenGLView.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerOpenGLView.h 3 | Abstract: 4 | This class implements the server specific subclass of NSOpenGLView. 5 | It handles the server side rendering, which calls into the GLUT-based 6 | Atlantis rendering code to draw into an IOSurface using an FBO. It 7 | also performs local rendering of each frame for display purposes. 8 | 9 | It also shows how to bind IOSurface objects to OpenGL textures, and 10 | how to use those for rendering with FBOs. 11 | 12 | Version: 1.2 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | #import 57 | #import 58 | 59 | @interface ServerOpenGLView : NSOpenGLView 60 | 61 | - (GLuint)setupIOSurfaceTexture:(IOSurfaceRef)ioSurfaceBuffer fboName:(GLuint *)fboName; 62 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *rendererNames; 63 | - (void)setRendererIndex:(uint32_t)index; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /ServerOpenGLView.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerOpenGLView.m 3 | Abstract: 4 | This class implements the server specific subclass of NSOpenGLView. 5 | It handles the server side rendering, which calls into the GLUT-based 6 | Atlantis rendering code to draw into an IOSurface using an FBO. It 7 | also performs local rendering of each frame for display purposes. 8 | 9 | It also shows how to bind IOSurface objects to OpenGL textures, and 10 | how to use those for rendering with FBOs. 11 | 12 | Version: 1.2 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | #import "ServerOpenGLView.h" 57 | #import "ServerController.h" 58 | #import "BoingRenderer.h" 59 | 60 | #import 61 | #import 62 | #import 63 | #import 64 | 65 | programInfo_t program[NUM_PROGRAMS] = { 66 | { "lighting.vsh", "color.fsh" }, // PROGRAM_LIGHTING 67 | { "color.vsh", "color.fsh" }, // PROGRAM_PASSTHRU 68 | { "texture.vsh", "textureRect.fsh" }, // PROGRAM_TEXTURE_RECT 69 | }; 70 | 71 | 72 | @interface ServerOpenGLView() 73 | { 74 | GLuint quadVAOId, quadVBOId; 75 | BOOL quadInit; 76 | GLuint depthBufferName; 77 | BoingRenderer *renderer; 78 | } 79 | @end 80 | 81 | @implementation ServerOpenGLView 82 | 83 | - (instancetype)initWithFrame:(NSRect)frame 84 | { 85 | NSOpenGLPixelFormat *pix_fmt; 86 | 87 | NSOpenGLPixelFormatAttribute attribs[] = 88 | { 89 | NSOpenGLPFAAllowOfflineRenderers, 90 | NSOpenGLPFAAccelerated, 91 | NSOpenGLPFADoubleBuffer, 92 | NSOpenGLPFAColorSize, 32, 93 | NSOpenGLPFADepthSize, 24, 94 | NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, // Core Profile is the future 95 | 0 96 | }; 97 | 98 | pix_fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 99 | if(!pix_fmt) 100 | { 101 | NSLog(@"couldn't create pixel format\n"); 102 | [NSApp terminate:nil]; 103 | } 104 | 105 | self = [super initWithFrame:frame pixelFormat:pix_fmt]; 106 | [pix_fmt release]; 107 | 108 | [[self openGLContext] makeCurrentContext]; 109 | 110 | return self; 111 | } 112 | 113 | - (void)prepareOpenGL 114 | { 115 | [super prepareOpenGL]; 116 | 117 | glGenVertexArrays(1, &quadVAOId); 118 | glGenBuffers(1, &quadVBOId); 119 | glBindVertexArray(quadVAOId); 120 | 121 | [self setupShaders]; 122 | 123 | // Create a BoingRenderer object which handles the rendering of a Boing ball. 124 | renderer = [[BoingRenderer alloc] init]; 125 | [renderer initShaders:program]; 126 | 127 | glBindVertexArray(0); 128 | } 129 | 130 | - (void)update 131 | { 132 | // Override to do nothing. 133 | } 134 | 135 | - (NSArray *)rendererNames 136 | { 137 | NSMutableArray *rendererNames; 138 | GLint i, numScreens; 139 | 140 | rendererNames = [[NSMutableArray alloc] init]; 141 | 142 | numScreens = [[self pixelFormat] numberOfVirtualScreens]; 143 | for(i = 0; i < numScreens; i++) 144 | { 145 | [[self openGLContext] setCurrentVirtualScreen:i]; 146 | [rendererNames addObject:@((const char *)glGetString(GL_RENDERER))]; 147 | } 148 | 149 | return [rendererNames autorelease]; 150 | } 151 | 152 | - (void)setRendererIndex:(uint32_t)index 153 | { 154 | [[self openGLContext] setCurrentVirtualScreen:index]; 155 | } 156 | 157 | // Create an IOSurface backed texture 158 | // Create an FBO using the name of this texture and bind the texture to the color attachment of the FBO 159 | - (GLuint)setupIOSurfaceTexture:(IOSurfaceRef)ioSurfaceBuffer fboName:(GLuint *)fboName 160 | { 161 | GLuint name, namef; 162 | CGLContextObj cgl_ctx = (CGLContextObj)[[self openGLContext] CGLContextObj]; 163 | 164 | glGenTextures(1, &name); 165 | 166 | glBindTexture(GL_TEXTURE_RECTANGLE, name); 167 | // At the moment, CGLTexImageIOSurface2D requires the GL_TEXTURE_RECTANGLE target 168 | // CGLTexImageIOSurface2D(cgl_ctx, GL_TEXTURE_RECTANGLE, GL_RGBA, 512, 512, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 169 | // ioSurfaceBuffer, 0); 170 | 171 | glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 512, 512, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); 172 | 173 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 174 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 175 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 176 | glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 177 | 178 | // Generate an FBO and bind the texture to it as a render target. 179 | 180 | glBindTexture(GL_TEXTURE_RECTANGLE, 0); 181 | 182 | glGenFramebuffers(1, &namef); 183 | glBindFramebuffer(GL_FRAMEBUFFER, namef); 184 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, name, 0); 185 | 186 | if(!depthBufferName) 187 | { 188 | glGenRenderbuffers(1, &depthBufferName); 189 | glRenderbufferStorage(GL_TEXTURE_RECTANGLE, GL_DEPTH, 512, 512); 190 | } 191 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, depthBufferName); 192 | 193 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 194 | 195 | *fboName = namef; 196 | 197 | return name; 198 | } 199 | 200 | // Render to the current IOSurface via the corresponding FBO previously setuped in -setupIOSurfaceTexture:fboName 201 | - (void)renderToCurrentIOSurface 202 | { 203 | glBindFramebuffer(GL_FRAMEBUFFER, [(ServerController *)[NSApp delegate] currentFBOName]); 204 | 205 | glClearColor(0.675f, 0.675f, 0.675f, 1.0f); 206 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 207 | 208 | glViewport(0,0,512,512); 209 | 210 | // Delegate to the BoingRenderer object to setup an appropriate projection matrix 211 | [renderer makeOrthographicForWidth:512 height:512]; 212 | 213 | // Let the BoingRenderer object update the physics stuff 214 | [renderer update]; 215 | 216 | // Delegate to the BoingRenderer object for drawing the boling ball 217 | [renderer render:program]; 218 | 219 | // Bind back to system drawable. 220 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 221 | 222 | glFlush(); 223 | } 224 | 225 | // Fill the view with the IOSurface backed texture 226 | - (void)renderTextureFromCurrentIOSurface 227 | { 228 | NSRect bounds = [self bounds]; 229 | GLfloat width = self.bounds.size.width; 230 | GLfloat height = self.bounds.size.height; 231 | 232 | GLfloat quad[] = { 233 | //x, y s, t 234 | 0.0f, 0.0f, 0.0f, 0.0f, 235 | width, 0.0f, 512.0f, 0.0f, 236 | 0.0f, height, 0.0f, 512.0f, 237 | width, height, 512.0f, 512.0f, 238 | }; 239 | 240 | if (!quadInit) { 241 | glBindVertexArray(quadVAOId); 242 | glBindBuffer(GL_ARRAY_BUFFER, quadVBOId); 243 | glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW); 244 | // positions 245 | glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), NULL); 246 | // texture coordinates 247 | glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (const GLvoid*)(2*sizeof(GLfloat))); 248 | 249 | quadInit = YES; 250 | } 251 | 252 | glViewport(0, 0, (GLint)bounds.size.width, (GLint)bounds.size.height); 253 | 254 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 255 | glClear(GL_COLOR_BUFFER_BIT); 256 | 257 | glUseProgram(program[PROGRAM_TEXTURE_RECT].id); 258 | 259 | GLKMatrix4 projection = GLKMatrix4MakeOrtho(0.0, (GLfloat)bounds.size.width, 0.0f, (GLfloat)bounds.size.height, -1.0f, 1.0f); 260 | GLKMatrix4 modelView = GLKMatrix4Identity; 261 | GLKMatrix4 mvp = GLKMatrix4Multiply(projection, modelView); 262 | glUniformMatrix4fv(program[PROGRAM_TEXTURE_RECT].uniform[UNIFORM_MVP], 1, GL_FALSE, mvp.m); 263 | 264 | glUniform1i(program[PROGRAM_TEXTURE_RECT].uniform[UNIFORM_TEXTURE], 0); 265 | 266 | // Render quad from our iosurface texture 267 | glBindTexture(GL_TEXTURE_RECTANGLE, [(ServerController *)[NSApp delegate] currentTextureName]); 268 | glEnable(GL_TEXTURE_RECTANGLE); 269 | 270 | glBindVertexArray(quadVAOId); 271 | glEnableVertexAttribArray(ATTRIB_VERTEX); 272 | glEnableVertexAttribArray(ATTRIB_TEXCOORD); 273 | 274 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 275 | 276 | glDisableVertexAttribArray(ATTRIB_VERTEX); 277 | glDisableVertexAttribArray(ATTRIB_TEXCOORD); 278 | glDisable(GL_TEXTURE_RECTANGLE); 279 | } 280 | 281 | - (BOOL)isOpaque 282 | { 283 | return YES; 284 | } 285 | 286 | - (void)drawRect:(NSRect)theRect 287 | { 288 | // Only the Master app renders to the IOSurface 289 | [self renderToCurrentIOSurface]; 290 | 291 | // Render a view size quad with the IOSurface backed texture 292 | glDisable(GL_DEPTH_TEST); 293 | [self renderTextureFromCurrentIOSurface]; 294 | 295 | [[self openGLContext] flushBuffer]; 296 | 297 | // This flush is necessary to ensure proper behavior if the MT engine is enabled. 298 | glFlush(); 299 | } 300 | 301 | - (void)setupShaders 302 | { 303 | for (int i = 0; i < NUM_PROGRAMS; i++) 304 | { 305 | char *vsrc = readFile(pathForResource(program[i].vert)); 306 | char *fsrc = readFile(pathForResource(program[i].frag)); 307 | GLsizei attribCt = 0; 308 | GLchar *attribUsed[NUM_ATTRIBS]; 309 | GLint attrib[NUM_ATTRIBS]; 310 | GLchar *attribName[NUM_ATTRIBS] = { 311 | "inVertex", "inColor", "inNormal", "inTexCoord", 312 | }; 313 | const GLchar *uniformName[NUM_UNIFORMS] = { 314 | "MVP", "ModelView", "ModelViewIT", "lightDir", "ambient", "diffuse", "specular", "shininess", "constantColor", "tex", 315 | }; 316 | 317 | // auto-assign known attribs 318 | for (int j = 0; j < NUM_ATTRIBS; j++) 319 | { 320 | if (strstr(vsrc, attribName[j])) 321 | { 322 | attrib[attribCt] = j; 323 | attribUsed[attribCt++] = attribName[j]; 324 | } 325 | } 326 | 327 | glueCreateProgram(vsrc, fsrc, 328 | attribCt, (const GLchar **)&attribUsed[0], attrib, 329 | NUM_UNIFORMS, &uniformName[0], program[i].uniform, 330 | &program[i].id); 331 | free(vsrc); 332 | free(fsrc); 333 | } 334 | } 335 | 336 | @end 337 | -------------------------------------------------------------------------------- /ServerShaderDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ServerShaderDefs.h 3 | Abstract: 4 | This header file contains shader info used by ServerOpenGLView and BoingRenderer 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #ifndef MultiGPU_shaderDef_h 51 | #define MultiGPU_shaderDef_h 52 | 53 | #include "shaderUtil.h" 54 | #include "fileUtil.h" 55 | 56 | enum { 57 | PROGRAM_LIGHTING, 58 | PROGRAM_PASSTHRU, 59 | PROGRAM_TEXTURE_RECT, 60 | NUM_PROGRAMS 61 | }; 62 | 63 | enum { 64 | UNIFORM_MVP, 65 | UNIFORM_MODELVIEW, 66 | UNIFORM_MODELVIEWIT, 67 | UNIFORM_LIGHTDIR, 68 | UNIFORM_AMBIENT, 69 | UNIFORM_DIFFUSE, 70 | UNIFORM_SPECULAR, 71 | UNIFORM_SHININESS, 72 | UNIFORM_CONSTANT_COLOR, 73 | UNIFORM_TEXTURE, 74 | NUM_UNIFORMS 75 | }; 76 | 77 | enum { 78 | ATTRIB_VERTEX, 79 | ATTRIB_COLOR, 80 | ATTRIB_NORMAL, 81 | ATTRIB_TEXCOORD, 82 | NUM_ATTRIBS 83 | }; 84 | 85 | typedef struct { 86 | char *vert, *frag; 87 | GLint uniform[NUM_UNIFORMS]; 88 | GLuint id; 89 | } programInfo_t; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /Shaders/color.fsh: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 color; 4 | out vec4 fragColor; 5 | 6 | void main() 7 | { 8 | fragColor = color; 9 | } 10 | -------------------------------------------------------------------------------- /Shaders/color.vsh: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 inVertex; 4 | out vec4 color; 5 | 6 | uniform mat4 MVP; 7 | uniform vec4 constantColor; 8 | 9 | void main() 10 | { 11 | gl_Position = MVP * inVertex; 12 | color = constantColor; 13 | } 14 | -------------------------------------------------------------------------------- /Shaders/gecko.fsh: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : require 2 | #ifdef GL_ES 3 | precision mediump float; 4 | #define COLOR_PRECISION lowp 5 | #else 6 | #define COLOR_PRECISION 7 | #endif 8 | varying vec2 vTexCoord; 9 | uniform vec2 uTexCoordMultiplier; 10 | uniform sampler2DRect uTexture; 11 | vec4 sample(vec2 coord) { 12 | vec4 color; 13 | color = texture2DRect(uTexture, coord); 14 | return color; 15 | } 16 | void main() { 17 | vec4 color = sample(vTexCoord * uTexCoordMultiplier); 18 | COLOR_PRECISION float mask = 1.0; 19 | color *= mask; 20 | gl_FragColor = color; 21 | } 22 | -------------------------------------------------------------------------------- /Shaders/gecko.vsh: -------------------------------------------------------------------------------- 1 | uniform mat4 uMatrixProj; 2 | uniform vec4 uLayerRects[4]; 3 | uniform mat4 uLayerTransform; 4 | uniform vec4 uRenderTargetOffset; 5 | attribute vec4 aCoord; 6 | uniform mat4 uTextureTransform; 7 | uniform vec4 uTextureRects[4]; 8 | varying vec2 vTexCoord; 9 | void main() { 10 | int vertexID = int(aCoord.w); 11 | vec4 layerRect = uLayerRects[vertexID]; 12 | vec4 finalPosition = vec4(aCoord.xy * layerRect.zw + layerRect.xy, 0.0, 1.0); 13 | finalPosition = uLayerTransform * finalPosition; 14 | finalPosition.xyz /= finalPosition.w; 15 | finalPosition = finalPosition - uRenderTargetOffset; 16 | finalPosition.xyz *= finalPosition.w; 17 | finalPosition = uMatrixProj * finalPosition; 18 | vec4 textureRect = uTextureRects[vertexID]; 19 | vec2 texCoord = aCoord.xy * textureRect.zw + textureRect.xy; 20 | vTexCoord = (uTextureTransform * vec4(texCoord, 0.0, 1.0)).xy; 21 | gl_Position = finalPosition; 22 | } 23 | -------------------------------------------------------------------------------- /Shaders/lighting.vsh: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 inVertex, inColor; 4 | in vec3 inNormal; 5 | 6 | out vec4 color; 7 | 8 | uniform mat4 MVP, ModelView; 9 | uniform mat3 ModelViewIT; 10 | uniform vec3 lightDir; 11 | uniform vec4 ambient, diffuse, specular; 12 | uniform float shininess; 13 | 14 | void main() 15 | { 16 | // transform position to clip space 17 | gl_Position = MVP * inVertex; 18 | 19 | // transform position to eye space 20 | vec3 eyePosition = vec3(ModelView * inVertex); 21 | 22 | // transform normal to eye space (normalization skipped here: inNormal already normalized, matrix not scaled) 23 | vec3 eyeNormal = ModelViewIT * inNormal; 24 | 25 | // directional light ambient and diffuse contribution (lightDir alreay normalized) 26 | float NdotL = max(dot(eyeNormal, lightDir), 0.0); 27 | vec4 lightColor = ambient + diffuse * NdotL; 28 | 29 | if (NdotL > 0.0) 30 | { 31 | // half angle 32 | vec3 H = normalize(lightDir - normalize(eyePosition)); 33 | 34 | // specular contribution 35 | float NdotH = max(dot(eyeNormal, H), 0.0); 36 | lightColor += specular * pow(NdotH, shininess); 37 | } 38 | 39 | // apply directional light color and saturate result 40 | // to match fixed function behavior 41 | color = min(inColor * lightColor, 1.0); 42 | } 43 | -------------------------------------------------------------------------------- /Shaders/pattern.fsh: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision highp float; 3 | #endif 4 | #extension GL_OES_standard_derivatives : enable 5 | uniform vec3 iResolution; 6 | //uniform float iGlobalTime; 7 | // by Nikos Papadopoulos, 4rknova / 2013 8 | // WTFPL License 9 | 10 | #ifdef GL_ES 11 | precision highp float; 12 | #endif 13 | 14 | //#define ENABLE_SCROLLING 15 | const float S = 512.; // Scale 16 | 17 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 18 | { 19 | vec2 uv = floor(fragCoord.xy / iResolution.xy * S 20 | * vec2(iResolution.x / iResolution.y, 1) 21 | #ifdef ENABLE_SCROLLING 22 | + vec2(iGlobalTime, cos(iGlobalTime)) 23 | #endif // ENABLE_SCROLLING 24 | ); 25 | 26 | fragColor = vec4(vec3(mod(uv.x + uv.y, 2.)), 1); 27 | } 28 | 29 | void main() { 30 | vec4 color = vec4(0.0,0.0,0.0,1.0); 31 | mainImage( color, gl_FragCoord.xy ); 32 | color.w = 1.0; 33 | gl_FragColor = color; 34 | } -------------------------------------------------------------------------------- /Shaders/pattern.vsh: -------------------------------------------------------------------------------- 1 | attribute vec4 inVertex; 2 | 3 | void main() { 4 | gl_Position = vec4(inVertex.xy,0.0,1.0); 5 | } -------------------------------------------------------------------------------- /Shaders/texture.vsh: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 inVertex, inTexCoord; 4 | out vec2 textureCoord; 5 | 6 | uniform mat4 MVP; 7 | 8 | void main() 9 | { 10 | gl_Position = MVP * inVertex; 11 | textureCoord = inTexCoord.st; 12 | } 13 | -------------------------------------------------------------------------------- /Shaders/textureRect.fsh: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec2 textureCoord; 4 | out vec4 fragColor; 5 | 6 | uniform sampler2DRect tex; 7 | 8 | void main() 9 | { 10 | fragColor = texture(tex, textureCoord); 11 | } 12 | -------------------------------------------------------------------------------- /UtilSrc/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: debug.h 3 | Abstract: 4 | Utility functions for debugging. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #define glError() { \ 51 | GLenum err = glGetError(); \ 52 | if (err != GL_NO_ERROR) { \ 53 | printf("glError: %04x caught at %s:%u\n", err, __FILE__, __LINE__); \ 54 | } \ 55 | } 56 | 57 | -------------------------------------------------------------------------------- /UtilSrc/fileUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: fileUtil.h 3 | Abstract: 4 | Functions for loading source files. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #ifndef FILEUTIL_H 51 | #define FILEUTIL_H 52 | 53 | const char *pathForResource(const char *name); 54 | char *readFile(const char *name); 55 | 56 | #endif /* FILEUTIL_H */ 57 | -------------------------------------------------------------------------------- /UtilSrc/fileUtil.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: fileUtil.m 3 | Abstract: 4 | Functions for loading source files. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import 51 | #import 52 | 53 | const char *pathForResource(const char *name) 54 | { 55 | NSString *path = [[NSBundle mainBundle] pathForResource:@(name) ofType: nil]; 56 | return [path fileSystemRepresentation]; 57 | } 58 | 59 | char *readFile(const char *name) 60 | { 61 | struct stat statbuf; 62 | FILE *fh; 63 | char *source; 64 | 65 | fh = fopen(name, "r"); 66 | if (fh == 0) 67 | return 0; 68 | 69 | stat(name, &statbuf); 70 | source = (char *) malloc(statbuf.st_size + 1); 71 | fread(source, statbuf.st_size, 1, fh); 72 | source[statbuf.st_size] = '\0'; 73 | fclose(fh); 74 | 75 | return source; 76 | } 77 | -------------------------------------------------------------------------------- /UtilSrc/shaderUtil.c: -------------------------------------------------------------------------------- 1 | /* 2 | File: shaderUtil.c 3 | Abstract: 4 | Functions that compile, link and validate shader programs. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include "ShaderUtil.h" 55 | #include "debug.h" 56 | 57 | 58 | #define LogInfo printf 59 | #define LogError printf 60 | 61 | 62 | /* Compile a shader from the provided source(s) */ 63 | GLint glueCompileShader(GLenum target, GLsizei count, const GLchar **sources, GLuint *shader) 64 | { 65 | GLint logLength, status; 66 | 67 | *shader = glCreateShader(target); 68 | glShaderSource(*shader, count, sources, NULL); 69 | glCompileShader(*shader); 70 | glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); 71 | if (logLength > 0) 72 | { 73 | GLchar *log = (GLchar *)malloc(logLength); 74 | glGetShaderInfoLog(*shader, logLength, &logLength, log); 75 | LogInfo("Shader compile log:\n%s", log); 76 | free(log); 77 | } 78 | 79 | glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); 80 | if (status == 0) 81 | { 82 | int i; 83 | 84 | LogError("Failed to compile shader:\n"); 85 | for (i = 0; i < count; i++) 86 | LogInfo("%s", sources[i]); 87 | } 88 | glError(); 89 | 90 | return status; 91 | } 92 | 93 | 94 | /* Link a program with all currently attached shaders */ 95 | GLint glueLinkProgram(GLuint program) 96 | { 97 | GLint logLength, status; 98 | 99 | glLinkProgram(program); 100 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 101 | if (logLength > 0) 102 | { 103 | GLchar *log = (GLchar *)malloc(logLength); 104 | glGetProgramInfoLog(program, logLength, &logLength, log); 105 | LogInfo("Program link log:\n%s", log); 106 | free(log); 107 | } 108 | 109 | glGetProgramiv(program, GL_LINK_STATUS, &status); 110 | if (status == 0) 111 | LogError("Failed to link program %d", program); 112 | glError(); 113 | 114 | return status; 115 | } 116 | 117 | 118 | /* Validate a program (for i.e. inconsistent samplers) */ 119 | GLint glueValidateProgram(GLuint program) 120 | { 121 | GLint logLength, status; 122 | 123 | glValidateProgram(program); 124 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 125 | if (logLength > 0) 126 | { 127 | GLchar *log = (GLchar *)malloc(logLength); 128 | glGetProgramInfoLog(program, logLength, &logLength, log); 129 | LogInfo("Program validate log:\n%s", log); 130 | free(log); 131 | } 132 | 133 | glGetProgramiv(program, GL_VALIDATE_STATUS, &status); 134 | if (status == 0) 135 | LogError("Failed to validate program %d", program); 136 | glError(); 137 | 138 | return status; 139 | } 140 | 141 | 142 | /* Return named uniform location after linking */ 143 | GLint glueGetUniformLocation(GLuint program, const GLchar *uniformName) 144 | { 145 | GLint loc; 146 | 147 | loc = glGetUniformLocation(program, uniformName); 148 | 149 | return loc; 150 | } 151 | 152 | 153 | /* Convenience wrapper that compiles, links, enumerates uniforms and attribs */ 154 | GLint glueCreateProgram(const GLchar *vertSource, const GLchar *fragSource, 155 | GLsizei attribNameCt, const GLchar **attribNames, 156 | const GLint *attribLocations, 157 | GLsizei uniformNameCt, const GLchar **uniformNames, 158 | GLint *uniformLocations, 159 | GLuint *program) 160 | { 161 | GLuint vertShader = 0, fragShader = 0, prog = 0, status = 1, i; 162 | 163 | prog = glCreateProgram(); 164 | 165 | status *= glueCompileShader(GL_VERTEX_SHADER, 1, &vertSource, &vertShader); 166 | status *= glueCompileShader(GL_FRAGMENT_SHADER, 1, &fragSource, &fragShader); 167 | glAttachShader(prog, vertShader); 168 | glAttachShader(prog, fragShader); 169 | 170 | for (i = 0; i < attribNameCt; i++) 171 | { 172 | if(strlen(attribNames[i])) 173 | glBindAttribLocation(prog, attribLocations[i], attribNames[i]); 174 | } 175 | 176 | status *= glueLinkProgram(prog); 177 | status *= glueValidateProgram(prog); 178 | 179 | if (status) 180 | { 181 | for(i = 0; i < uniformNameCt; i++) 182 | { 183 | if(strlen(uniformNames[i])) 184 | uniformLocations[i] = glueGetUniformLocation(prog, uniformNames[i]); 185 | } 186 | *program = prog; 187 | } 188 | if (vertShader) 189 | glDeleteShader(vertShader); 190 | if (fragShader) 191 | glDeleteShader(fragShader); 192 | glError(); 193 | 194 | return status; 195 | } 196 | -------------------------------------------------------------------------------- /UtilSrc/shaderUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: shaderUtil.h 3 | Abstract: 4 | Functions that compile, link and validate shader programs. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #ifndef SHADERUTIL_H 51 | #define SHADERUTIL_H 52 | 53 | #import 54 | #import 55 | 56 | /* Shader Utilities */ 57 | GLint glueCompileShader(GLenum target, GLsizei count, const GLchar **sources, GLuint *shader); 58 | GLint glueLinkProgram(GLuint program); 59 | GLint glueValidateProgram(GLuint program); 60 | GLint glueGetUniformLocation(GLuint program, const GLchar *name); 61 | 62 | /* Shader Conveniences */ 63 | GLint glueCreateProgram(const GLchar *vertSource, const GLchar *fragSource, 64 | GLsizei attribNameCt, const GLchar **attribNames, 65 | const GLint *attribLocations, 66 | GLsizei uniformNameCt, const GLchar **uniformNames, 67 | GLint *uniformLocations, 68 | GLuint *program); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* SHADERUTIL_H */ 75 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: main.m 3 | Abstract: Application main entry point. 4 | Version: 1.2 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | return NSApplicationMain(argc, (const char **) argv); 53 | } 54 | --------------------------------------------------------------------------------