OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 define([ | 5 define([ |
6 "console", | 6 "console", |
7 "mojo/apps/js/bindings/connector", | 7 "mojo/apps/js/bindings/connector", |
8 "mojo/apps/js/bindings/core", | 8 "mojo/apps/js/bindings/core", |
| 9 "mojo/apps/js/bindings/gl", |
9 "mojo/apps/js/bindings/threading", | 10 "mojo/apps/js/bindings/threading", |
10 "mojom/native_viewport", | 11 "mojom/native_viewport", |
11 "mojom/gles2", | 12 "mojom/gles2", |
12 ], function(console, | 13 ], function(console, |
13 connector, | 14 connector, |
14 core, | 15 core, |
| 16 gljs, |
15 threading, | 17 threading, |
16 nativeViewport, | 18 nativeViewport, |
17 gles2) { | 19 gles2) { |
18 | 20 |
| 21 const VERTEX_SHADER_SOURCE = |
| 22 "uniform mat4 u_mvpMatrix; \n" + |
| 23 "attribute vec4 a_position; \n" + |
| 24 "void main() \n" + |
| 25 "{ \n" + |
| 26 " gl_Position = u_mvpMatrix * a_position; \n" + |
| 27 "} \n"; |
| 28 |
19 function NativeViewportClientImpl() { | 29 function NativeViewportClientImpl() { |
20 } | 30 } |
21 | 31 |
| 32 // TODO(aa): It is a bummer to need this stub object in JavaScript. We should |
| 33 // have a 'client' object that contains both the sending and receiving bits of |
| 34 // the client side of the interface. Since JS is loosely typed, we do not need |
| 35 // a separate base class to inherit from to receive callbacks. |
22 NativeViewportClientImpl.prototype = | 36 NativeViewportClientImpl.prototype = |
23 Object.create(nativeViewport.NativeViewportClientStub.prototype); | 37 Object.create(nativeViewport.NativeViewportClientStub.prototype); |
24 | 38 |
25 NativeViewportClientImpl.prototype.didOpen = function() { | 39 NativeViewportClientImpl.prototype.didOpen = function() { |
26 console.log("NativeViewportClientImpl.prototype.DidOpen"); | 40 console.log("NativeViewportClientImpl.prototype.DidOpen"); |
27 }; | 41 }; |
28 | 42 |
| 43 |
29 function GLES2ClientImpl() { | 44 function GLES2ClientImpl() { |
30 } | 45 } |
31 | 46 |
32 GLES2ClientImpl.prototype = | 47 GLES2ClientImpl.prototype = |
33 Object.create(gles2.GLES2ClientStub.prototype); | 48 Object.create(gles2.GLES2ClientStub.prototype); |
34 | 49 |
35 GLES2ClientImpl.prototype.didCreateContext = function(encoded, | 50 GLES2ClientImpl.prototype.didCreateContext = function(encoded, |
36 width, | 51 width, |
37 height) { | 52 height) { |
38 console.log("GLES2ClientImpl.prototype.didCreateContext"); | 53 console.log("GLES2ClientImpl.prototype.didCreateContext"); |
39 // Need to call MojoGLES2MakeCurrent(encoded) in C++. | 54 var gl = new gljs.Context(encoded, width, height); |
40 // TODO(abarth): Should we handle some of this GL setup in C++? | 55 |
| 56 var shader = gl.createShader(gl.VERTEX_SHADER); |
| 57 console.log("shader is: ", String(shader)); |
| 58 gl.shaderSource(shader, VERTEX_SHADER_SOURCE); |
| 59 gl.compileShader(shader); |
| 60 console.log("all done"); |
41 }; | 61 }; |
42 | 62 |
43 GLES2ClientImpl.prototype.contextLost = function() { | 63 GLES2ClientImpl.prototype.contextLost = function() { |
44 console.log("GLES2ClientImpl.prototype.contextLost"); | 64 console.log("GLES2ClientImpl.prototype.contextLost"); |
45 }; | 65 }; |
46 | 66 |
47 var nativeViewportConnection = null; | |
48 var gles2Connection = null; | |
49 | |
50 return function(handle) { | 67 return function(handle) { |
51 nativeViewportConnection = new connector.Connection( | 68 var nativeViewportConnection = new connector.Connection( |
52 handle, | 69 handle, |
53 NativeViewportClientImpl, | 70 NativeViewportClientImpl, |
54 nativeViewport.NativeViewportProxy); | 71 nativeViewport.NativeViewportProxy); |
55 | 72 |
56 var gles2Handles = core.createMessagePipe(); | 73 var gles2Handles = core.createMessagePipe(); |
57 gles2Connection = new connector.Connection( | 74 var gles2Connection = new connector.Connection( |
58 gles2Handles.handle0, GLES2ClientImpl, gles2.GLES2Proxy); | 75 gles2Handles.handle0, GLES2ClientImpl, gles2.GLES2Proxy); |
59 | 76 |
60 nativeViewportConnection.remote.open(); | 77 nativeViewportConnection.remote.open(); |
61 nativeViewportConnection.remote.createGLES2Context(gles2Handles.handle1); | 78 nativeViewportConnection.remote.createGLES2Context(gles2Handles.handle1); |
62 }; | 79 }; |
63 }); | 80 }); |
OLD | NEW |