OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 static RendererGL* CreateDefault(ServiceLocator* service_locator); | 58 static RendererGL* CreateDefault(ServiceLocator* service_locator); |
59 virtual ~RendererGL(); | 59 virtual ~RendererGL(); |
60 | 60 |
61 // Initialises the renderer for use, claiming hardware resources. | 61 // Initialises the renderer for use, claiming hardware resources. |
62 virtual InitStatus InitPlatformSpecific(const DisplayWindow& display, | 62 virtual InitStatus InitPlatformSpecific(const DisplayWindow& display, |
63 bool off_screen); | 63 bool off_screen); |
64 | 64 |
65 // Released all hardware resources. | 65 // Released all hardware resources. |
66 virtual void Destroy(); | 66 virtual void Destroy(); |
67 | 67 |
68 // Turns fullscreen display on or off. | 68 // Overridden from Renderer. |
69 // Parameters: | 69 virtual bool GoFullscreen(const DisplayWindow& display, |
70 // fullscreen: true for fullscreen, false for in-browser display | 70 int mode_id); |
71 // display: a platform-specific display identifier | 71 |
72 // mode_id: a mode returned by GetDisplayModes, for fullscreen use. | 72 // Overridden from Renderer. |
73 // (Ignored in non-fullscreen mode.) | 73 virtual bool CancelFullscreen(const DisplayWindow& display, |
74 // Returns true on success, false on failure. | 74 int width, int height); |
75 virtual bool SetFullscreen(bool fullscreen, | |
76 const DisplayWindow& display, | |
77 int mode_id); | |
78 | 75 |
79 // Tells whether we're currently displayed fullscreen or not. | 76 // Tells whether we're currently displayed fullscreen or not. |
80 virtual bool fullscreen() const { | 77 virtual bool fullscreen() const { |
81 return fullscreen_; | 78 return fullscreen_; |
82 } | 79 } |
83 | 80 |
84 // Resizes the viewport in OpenGL. | 81 // Resizes the viewport in OpenGL. |
85 virtual void Resize(int width, int height); | 82 virtual void Resize(int width, int height); |
86 | 83 |
87 // Creates a StreamBank, returning a platform specific implementation class. | 84 // Creates a StreamBank, returning a platform specific implementation class. |
(...skipping 23 matching lines...) Expand all Loading... |
111 virtual RenderDepthStencilSurface::Ref CreateDepthStencilSurface( | 108 virtual RenderDepthStencilSurface::Ref CreateDepthStencilSurface( |
112 int width, | 109 int width, |
113 int height); | 110 int height); |
114 | 111 |
115 // Overridden from Renderer. | 112 // Overridden from Renderer. |
116 virtual const int* GetRGBAUByteNSwizzleTable(); | 113 virtual const int* GetRGBAUByteNSwizzleTable(); |
117 | 114 |
118 // Makes this renderer active on the current thread if it is not active | 115 // Makes this renderer active on the current thread if it is not active |
119 // already. | 116 // already. |
120 void MakeCurrentLazy() { | 117 void MakeCurrentLazy() { |
121 if (!IsCurrent()) MakeCurrent(); | 118 if (!IsCurrent()) |
| 119 MakeCurrent(); |
122 } | 120 } |
123 | 121 |
124 // Returns whether or not this renderer is active on the current thread. | 122 // Returns whether or not this renderer is active on the current thread. |
125 // In the Mac case, also requires the correct GL context to be active. | |
126 // Don't worry, the "get" calls are el cheapo. | 123 // Don't worry, the "get" calls are el cheapo. |
127 bool IsCurrent() { | 124 bool IsCurrent() { |
128 #ifdef OS_MACOSX | 125 #if defined(OS_MACOSX) |
129 if ((mac_agl_context_ != NULL) && | 126 if ((mac_agl_context_ != NULL) && |
130 (mac_agl_context_ != aglGetCurrentContext())) { | 127 (mac_agl_context_ == aglGetCurrentContext())) { |
131 return false; | 128 return true; |
132 } else if ((mac_cgl_context_ != NULL) && | 129 } else if ((mac_cgl_context_ != NULL) && |
133 (mac_cgl_context_ != CGLGetCurrentContext())) { | 130 (mac_cgl_context_ == CGLGetCurrentContext())) { |
134 return false; | 131 return true; |
135 } | 132 } |
| 133 #elif defined(OS_WIN) |
| 134 if ((gl_context_ != NULL) && |
| 135 (gl_context_ == wglGetCurrentContext())) { |
| 136 return true; |
| 137 } |
| 138 #elif defined(OS_LINUX) |
| 139 if ((context_ != NULL) && |
| 140 (context_ == glXGetCurrentContext())) { |
| 141 return true; |
| 142 } |
| 143 #else |
| 144 Error: must port RendererGL::IsCurrent() to your platform. |
136 #endif | 145 #endif |
137 return this == current_renderer_; | 146 return false; |
138 } | 147 } |
139 | 148 |
140 // Makes this renderer active on the current thread. | 149 // Makes this renderer active on the current thread. |
141 bool MakeCurrent(); | 150 bool MakeCurrent(); |
142 | 151 |
143 inline CGcontext cg_context() const { return cg_context_; } | 152 inline CGcontext cg_context() const { return cg_context_; } |
144 inline CGprofile cg_vertex_profile() const { return cg_vertex_profile_; } | 153 inline CGprofile cg_vertex_profile() const { return cg_vertex_profile_; } |
145 inline CGprofile cg_fragment_profile() const { return cg_fragment_profile_; } | 154 inline CGprofile cg_fragment_profile() const { return cg_fragment_profile_; } |
146 | 155 |
147 protected: | 156 protected: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 InitStatus InitCommonGL(); | 223 InitStatus InitCommonGL(); |
215 | 224 |
216 // Platform-independent GL destruction | 225 // Platform-independent GL destruction |
217 void DestroyCommonGL(); | 226 void DestroyCommonGL(); |
218 | 227 |
219 // Updates the helper constant used to remap D3D clip coordinates to GL ones. | 228 // Updates the helper constant used to remap D3D clip coordinates to GL ones. |
220 void UpdateHelperConstant(float width, float height); | 229 void UpdateHelperConstant(float width, float height); |
221 | 230 |
222 ServiceDependency<SemanticManager> semantic_manager_; | 231 ServiceDependency<SemanticManager> semantic_manager_; |
223 | 232 |
224 // Current renderer, tracking which renderer has last called wglMakeCurrent | |
225 // (or equivalent on other platforms). | |
226 // NOTE: this should really be thread-local, but since we don't handle | |
227 // multiple threads currently, this is enough. | |
228 static RendererGL *current_renderer_; | |
229 | |
230 // Indicates we're rendering fullscreen rather than in the plugin region. | 233 // Indicates we're rendering fullscreen rather than in the plugin region. |
231 bool fullscreen_; | 234 bool fullscreen_; |
232 | 235 |
233 | 236 |
234 #ifdef OS_WIN | 237 #ifdef OS_WIN |
235 // Handle to the GL device. | 238 // Handle to the GL device. |
236 HWND window_; | 239 HWND window_; |
237 HDC device_context_; | 240 HDC device_context_; |
238 HGLRC gl_context_; | 241 HGLRC gl_context_; |
239 #endif | 242 #endif |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 float polygon_offset_factor_; | 318 float polygon_offset_factor_; |
316 float polygon_offset_bias_; | 319 float polygon_offset_bias_; |
317 | 320 |
318 // Sets the stencils states for either front, back or both facing polys. | 321 // Sets the stencils states for either front, back or both facing polys. |
319 void SetStencilStates(GLenum face, const StencilStates& stencil_states); | 322 void SetStencilStates(GLenum face, const StencilStates& stencil_states); |
320 }; | 323 }; |
321 | 324 |
322 } // namespace o3d | 325 } // namespace o3d |
323 | 326 |
324 #endif // O3D_CORE_CROSS_GL_RENDERER_GL_H_ | 327 #endif // O3D_CORE_CROSS_GL_RENDERER_GL_H_ |
OLD | NEW |