OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef PPAPI_CPP_GRAPHICS_3D_H_ | 5 #ifndef PPAPI_CPP_GRAPHICS_3D_H_ |
6 #define PPAPI_CPP_GRAPHICS_3D_H_ | 6 #define PPAPI_CPP_GRAPHICS_3D_H_ |
7 | 7 |
8 #include "ppapi/c/ppb_graphics_3d.h" | 8 #include "ppapi/c/ppb_graphics_3d.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 | 10 |
11 /// @file | |
12 /// This file defines the API to create a 3D rendering context in the browser. | |
11 namespace pp { | 13 namespace pp { |
12 | 14 |
13 class CompletionCallback; | 15 class CompletionCallback; |
14 class Instance; | 16 class Instance; |
15 class Var; | 17 class Var; |
16 | 18 |
19 /// This class represents a 3D rendering context in the browser. | |
17 class Graphics3D : public Resource { | 20 class Graphics3D : public Resource { |
18 public: | 21 public: |
19 /// Creates an is_null() Graphics3D object. | 22 /// Default constructor for creating an is_null() Graphics3D object. |
20 Graphics3D(); | 23 Graphics3D(); |
21 | 24 |
22 /// Creates and initializes a 3D rendering context. The returned context is | 25 /// A constructor for creating and and initializing a 3D rendering context. |
23 /// off-screen to start with. It must be attached to a plugin instance using | 26 /// The returned context is created off-screen and must be attached |
24 /// Instance::BindGraphics to draw on the web page. | 27 /// to a module instance using <code>Instance::BindGraphics</code> to draw on |
28 /// the web page. | |
25 /// | 29 /// |
26 /// @param[in] instance The instance that will own the new Graphics3D. | 30 /// @param[in] instance The instance that will own the new Graphics3D. |
27 /// | 31 /// |
28 /// @param[in] attrib_list The list of attributes for the context. It is a | 32 /// @param[in] attrib_list The list of attributes (name=value pairs) for the |
29 /// list of attribute name-value pairs in which each attribute is immediately | 33 /// context. The list is terminated with |
30 /// followed by the corresponding desired value. The list is terminated with | 34 /// <code>PP_GRAPHICS3DATTRIB_NONE</code>. The <code>attrib_list</code> may |
31 /// PP_GRAPHICS3DATTRIB_NONE. The attrib_list may be NULL or empty | 35 /// be <code>NULL</code> or empty (first attribute is |
32 /// (first attribute is PP_GRAPHICS3DATTRIB_NONE). If an attribute is not | 36 /// <code>PP_GRAPHICS3DATTRIB_NONE</code>). If an attribute is not specified |
33 /// specified in attrib_list, then the default value is used (it is said to | 37 /// in <code>attrib_list</code>, then the default value of 0 is used. |
alokp
2011/09/27 15:48:30
Not all default vales are 0.
jond
2011/10/11 15:46:52
Please clarify. All seemed to have Default: 0 in t
alokp
2011/10/17 16:30:32
For PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, the default
jond
2011/10/17 21:32:04
Done.
jond
2011/10/17 21:32:04
Done.
| |
34 /// be specified implicitly). | |
35 /// | 38 /// |
36 /// Attributes for the context are chosen according to an attribute-specific | 39 /// Attributes are classified into two categories: |
37 /// criteria. Attributes can be classified into two categories: | |
38 /// - AtLeast: The attribute value in the returned context meets or exceeds | |
39 /// the value specified in attrib_list. | |
40 /// - Exact: The attribute value in the returned context is equal to | |
41 /// the value specified in attrib_list. | |
42 /// | 40 /// |
43 /// Attributes that can be specified in attrib_list include: | 41 /// 1. AtLeast: The attribute value in the returned context will meet or |
44 /// - PP_GRAPHICS3DATTRIB_ALPHA_SIZE: Category: AtLeast Default: 0. | 42 /// exceed the value requested when creating the object. |
45 /// - PP_GRAPHICS3DATTRIB_BLUE_SIZE: Category: AtLeast Default: 0. | 43 /// 2. Exact: The attribute value in the returned context is equal to |
46 /// - PP_GRAPHICS3DATTRIB_GREEN_SIZE: Category: AtLeast Default: 0. | 44 /// the value requested when creating the object. |
47 /// - PP_GRAPHICS3DATTRIB_RED_SIZE: Category: AtLeast Default: 0. | 45 /// |
48 /// - PP_GRAPHICS3DATTRIB_DEPTH_SIZE: Category: AtLeast Default: 0. | 46 /// AtLeast attributes are (all have default values of 0): |
49 /// - PP_GRAPHICS3DATTRIB_STENCIL_SIZE: Category: AtLeast Default: 0. | 47 /// |
50 /// - PP_GRAPHICS3DATTRIB_SAMPLES: Category: AtLeast Default: 0. | 48 /// <code>PP_GRAPHICS3DATTRIB_ALPHA_SIZE</code> |
51 /// - PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS: Category: AtLeast Default: 0. | 49 /// <code>PP_GRAPHICS3DATTRIB_BLUE_SIZE</code> |
52 /// - PP_GRAPHICS3DATTRIB_WIDTH: Category: Exact Default: 0. | 50 /// <code>PP_GRAPHICS3DATTRIB_GREEN_SIZE</code> |
53 /// - PP_GRAPHICS3DATTRIB_HEIGHT: Category: Exact Default: 0. | 51 /// <code>PP_GRAPHICS3DATTRIB_RED_SIZE</code> |
54 /// - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR: | 52 /// <code>PP_GRAPHICS3DATTRIB_DEPTH_SIZE</code> |
55 /// Category: Exact Default: Implementation defined. | 53 /// <code>PP_GRAPHICS3DATTRIB_STENCIL_SIZE</code> |
54 /// <code>PP_GRAPHICS3DATTRIB_SAMPLES</code> | |
55 /// <code>PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS</code> | |
56 /// | |
57 /// Exact attributes are: | |
58 /// | |
59 /// <code>PP_GRAPHICS3DATTRIB_WIDTH</code> Default 0 | |
60 /// <code>PP_GRAPHICS3DATTRIB_HEIGHT</code> Default 0 | |
61 /// <code>PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR</code> | |
62 /// Default: Implementation defined. | |
56 /// | 63 /// |
57 /// On failure, the object will be is_null(). | 64 /// On failure, the object will be is_null(). |
58 Graphics3D(const Instance* instance, | 65 Graphics3D(const Instance* instance, |
59 const int32_t* attrib_list); | 66 const int32_t* attrib_list); |
60 | 67 |
61 /// Creates and initializes a 3D rendering context. The returned context is | 68 /// A constructor for creating and initializing a 3D rendering context. The |
62 /// off-screen to start with. It must be attached to a plugin instance using | 69 /// returned context is created off-screen. It must be attached to a |
63 /// Instance::BindGraphics to draw on the web page. | 70 /// module instance using <code>Instance::BindGraphics</code> to draw on the |
71 /// web page. | |
64 /// | 72 /// |
65 /// This is identical to the 2-argument version except that this version | 73 /// This constructor is identical to the 2-argument version except that this |
66 /// allows sharing of resources with another context. | 74 /// version allows sharing of resources with another context. |
67 /// | 75 /// |
68 /// @param[in] instance The instance that will own the new Graphics3D. | 76 /// @param[in] instance The instance that will own the new Graphics3D. |
69 /// | 77 /// |
70 /// @param[in] share_context Specifies the context with which all | 78 /// @param[in] share_context Specifies the context with which all |
71 /// shareable data will be shared. The shareable data is defined by the | 79 /// shareable data will be shared. The shareable data is defined by the |
72 /// client API (note that for OpenGL and OpenGL ES, shareable data excludes | 80 /// client API (note that for OpenGL and OpenGL ES, shareable data excludes |
73 /// texture objects named 0). An arbitrary number of Graphics3D resources | 81 /// texture objects named 0). An arbitrary number of Graphics3D resources |
74 /// can share data in this fashion. | 82 /// can share data in this fashion. |
75 // | 83 // |
76 /// @param[in] attrib_list The list of attributes for the context. See the | 84 /// @param[in] attrib_list The list of attributes for the context. See the |
77 /// 2-argument version for more information. | 85 /// 2-argument version of this constructor for more information. |
78 /// | 86 /// |
79 /// On failure, the object will be is_null(). | 87 /// On failure, the object will be is_null(). |
80 Graphics3D(const Instance* instance, | 88 Graphics3D(const Instance* instance, |
81 const Graphics3D& share_context, | 89 const Graphics3D& share_context, |
82 const int32_t* attrib_list); | 90 const int32_t* attrib_list); |
83 | 91 |
92 /// Destructor. | |
84 ~Graphics3D(); | 93 ~Graphics3D(); |
85 | 94 |
86 /// Retrieves the value for each attribute in attrib_list. The list | 95 /// GetAttribs() retrieves the value for each attribute in |
87 /// has the same structure as described for the constructor. | 96 /// <code>attrib_list</code>. The list has the same structure as described |
88 /// It is both input and output structure for this function. | 97 /// for the constructor. All attribute values specified in |
98 /// <code>pp_graphics_3d.h</code> can be retrieved. | |
89 /// | 99 /// |
90 /// All attributes specified in PPB_Graphics3D.Create can be queried for. | 100 /// @param[in] context The 3D rendering context whose values you want to |
91 /// On failure the following error codes may be returned: | 101 /// retrieve. |
92 /// - PP_ERROR_BADRESOURCE if context is invalid. | 102 /// @param[in/out] attrib_list The list of attributes (name=value pairs) for |
93 /// - PP_ERROR_BADARGUMENT if attrib_list is NULL or any attribute in the | 103 /// the context. The list is terminated with |
94 /// attrib_list is not a valid attribute. | 104 /// <code>PP_GRAPHICS3DATTRIB_NONE</code>. |
95 /// | 105 /// |
96 /// Example usage: To get the values for rgb bits in the color buffer, | 106 /// The following error codes may be returned on failure: |
97 /// this function must be called as following: | 107 /// |
108 /// PP_ERROR_BADRESOURCE if context is invalid. | |
109 /// PP_ERROR_BADARGUMENT if <code>attrib_list</code> is NULL or any attribute | |
110 /// in the <code>attrib_list</code> is not a valid attribute. | |
111 /// | |
112 /// <strong>Example:</code> | |
113 /// | |
114 /// <code> | |
98 /// int attrib_list[] = {PP_GRAPHICS3DATTRIB_RED_SIZE, 0, | 115 /// int attrib_list[] = {PP_GRAPHICS3DATTRIB_RED_SIZE, 0, |
99 /// PP_GRAPHICS3DATTRIB_GREEN_SIZE, 0, | 116 /// PP_GRAPHICS3DATTRIB_GREEN_SIZE, 0, |
100 /// PP_GRAPHICS3DATTRIB_BLUE_SIZE, 0, | 117 /// PP_GRAPHICS3DATTRIB_BLUE_SIZE, 0, |
101 /// PP_GRAPHICS3DATTRIB_NONE}; | 118 /// PP_GRAPHICS3DATTRIB_NONE}; |
102 /// GetAttribs(context, attrib_list); | 119 /// GetAttribs(context, attrib_list); |
103 /// int red_bits = attrib_list[1]; | 120 /// int red_bits = attrib_list[1]; |
104 /// int green_bits = attrib_list[3]; | 121 /// int green_bits = attrib_list[3]; |
105 /// int blue_bits = attrib_list[5]; | 122 /// int blue_bits = attrib_list[5]; |
123 /// </code> | |
124 /// | |
125 /// This example retrieves the values for rgb bits in the color buffer. | |
alokp
2011/09/27 15:48:30
Should this line be moved before the example?
jond
2011/10/11 15:46:52
Its okay to introduce the example and then discuss
| |
106 int32_t GetAttribs(int32_t* attrib_list) const; | 126 int32_t GetAttribs(int32_t* attrib_list) const; |
107 | 127 |
108 /// Sets the values for each attribute in attrib_list. The list | 128 /// SetAttribs() sets the values for each attribute in |
109 /// has the same structure as described for PPB_Graphics3D.Create. | 129 /// <code>attrib_list</code>. The list has the same structure as the list |
130 /// used in the constructors. | |
110 /// | 131 /// |
111 /// Attributes that can be specified are: | 132 /// Attributes that can be specified are: |
112 /// - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR | 133 /// - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR |
113 /// | 134 /// |
114 /// On failure the following error codes may be returned: | 135 /// On failure the following error codes may be returned: |
115 /// - PP_ERROR_BADRESOURCE if context is invalid. | 136 /// - PP_ERROR_BADRESOURCE if context is invalid. |
116 /// - PP_ERROR_BADARGUMENT if attrib_list is NULL or any attribute in the | 137 /// - PP_ERROR_BADARGUMENT if attrib_list is NULL or any attribute in the |
117 /// attrib_list is not a valid attribute. | 138 /// attrib_list is not a valid attribute. |
118 int32_t SetAttribs(int32_t* attrib_list); | 139 int32_t SetAttribs(int32_t* attrib_list); |
119 | 140 |
120 /// Resizes the backing surface for the context. | 141 /// ResizeBuffers() resizes the backing surface for the context. |
121 /// | 142 /// |
122 /// On failure the following error codes may be returned: | 143 /// @param[in] width The width. |
alokp
2011/09/27 15:48:30
The width of backing surface?
jond
2011/10/11 15:46:52
Done.
| |
123 /// - PP_ERROR_BADRESOURCE if context is invalid. | 144 /// @param[in] height The height. |
124 /// - PP_ERROR_BADARGUMENT if the value specified for width or height | |
125 /// is less than zero. | |
126 /// | 145 /// |
127 /// If the surface could not be resized due to insufficient resources, | 146 /// @return An int32_t containing <code>PP_ERROR_BADRESOURCE</code> if |
128 /// PP_ERROR_NOMEMORY error is returned on the next SwapBuffers callback. | 147 /// context is invalid or <code>PP_ERROR_BADARGUMENT</code> if the value |
148 /// specified for width or height is less than zero. | |
149 /// <code>PP_ERROR_NOMEMORY</code> might be returned on the next | |
150 /// SwapBuffers() callback if the surface could not be resized due to | |
151 /// insufficient resources. | |
129 int32_t ResizeBuffers(int32_t width, int32_t height); | 152 int32_t ResizeBuffers(int32_t width, int32_t height); |
130 | 153 |
131 /// Makes the contents of the color buffer available for compositing. | 154 /// SwapBuffers() makes the contents of the color buffer available for |
132 /// This function has no effect on off-screen surfaces - ones not bound | 155 /// compositing. This function has no effect on off-screen surfaces: surfaces |
133 /// to any plugin instance. The contents of ancillary buffers are always | 156 /// not bound to any module instance. The contents of ancillary buffers are |
134 /// undefined after calling SwapBuffers. The contents of the color buffer are | 157 /// always undefined after calling SwapBuffers(). The contents of the color |
135 /// undefined if the value of the PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR attribute | 158 /// buffer are undefined if the value of the |
136 /// of context is not PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED. | 159 /// <code>PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR</code> attribute of context is |
160 /// not <code>PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED</code>. | |
137 /// | 161 /// |
138 /// SwapBuffers runs in asynchronous mode. Specify a callback function and the | 162 /// SwapBuffers() runs in asynchronous mode. Specify a callback function and |
139 /// argument for that callback function. The callback function will be | 163 /// the argument for that callback function. The callback function will be |
140 /// executed on the calling thread after the color buffer has been composited | 164 /// executed on the calling thread after the color buffer has been composited |
141 /// with rest of the html page. While you are waiting for a SwapBuffers | 165 /// with rest of the html page. While you are waiting for a SwapBuffers() |
142 /// callback, additional calls to SwapBuffers will fail. | 166 /// callback, additional calls to SwapBuffers() will fail. |
143 /// | 167 /// |
144 /// Because the callback is executed (or thread unblocked) only when the | 168 /// Because the callback is executed (or thread unblocked) only when the |
145 /// plugin's current state is actually on the screen, this function provides a | 169 /// instance's current state is actually on the screen, this function |
146 /// way to rate limit animations. By waiting until the image is on the screen | 170 /// provides a way to rate limit animations. By waiting until the image is on |
147 /// before painting the next frame, you can ensure you're not generating | 171 /// the screen before painting the next frame, you can ensure you're not |
148 /// updates faster than the screen can be updated. | 172 /// generating updates faster than the screen can be updated. |
149 /// | 173 /// |
150 /// SwapBuffers performs an implicit flush operation on context. | 174 /// SwapBuffers() performs an implicit flush operation on context. |
151 /// If the context gets into an unrecoverable error condition while | 175 /// If the context gets into an unrecoverable error condition while |
152 /// processing a command, the error code will be returned as the argument | 176 /// processing a command, the error code will be returned as the argument |
153 /// for the callback. The callback may return the following error codes: | 177 /// for the callback. The callback may return the following error codes: |
154 /// - PP_ERROR_NOMEMORY | |
155 /// - PP_ERROR_CONTEXT_LOST | |
156 /// Note that the same error code may also be obtained by calling GetError. | |
157 /// | 178 /// |
158 /// On failure SwapBuffers may return the following error codes: | 179 /// <code>PP_ERROR_NOMEMORY</code> |
159 /// - PP_ERROR_BADRESOURCE if context is invalid. | 180 /// <code>PP_ERROR_CONTEXT_LOST</code> |
160 /// - PP_ERROR_BADARGUMENT if callback is invalid. | 181 /// |
182 /// Note that the same error code may also be obtained by calling GetError(). | |
183 /// | |
184 /// param[in] cc A <code>CompletionCallback</code> to be called upon | |
185 /// completion of SwapBuffers(). | |
186 /// | |
187 /// @return An int32_t containing <code>PP_ERROR_BADRESOURCE</code> if | |
188 /// context is invalid or <code>PP_ERROR_BADARGUMENT</code> if callback is | |
189 /// invalid. | |
161 int32_t SwapBuffers(const CompletionCallback& cc); | 190 int32_t SwapBuffers(const CompletionCallback& cc); |
162 }; | 191 }; |
163 | 192 |
164 } // namespace pp | 193 } // namespace pp |
165 | 194 |
166 #endif // PPAPI_CPP_GRAPHICS_3D_H_ | 195 #endif // PPAPI_CPP_GRAPHICS_3D_H_ |
167 | 196 |
OLD | NEW |