diff options
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/core/cross/renderer.h | 8 | ||||
-rw-r--r-- | o3d/core/win/d3d9/renderer_d3d9.cc | 29 | ||||
-rw-r--r-- | o3d/plugin/cross/o3d_glue.cc | 16 | ||||
-rw-r--r-- | o3d/plugin/cross/o3d_glue.h | 12 | ||||
-rw-r--r-- | o3d/plugin/idl/client.idl | 83 | ||||
-rw-r--r-- | o3d/plugin/idl/effect.idl | 2 | ||||
-rw-r--r-- | o3d/samples/assets/fullscreen.png | bin | 865 -> 988 bytes | |||
-rw-r--r-- | o3d/samples/convolution.html | 2 | ||||
-rw-r--r-- | o3d/samples/fullscreen.html | 28 |
9 files changed, 127 insertions, 53 deletions
diff --git a/o3d/core/cross/renderer.h b/o3d/core/cross/renderer.h index 3f96456..55ec2be 100644 --- a/o3d/core/cross/renderer.h +++ b/o3d/core/cross/renderer.h @@ -104,6 +104,14 @@ class Renderer { INITIALIZATION_ERROR, }; + // This is exposed to JavaScript, but as long as users always refer to it + // symbolically, it should be possible to change it without breaking anyone. + // NOTE: windows d3d display modes are internally implemented via adding 1 to + // their normal values of [0, NUM) so as not to collide with this value. + enum DisplayModes { + DISPLAY_MODE_DEFAULT = 0 + }; + // A StateHandler takes a param and sets or resets a render state. class StateHandler { public: diff --git a/o3d/core/win/d3d9/renderer_d3d9.cc b/o3d/core/win/d3d9/renderer_d3d9.cc index 0c3c5b2..8001043 100644 --- a/o3d/core/win/d3d9/renderer_d3d9.cc +++ b/o3d/core/win/d3d9/renderer_d3d9.cc @@ -1295,8 +1295,9 @@ void RendererD3D9::GetDisplayModes(std::vector<DisplayMode> *modes) { LOG(ERROR) << "Failed to enumerate adapter display modes."; } else { DCHECK(mode.Format == D3DFMT_X8R8G8B8); + // Display mode IDs are one higher than D3D display modes. modes_found.push_back( - DisplayMode(mode.Width, mode.Height, mode.RefreshRate, i)); + DisplayMode(mode.Width, mode.Height, mode.RefreshRate, i + 1)); } } modes->swap(modes_found); @@ -1304,10 +1305,17 @@ void RendererD3D9::GetDisplayModes(std::vector<DisplayMode> *modes) { bool RendererD3D9::GetDisplayMode(int id, DisplayMode *mode) { D3DDISPLAYMODE d3d_mode; - bool success = SUCCEEDED(d3d_->EnumAdapterModes(D3DADAPTER_DEFAULT, - D3DFMT_X8R8G8B8, - id, - &d3d_mode)); + bool success = false; + if (id == DISPLAY_MODE_DEFAULT) { + success = SUCCEEDED(d3d_->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, + &d3d_mode)); + } else { + // Display mode IDs are one higher than D3D display modes. + success = SUCCEEDED(d3d_->EnumAdapterModes(D3DADAPTER_DEFAULT, + D3DFMT_X8R8G8B8, + id - 1, + &d3d_mode)); + } if (success) { mode->Set(d3d_mode.Width, d3d_mode.Height, d3d_mode.RefreshRate, id); } @@ -1325,15 +1333,12 @@ bool RendererD3D9::SetFullscreen(bool fullscreen, int refresh_rate = 0; if (fullscreen) { // Look up the refresh rate. - D3DDISPLAYMODE mode; - if (FAILED(d3d_->EnumAdapterModes(D3DADAPTER_DEFAULT, - D3DFMT_X8R8G8B8, - mode_id, - &mode))) { - LOG(ERROR) << "Failed to EnumAdapterModes"; + DisplayMode mode; + if (!GetDisplayMode(mode_id, &mode)) { + LOG(ERROR) << "Failed to GetDisplayMode"; return false; } - refresh_rate = mode.RefreshRate; + refresh_rate = mode.refresh_rate(); showing_fullscreen_message_ = true; fullscreen_message_timer_.GetElapsedTimeAndReset(); // Reset the timer. } else { diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index f760e1b..e14bb00 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -669,6 +669,22 @@ int PluginObject::height() const { return 0; } +bool PluginObject::SetFullscreenClickRegion(int x, int y, int width, int height, + int mode_id) { + bool success = false; + o3d::DisplayMode mode; + // Make sure it's a valid ID first. + if (renderer()->GetDisplayMode(mode_id, &mode)) { + fullscreen_region_valid_ = true; + fullscreen_region_x_ = x; + fullscreen_region_y_ = y; + fullscreen_region_width_ = width; + fullscreen_region_height_ = height; + fullscreen_region_mode_id_ = mode_id; + success = true; + } + return success; +} // On Mac there is a different implementation in plugin_mac.mm. #ifndef OS_MACOSX diff --git a/o3d/plugin/cross/o3d_glue.h b/o3d/plugin/cross/o3d_glue.h index ebe2a44..1b49e02 100644 --- a/o3d/plugin/cross/o3d_glue.h +++ b/o3d/plugin/cross/o3d_glue.h @@ -306,15 +306,9 @@ class PluginObject: public NPObject { // user, as this region has no visible marker. The user is also responsible // for updating this region if the plugin gets resized, as we don't know // whether or how to scale it. - void SetFullscreenClickRegion(int x, int y, int width, int height, - int mode_id) { - fullscreen_region_valid_ = true; - fullscreen_region_x_ = x; - fullscreen_region_y_ = y; - fullscreen_region_width_ = width; - fullscreen_region_height_ = height; - fullscreen_region_mode_id_ = mode_id; - } + // Fails if the mode_id supplied isn't valid. Returns true on success. + bool SetFullscreenClickRegion(int x, int y, int width, int height, + int mode_id); void ClearFullscreenClickRegion() { fullscreen_region_valid_ = false; } diff --git a/o3d/plugin/idl/client.idl b/o3d/plugin/idl/client.idl index 0ac3b91..439f63b 100644 --- a/o3d/plugin/idl/client.idl +++ b/o3d/plugin/idl/client.idl @@ -53,18 +53,24 @@ callback void LostResourcesCallback(); callback void EventCallback(Event event_descriptor); +%[ + The Renderer class provides the abstract interface to each platform's + rendering library. +%] [binding_model=by_pointer, include="core/cross/renderer.h", nocpp, glue_iface] class Renderer { %[ The initialization status of the renderer. - \li UNINITIALIZED - \li SUCCESS The renderer is initialized. - \li GPU_NOT_UP_TO_SPEC The renderer determined the user's machine can not - run O3D - \li OUT_OF_RESOURCES The user's machine does not have enough graphic + + \var InitStatus, + \li UNINITIALIZED, + \li SUCCESS, The renderer is initialized. + \li GPU_NOT_UP_TO_SPEC, The renderer determined the user's machine cannot + run O3D. + \li OUT_OF_RESOURCES, The user's machine does not have enough graphic resources available to start another instance of the O3D renderer. - \li INITIALIZATION_ERROR Some unknown error like possibly drivers not being - installed correctly. + \li INITIALIZATION_ERROR, Some unknown error such as e.g. drivers not + being installed correctly. %] enum InitStatus { UNINITIALIZED, @@ -73,6 +79,18 @@ class Renderer { OUT_OF_RESOURCES, INITIALIZATION_ERROR }; + + %[ + This is used in SetFullscreenClickRegion to request the current display + mode, such that the change to full-screen mode won't change the screen + resolution or refresh rate. + + \var DisplayModes, + \li DISPLAY_MODE_DEFAULT + %] + enum DisplayModes { + DISPLAY_MODE_DEFAULT + }; }; %[ @@ -138,7 +156,7 @@ class Client { [const] ObjectArray GetObjectsByClassName(String class_name); %[ - \var Property, + \var RenderMode, \li RENDERMODE_CONTINUOUS, Draw as often as possible up to refresh rate. \li RENDERMODE_ON_DEMAND, Draw once then only when the OS requests it (like uncovering part of a window.) @@ -178,44 +196,54 @@ class Client { void RenderTree(RenderNode render_node); %[ - Returns an array of DisplayModes which are available for use in fullscreen + Returns an array of DisplayModes which are available for use in full-screen mode. %] [userglue, plugin_data] DisplayMode[] GetDisplayModes(); %[ - Makes a region of the plugin area that will invoke fullscreen mode if + Makes a region of the plugin area that will invoke full-screen mode if clicked. The developer is responsible for communicating this to the user, as this region has no visible marker. The developer is also responsible for updating this region if the plugin gets resized, as we don't know whether or - how to scale it. + how to scale it. There can be only one full-screen click region at a time; + calling this again will override any previous call. + + Returns true on success, false if the mode_id is invalid. %] [userglue, plugin_data] void SetFullscreenClickRegion(int x, int y, int width, int height, int mode_id); %[ - Cancels fullscreen display, reverting to displaying content only in the - plugin region. If the plugin is already not in fullscreen mode, this has - no effect. + Deactivates the plugin click region that was previously created with + SetFullscreenClickRegion(). + %] + [userglue, plugin_data] + void ClearFullscreenClickRegion(); + %[ + Cancels full-screen display, reverting to displaying content only in the + plugin region. If the plugin is already not in full-screen mode, this has + no effect. This does not deactivate the plugin click region--if the user + clicks there again, we'll go back to full-screen display. %] [userglue, plugin_data] void CancelFullscreenDisplay(); %[ - Whether content is displayed in fullscreen mode or in a plugin window. The - default is false [not fullscreen]. + Whether content is displayed in full-screen mode or in a plugin window. The + default is false [not full-screen]. %] [userglue_getter, getter, plugin_data] bool fullscreen; %[ - Returns the width of the current drawing area [plugin or fullscreen] in + Returns the width of the current drawing area [plugin or full-screen] in pixels. %] [userglue_getter, getter, plugin_data] int width; %[ - Returns the height of the current drawing area [plugin or fullscreen] in + Returns the height of the current drawing area [plugin or full-screen] in pixels. %] [userglue_getter, getter, plugin_data] @@ -305,12 +333,12 @@ class Client { void ClearLostResourcesCallback(); %[ - Sets a callback for a given event type. See @Event for a list of event - types. However, only mousedown, mousemove, mouseup, and dblclick will - actually do anything at present. - + Sets a callback for a given event type. + types. There can be only one callback for a given event type at a time; setting a new one deletes the old one. + + \sa Event for a list of event %] void SetEventCallback(String type, EventCallback? handler); @@ -493,8 +521,17 @@ class Client { void userglue_method_SetFullscreenClickRegion( void *plugin_data, o3d::Client *self, int x, int y, int width, int height, int mode_id) { + glue::_o3d::PluginObject *plugin = + static_cast<glue::_o3d::PluginObject*>(plugin_data); + if (!plugin->SetFullscreenClickRegion(x, y, width, height, mode_id)) { + O3D_ERROR(plugin->service_locator()) + << "Call to SetFullscreenClickRegion failed."; + } + } + void userglue_method_ClearFullscreenClickRegion( + void *plugin_data, o3d::Client *self) { static_cast<glue::_o3d::PluginObject*>(plugin_data)-> - SetFullscreenClickRegion(x, y, width, height, mode_id); + ClearFullscreenClickRegion(); } void userglue_method_CancelFullscreenDisplay( void *plugin_data, o3d::Client *self) { diff --git a/o3d/plugin/idl/effect.idl b/o3d/plugin/idl/effect.idl index b6d2243..3066a20 100644 --- a/o3d/plugin/idl/effect.idl +++ b/o3d/plugin/idl/effect.idl @@ -191,7 +191,7 @@ typedef EffectStreamInfo[] EffectStreamInfoArray; [userglue] EffectStreamInfoArray GetStreamInfo(); %[ - \var Property, + \var MatrixLoadOrder, \li ROW_MAJOR, Matrix parameters are loaded in row-major order (DX-style). \li COLUMN_MAJOR, Matrix parameters are loaded in column-major order (OpenGL-style). diff --git a/o3d/samples/assets/fullscreen.png b/o3d/samples/assets/fullscreen.png Binary files differindex 27a20c2..a4edb49 100644 --- a/o3d/samples/assets/fullscreen.png +++ b/o3d/samples/assets/fullscreen.png diff --git a/o3d/samples/convolution.html b/o3d/samples/convolution.html index 83fdede..2a21024 100644 --- a/o3d/samples/convolution.html +++ b/o3d/samples/convolution.html @@ -79,7 +79,7 @@ var g_finished = false; // for selenium testing. * @param {string} fileName filename of the scene. * @param {!o3d.Transform} parent parent node in the transform graph to * which to load the scene into. - * @param {!o3djs.rendergraph.ViewInfo} viewInfo who's view and projection will + * @param {!o3djs.rendergraph.ViewInfo} viewInfo whose view and projection will * be set from the scene after it's loaded. */ function loadScene(pack, fileName, parent, viewInfo) { diff --git a/o3d/samples/fullscreen.html b/o3d/samples/fullscreen.html index cf80c56..449de27 100644 --- a/o3d/samples/fullscreen.html +++ b/o3d/samples/fullscreen.html @@ -68,6 +68,7 @@ var g_pack; var g_finished = false; // for selenium testing var g_teapotRoot; var g_orthoRoot; +var g_bannerTexture; var g_o3dElement; /** @@ -120,7 +121,7 @@ function createBannerSurfaceAndClickableRegion(clientHeight, viewInfo) { var paramSampler = g_orthoRoot.createParam('texSampler0', 'ParamSampler'); paramSampler.value = sampler; - sampler.texture = texture; + g_bannerTexture = sampler.texture = texture; g_orthoRoot.addShape(g_planeShape); // Convert to a top-left-corner-based coordinate system from the @@ -137,8 +138,7 @@ function createBannerSurfaceAndClickableRegion(clientHeight, viewInfo) { g_orthoRoot.scale(texture.width, -texture.height, 1); o3djs.event.addEventListener(g_o3dElement, 'resize', handleResizeEvent); - g_client.setFullscreenClickRegion(10, clientHeight - texture.height - 10, - texture.width, texture.height, getFullscreenModeId()); + updateBanner(); } g_finished = true; // for selenium testing. }); @@ -302,23 +302,35 @@ function getFullscreenModeId() { } if (bestMode) { return bestMode.id; - } else { - return 0; // getDisplayModes isn't implemented on all platforms yet + } else { // getDisplayModes isn't implemented on all platforms yet. + return g_o3d.Renderer.DISPLAY_MODE_DEFAULT; } } function handleResizeEvent(event) { // Only show the fullscreen banner if we're in plugin mode. - g_orthoRoot.visible = !event.fullscreen; + g_orthoRoot.visible = !event.fullscreen && + document.getElementById("show_banner").checked; setupCamera(g_teapotRoot); } +function updateBanner() { + if (document.getElementById("show_banner").checked) { + g_client.setFullscreenClickRegion(10, + g_client.height - g_bannerTexture.height - 10, g_bannerTexture.width, + g_bannerTexture.height, getFullscreenModeId()); + g_orthoRoot.visible = true; + } else { + g_client.clearFullscreenClickRegion(); + g_orthoRoot.visible = false; + } +} </script> </head> <body> -<h1>Fullscreen mode.</h1> +<h1>Full-screen mode.</h1> This tutorial shows how to toggle between plugin and full-screen display. <p>It's built on top of helloworld.html; diff the two to see what changes were necessary. @@ -326,5 +338,7 @@ necessary. <!-- Start of O3D plugin --> <div id="o3d" style="width: 600px; height: 600px;"></div> <!-- End of O3D plugin --> +<input type="checkbox" id="show_banner" checked onclick=updateBanner()> +Show full-screen banner when not full-screen.</input> </body> </html> |