Browse Source

Added getResolutions() to Renderer, and exposed it and getMultiSampleLevels() to script.
Scene::getComponentTypes() now sorts the list alphabetically.

Lasse Öörni 15 years ago
parent
commit
c2e9d8abf7

+ 12 - 1
Engine/Engine/RegisterRenderer.cpp

@@ -778,6 +778,16 @@ static void registerInstancedModel(asIScriptEngine* engine)
     registerRefCasts<Node, InstancedModel>(engine, "Node", "InstancedModel");
 }
 
+static CScriptArray* RendererGetResolutions(Renderer* ptr)
+{
+    return vectorToArray<IntVector2>(ptr->getResolutions(), "array<IntVector2>");
+}
+
+static CScriptArray* RendererGetMultiSampleLevels(Renderer* ptr)
+{
+    return vectorToArray<int>(ptr->getMultiSampleLevels(), "array<int>");
+}
+
 static Renderer* GetRenderer()
 {
     return getEngine()->getRenderer();
@@ -815,7 +825,8 @@ static void registerRenderer(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Renderer", "bool getHardwareDepthSupport() const", asMETHOD(Renderer, getHardwareDepthSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Renderer", "bool getHardwareShadowSupport() const", asMETHOD(Renderer, getHardwareShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Renderer", "bool getHiresShadowSupport() const", asMETHOD(Renderer, getHiresShadowSupport), asCALL_THISCALL);
-    
+    engine->RegisterObjectMethod("Renderer", "array<IntVector2>@ getResolutions() const", asFUNCTION(RendererGetResolutions), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Renderer", "array<int>@ getMultiSampleLevels() const", asFUNCTION(RendererGetMultiSampleLevels), asCALL_CDECL_OBJLAST);
     engine->RegisterGlobalFunction("Renderer@+ getRenderer()", asFUNCTION(GetRenderer), asCALL_CDECL);
     engine->RegisterGlobalFunction("Renderer@+ get_renderer()", asFUNCTION(GetRenderer), asCALL_CDECL);
 }

+ 1 - 3
Engine/Engine/RegisterScene.cpp

@@ -360,9 +360,7 @@ static void SceneLoadAsyncXML(File* file, Scene* ptr)
 
 static CScriptArray* SceneGetComponentTypes(Scene* ptr)
 {
-    std::vector<std::string> result;
-    ptr->getComponentTypes(result);
-    return vectorToArray(result, "array<string>");
+    return vectorToArray(ptr->getComponentTypes(), "array<string>");
 }
 
 static CScriptArray* SceneGetAllEntities(Scene* ptr)

+ 46 - 28
Engine/Renderer/Renderer.cpp

@@ -165,23 +165,17 @@ void Renderer::messagePump()
 
 void Renderer::setMode(RenderMode mode, int width, int height, bool fullscreen, bool vsync, int multiSample)
 {
-    // Find out the desktop defaults and the full screen mode display format (match desktop color depth)
-    D3DFORMAT fullscreenFormat = D3DFMT_X8R8G8B8;
-    DEVMODE settings;
-    EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &settings);
-    int desktopWidth = settings.dmPelsWidth;
-    int desktopHeight = settings.dmPelsHeight;
-    int desktopDepth = settings.dmBitsPerPel;
-    if (desktopDepth <= 16)
-        fullscreenFormat = D3DFMT_R5G6B5;
+    // Find out the full screen mode display format (match desktop color depth)
+    D3DFORMAT fullscreenFormat = mImpl->getDesktopFormat();
     
     // If zero dimensions, use the desktop default
     if ((width <= 0) || (height <= 0))
     {
         if (fullscreen)
         {
-            width = desktopWidth;
-            height = desktopHeight;
+            IntVector2 desktopResolution = mImpl->getDesktopResolution();
+            width = desktopResolution.mX;
+            height = desktopResolution.mY;
         }
         else
         {
@@ -221,27 +215,16 @@ void Renderer::setMode(RenderMode mode, int width, int height, bool fullscreen,
     // Check fullscreen mode validity. If not valid, revert to windowed
     if (fullscreen)
     {
-        unsigned numModes = mImpl->mInterface->GetAdapterModeCount(mImpl->mAdapter, fullscreenFormat);
-        bool match = false;
-        D3DDISPLAYMODE screenMode;
-        
-        for (unsigned i = 0; i < numModes; ++i)
+        std::vector<IntVector2> resolutions = getResolutions();
+        fullscreen = false;
+        for (unsigned i = 0; i < resolutions.size(); ++i)
         {
-            if (FAILED(mImpl->mInterface->EnumAdapterModes(mImpl->mAdapter, fullscreenFormat, i, &screenMode)))
-                continue;
-                
-            if (screenMode.Format != fullscreenFormat)
-                continue;
-                
-            if ((screenMode.Width == width) && (screenMode.Height == height))
+            if ((width == resolutions[i].mX) && (height == resolutions[i].mY))
             {
-                match = true;
+                fullscreen = true;
                 break;
             }
         }
-        
-        if (!match)
-            fullscreen = false;
     }
     
     // Fall back to non-multisampled if unsupported multisampling mode
@@ -1781,7 +1764,42 @@ unsigned Renderer::getWindowHandle() const
     return (unsigned)mImpl->mWindow;
 }
 
-std::vector<int> Renderer::getMultiSampleSupport() const
+std::vector<IntVector2> Renderer::getResolutions() const
+{
+    std::vector<IntVector2> ret;
+    if (!mImpl->mInterface)
+        return ret;
+    
+    D3DFORMAT fullscreenFormat = mImpl->getDesktopFormat();
+    unsigned numModes = mImpl->mInterface->GetAdapterModeCount(mImpl->mAdapter, fullscreenFormat);
+    D3DDISPLAYMODE displayMode;
+    
+    for (unsigned i = 0; i < numModes; ++i)
+    {
+        if (FAILED(mImpl->mInterface->EnumAdapterModes(mImpl->mAdapter, fullscreenFormat, i, &displayMode)))
+            continue;
+        if (displayMode.Format != fullscreenFormat)
+            continue;
+        IntVector2 newMode(displayMode.Width, displayMode.Height);
+        
+        // Check for duplicate before storing
+        bool unique = true;
+        for (unsigned j = 0; j < ret.size(); ++j)
+        {
+            if (ret[j] == newMode)
+            {
+                unique = false;
+                break;
+            }
+        }
+        if (unique)
+            ret.push_back(newMode);
+    }
+    
+    return ret;
+}
+
+std::vector<int> Renderer::getMultiSampleLevels() const
 {
     std::vector<int> ret;
     // No multisampling always supported

+ 3 - 1
Engine/Renderer/Renderer.h

@@ -249,8 +249,10 @@ public:
     bool getHardwareShadowSupport() const { return mHardwareShadowSupport; }
     //! Return whether 24-bit shadow maps are supported
     bool getHiresShadowSupport() const { return mHiresShadowSupport; }
+    //! Return supported fullscreen resolutions
+    std::vector<IntVector2> getResolutions() const;
     //! Return supported multisampling levels
-    std::vector<int> getMultiSampleSupport() const;
+    std::vector<int> getMultiSampleLevels() const;
     //! Return vertex buffer by index
     VertexBuffer* getVertexBuffer(unsigned index) const;
     //! Return index buffer

+ 14 - 0
Engine/Renderer/RendererImpl.cpp

@@ -55,3 +55,17 @@ bool RendererImpl::checkFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCE
     else
         return false;
 }
+
+D3DFORMAT RendererImpl::getDesktopFormat()
+{
+    DEVMODE settings;
+    EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &settings);
+    return settings.dmBitsPerPel <= 16 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
+}
+
+IntVector2 RendererImpl::getDesktopResolution()
+{
+    DEVMODE settings;
+    EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &settings);
+    return IntVector2(settings.dmPelsWidth, settings.dmPelsHeight);
+}

+ 4 - 0
Engine/Renderer/RendererImpl.h

@@ -48,6 +48,10 @@ public:
     const D3DADAPTER_IDENTIFIER9& getAdapterIdentifier() const { return mAdapterIdentifier; }
     //! Return whether a texture format and usage is supported
     bool checkFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
+    //! Return desktop texture format
+    D3DFORMAT getDesktopFormat();
+    //! Return desktop width/height
+    IntVector2 getDesktopResolution();
     
 private:
     //! Direct3D interface

+ 7 - 3
Engine/Scene/Scene.cpp

@@ -34,6 +34,8 @@
 #include "StringUtils.h"
 #include "XMLFile.h"
 
+#include <algorithm>
+
 #include "DebugNew.h"
 
 static const int ASYNC_MIN_FPS = 50;
@@ -806,11 +808,13 @@ EntityID Scene::getNextLocalEntityID()
     return current;
 }
 
-void Scene::getComponentTypes(std::vector<std::string>& dest) const
+std::vector<std::string> Scene::getComponentTypes() const
 {
-    dest.clear();
+    std::vector<std::string> ret;
     for (std::vector<SharedPtr<ComponentFactory> >::const_iterator i = mFactories.begin(); i != mFactories.end(); ++i)
-        (*i)->getComponentTypes(dest);
+        (*i)->getComponentTypes(ret);
+    std::sort(ret.begin(), ret.end());
+    return ret;
 }
 
 bool Scene::hasEntity(EntityID id) const

+ 1 - 1
Engine/Scene/Scene.h

@@ -147,7 +147,7 @@ public:
     //! Return component factories
     const std::vector<SharedPtr<ComponentFactory> >& getComponentFactories() const { return mFactories; }
     //! Return component types supported by the factories
-    void getComponentTypes(std::vector<std::string>& dest) const;
+    std::vector<std::string> getComponentTypes() const;
     //! Return whether has an entity by ID. This is preferred for performance
     bool hasEntity(EntityID id) const;
     //! Return whether has an entity by pointer. Needs to search through all entities