diff options
author | Valerio Virgillito | 2012-03-06 11:05:00 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-03-06 11:05:00 -0800 |
commit | 4540b5b4ea2065c3e0d67b46bba8b6764801fbea (patch) | |
tree | 4e1561530b1b90ea497bac8e41d193fa605e98b4 /js/lib/geom/shape-primitive.js | |
parent | 4e35725e6c9044c37bef28b8c8d36f4b5c89bfd9 (diff) | |
parent | 84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff) | |
download | ninja-4540b5b4ea2065c3e0d67b46bba8b6764801fbea.tar.gz |
Merge branch 'refs/heads/master' into panels
Diffstat (limited to 'js/lib/geom/shape-primitive.js')
-rw-r--r-- | js/lib/geom/shape-primitive.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js new file mode 100644 index 00000000..bf0087b2 --- /dev/null +++ b/js/lib/geom/shape-primitive.js | |||
@@ -0,0 +1,54 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | // Helper function for generating a RDGE primitive | ||
8 | var ShapePrimitive = {}; | ||
9 | |||
10 | ShapePrimitive.create = function(coords, normals, uvs, indices, primType, vertexCount) { | ||
11 | var renderer = g_Engine.getContext().renderer; | ||
12 | |||
13 | // to setup a primitive you must define it | ||
14 | // create a new primitive definition here to then fill out | ||
15 | var prim = new rdgePrimitiveDefinition(); | ||
16 | |||
17 | // the vertex definition declares how the data will be delivered to the shader | ||
18 | // the position of an element in array determines which attribute in a shader the | ||
19 | // data is bound to | ||
20 | prim.vertexDefinition = { | ||
21 | // this shows two ways to map this data to an attribute | ||
22 | "vert":{'type':renderer.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
23 | "a_pos":{'type':renderer.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
24 | |||
25 | "normal":{'type':renderer.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
26 | "a_nrm":{'type':renderer.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
27 | "a_normal":{'type':renderer.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
28 | |||
29 | "texcoord":{'type':renderer.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': renderer.BUFFER_STATIC}, | ||
30 | "a_texcoord":{'type':renderer.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': renderer.BUFFER_STATIC} | ||
31 | }; | ||
32 | |||
33 | // the actual data that correlates to the vertex definition | ||
34 | prim.bufferStreams = [ coords, normals, uvs ]; | ||
35 | |||
36 | // what type of buffers the data resides in, static is the most common case | ||
37 | prim.streamUsage = [ renderer.BUFFER_STATIC, renderer.BUFFER_STATIC, renderer.BUFFER_STATIC ]; | ||
38 | |||
39 | // this tells the renderer to draw the primitive as a list of triangles | ||
40 | prim.type = primType; | ||
41 | |||
42 | prim.indexUsage = renderer.BUFFER_STREAM; | ||
43 | prim.indexBuffer = indices; | ||
44 | |||
45 | // finally the primitive is created, buffers are generated and the system determines | ||
46 | // the data it needs to draw this primitive according to the previous definition | ||
47 | renderer.createPrimitive(prim, vertexCount); | ||
48 | |||
49 | return prim; | ||
50 | }; | ||
51 | |||
52 | if (typeof exports === "object") { | ||
53 | exports.ShapePrimitive = ShapePrimitive; | ||
54 | } \ No newline at end of file | ||