Browse Source

Added OpenGL version of GetMultiSampleLevels().
Fixed Direct3D9 version of GetMultiSampleLevels().

Lasse Öörni 14 years ago
parent
commit
f06fa1f2ac

+ 16 - 16
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -158,7 +158,7 @@ Graphics::Graphics(Context* context) :
     mode_(RENDER_FORWARD),
     mode_(RENDER_FORWARD),
     width_(0),
     width_(0),
     height_(0),
     height_(0),
-    multiSample_(0),
+    multiSample_(1),
     windowPosX_(0),
     windowPosX_(0),
     windowPosY_(0),
     windowPosY_(0),
     fullscreen_(false),
     fullscreen_(false),
@@ -269,6 +269,8 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
         }
         }
     }
     }
     
     
+    multiSample = Clamp(multiSample, 1, (int)D3DMULTISAMPLE_16_SAMPLES);
+
     if ((mode == mode_) && (width == width_) && (height == height_) && (fullscreen == fullscreen_) && (vsync == vsync_)
     if ((mode == mode_) && (width == width_) && (height == height_) && (fullscreen == fullscreen_) && (vsync == vsync_)
         && (multiSample == multiSample_))
         && (multiSample == multiSample_))
         return true;
         return true;
@@ -288,16 +290,12 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
     // Disable deferred  rendering if not supported
     // Disable deferred  rendering if not supported
     if ((mode == RENDER_DEFERRED) && (!deferredSupport_))
     if ((mode == RENDER_DEFERRED) && (!deferredSupport_))
         mode = RENDER_FORWARD;
         mode = RENDER_FORWARD;
-    
-    if (multiSample >= (int)D3DMULTISAMPLE_2_SAMPLES)
-        multiSample = Clamp(multiSample, (int)D3DMULTISAMPLE_NONE, (int)D3DMULTISAMPLE_16_SAMPLES);
-    else
-        multiSample = 0;
+
     // Note: GetMultiSample() will not reflect the actual hardware multisample mode, but rather what the caller wanted.
     // Note: GetMultiSample() will not reflect the actual hardware multisample mode, but rather what the caller wanted.
     // In deferred rendering mode, it is used to control temporal antialiasing
     // In deferred rendering mode, it is used to control temporal antialiasing
     multiSample_ = multiSample;
     multiSample_ = multiSample;
     if (mode != RENDER_FORWARD)
     if (mode != RENDER_FORWARD)
-        multiSample = 0;
+        multiSample = 1;
     
     
     // Check fullscreen mode validity. If not valid, revert to windowed
     // Check fullscreen mode validity. If not valid, revert to windowed
     if (fullscreen)
     if (fullscreen)
@@ -315,11 +313,11 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
     }
     }
     
     
     // Fall back to non-multisampled if unsupported multisampling mode
     // Fall back to non-multisampled if unsupported multisampling mode
-    if (multiSample)
+    if (multiSample > 1)
     {
     {
         if (FAILED(impl_->interface_->CheckDeviceMultiSampleType(impl_->adapter_, impl_->deviceType_, fullscreenFormat, FALSE,
         if (FAILED(impl_->interface_->CheckDeviceMultiSampleType(impl_->adapter_, impl_->deviceType_, fullscreenFormat, FALSE,
             (D3DMULTISAMPLE_TYPE)multiSample, NULL)))
             (D3DMULTISAMPLE_TYPE)multiSample, NULL)))
-            multiSample = 0;
+            multiSample = 1;
     }
     }
     
     
     // Save window placement if currently windowed
     // Save window placement if currently windowed
@@ -348,7 +346,7 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
     impl_->presentParams_.BackBufferWidth            = width;
     impl_->presentParams_.BackBufferWidth            = width;
     impl_->presentParams_.BackBufferHeight           = height;
     impl_->presentParams_.BackBufferHeight           = height;
     impl_->presentParams_.BackBufferCount            = 1;
     impl_->presentParams_.BackBufferCount            = 1;
-    impl_->presentParams_.MultiSampleType            = (D3DMULTISAMPLE_TYPE)multiSample;
+    impl_->presentParams_.MultiSampleType            = multiSample > 1 ? (D3DMULTISAMPLE_TYPE)multiSample : D3DMULTISAMPLE_NONE;
     impl_->presentParams_.MultiSampleQuality         = 0;
     impl_->presentParams_.MultiSampleQuality         = 0;
     impl_->presentParams_.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
     impl_->presentParams_.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
     impl_->presentParams_.hDeviceWindow              = impl_->window_;
     impl_->presentParams_.hDeviceWindow              = impl_->window_;
@@ -395,11 +393,11 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
     
     
     AdjustWindow(width, height, fullscreen);
     AdjustWindow(width, height, fullscreen);
     
     
-    if (!multiSample)
-        LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed"));
-    else
+    if (multiSample > 1)
         LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed") +
         LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed") +
         " multisample " + String(multiSample));
         " multisample " + String(multiSample));
+    else
+        LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed"));
     
     
     using namespace ScreenMode;
     using namespace ScreenMode;
     
     
@@ -1874,14 +1872,16 @@ PODVector<int> Graphics::GetMultiSampleLevels() const
 {
 {
     PODVector<int> ret;
     PODVector<int> ret;
     // No multisampling always supported
     // No multisampling always supported
-    ret.Push(0);
+    ret.Push(1);
     
     
     if (!impl_->interface_)
     if (!impl_->interface_)
         return ret;
         return ret;
     
     
+    D3DFORMAT fullscreenFormat = impl_->GetDesktopFormat();
+    
     for (unsigned i = (int)D3DMULTISAMPLE_2_SAMPLES; i < (int)D3DMULTISAMPLE_16_SAMPLES; ++i)
     for (unsigned i = (int)D3DMULTISAMPLE_2_SAMPLES; i < (int)D3DMULTISAMPLE_16_SAMPLES; ++i)
     {
     {
-        if (SUCCEEDED(impl_->interface_->CheckDeviceMultiSampleType(impl_->adapter_, impl_->deviceType_, D3DFMT_R8G8B8, FALSE,
+        if (SUCCEEDED(impl_->interface_->CheckDeviceMultiSampleType(impl_->adapter_, impl_->deviceType_, fullscreenFormat, FALSE,
             (D3DMULTISAMPLE_TYPE)i, NULL)))
             (D3DMULTISAMPLE_TYPE)i, NULL)))
             ret.Push(i);
             ret.Push(i);
     }
     }
@@ -2230,7 +2230,7 @@ void Graphics::CreateRenderTargets()
         // If deferred antialiasing is used, reserve screen buffer
         // If deferred antialiasing is used, reserve screen buffer
         // (later we will probably want the screen buffer reserved in any case, to do for example distortion effects,
         // (later we will probably want the screen buffer reserved in any case, to do for example distortion effects,
         // which will also be useful in forward rendering)
         // which will also be useful in forward rendering)
-        if (multiSample_)
+        if (multiSample_ > 1)
         {
         {
             screenBuffer_ = new Texture2D(context_);
             screenBuffer_ = new Texture2D(context_);
             screenBuffer_->SetSize(0, 0, GetRGBAFormat(), TEXTURE_RENDERTARGET);
             screenBuffer_->SetSize(0, 0, GetRGBAFormat(), TEXTURE_RENDERTARGET);

+ 1 - 1
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -208,7 +208,7 @@ public:
     int GetWidth() const { return width_; }
     int GetWidth() const { return width_; }
     /// Return window height
     /// Return window height
     int GetHeight() const { return height_; }
     int GetHeight() const { return height_; }
-    /// Return multisample mode (0 = no multisampling)
+    /// Return multisample mode (1 = no multisampling)
     int GetMultiSample() const { return multiSample_; }
     int GetMultiSample() const { return multiSample_; }
     /// Return whether window is fullscreen
     /// Return whether window is fullscreen
     bool GetFullscreen() const { return fullscreen_; }
     bool GetFullscreen() const { return fullscreen_; }

+ 49 - 6
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -119,7 +119,7 @@ Graphics::Graphics(Context* context_) :
     mode_(RENDER_FORWARD),
     mode_(RENDER_FORWARD),
     width_(0),
     width_(0),
     height_(0),
     height_(0),
-    multiSample_(0),
+    multiSample_(1),
     inModeChange_(0),
     inModeChange_(0),
     windowPosX_(0),
     windowPosX_(0),
     windowPosY_(0),
     windowPosY_(0),
@@ -183,6 +183,9 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
         return false;
         return false;
     }
     }
     
     
+    if (multiSample < 1)
+        multiSample = 1;
+    
     // If zero dimensions, use the desktop default
     // If zero dimensions, use the desktop default
     if ((width <= 0) || (height <= 0))
     if ((width <= 0) || (height <= 0))
     {
     {
@@ -341,11 +344,11 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
     // Create deferred rendering buffers as necessary
     // Create deferred rendering buffers as necessary
     CreateRenderTargets();
     CreateRenderTargets();
     
     
-    if (!multiSample)
-        LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed"));
-    else
+    if (multiSample > 1)
         LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed") +
         LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed") +
         " multisample " + String(multiSample));
         " multisample " + String(multiSample));
+    else
+        LOGINFO("Set screen mode " + String(width_) + "x" + String(height_) + " " + (fullscreen_ ? "fullscreen" : "windowed"));
     
     
     using namespace ScreenMode;
     using namespace ScreenMode;
     
     
@@ -1900,7 +1903,47 @@ PODVector<int> Graphics::GetMultiSampleLevels() const
 {
 {
     PODVector<int> ret;
     PODVector<int> ret;
     // No multisampling always supported
     // No multisampling always supported
-    ret.Push(0);
+    ret.Push(1);
+    
+    if ((_GLEE_WGL_ARB_pixel_format) && (impl_->deviceContext_))
+    {
+        int attributes[] = {
+            WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
+            WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
+            WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
+            WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
+            WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
+            WGL_SAMPLES_ARB, 2,
+            0, 0
+        };
+        
+        int pixelFormats[256];
+        unsigned numPixelFormats;
+        
+        wglChoosePixelFormatARB(impl_->deviceContext_, attributes, 0, 256, pixelFormats, &numPixelFormats);
+        for (unsigned i = 0; i < numPixelFormats; ++i)
+        {
+            int multiSampleQuery = WGL_SAMPLES_ARB;
+            int multiSampleLevel;
+            
+            wglGetPixelFormatAttribivARB(impl_->deviceContext_, pixelFormats[i], 0, 1, &multiSampleQuery, &multiSampleLevel);
+            if (multiSampleLevel > 1)
+            {
+                bool unique = true;
+                for (unsigned j = 0; j < ret.Size(); ++j)
+                {
+                    if (ret[j] == multiSampleLevel)
+                    {
+                        unique = false;
+                        break;
+                    }
+                }
+                
+                if (unique)
+                    ret.Push(multiSampleLevel);
+            }
+        }
+    }
     
     
     return ret;
     return ret;
 }
 }
@@ -2200,7 +2243,7 @@ void Graphics::CreateRenderTargets()
         // If deferred antialiasing is used, reserve screen buffer
         // If deferred antialiasing is used, reserve screen buffer
         // (later we will probably want the screen buffer reserved in any case, to do for example distortion effects,
         // (later we will probably want the screen buffer reserved in any case, to do for example distortion effects,
         // which will also be useful in forward rendering)
         // which will also be useful in forward rendering)
-        if (multiSample_)
+        if (multiSample_ > 1)
         {
         {
             screenBuffer_ = new Texture2D(context_);
             screenBuffer_ = new Texture2D(context_);
             screenBuffer_->SetSize(0, 0, GetRGBAFormat(), TEXTURE_RENDERTARGET);
             screenBuffer_->SetSize(0, 0, GetRGBAFormat(), TEXTURE_RENDERTARGET);

+ 1 - 1
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -213,7 +213,7 @@ public:
     int GetWidth() const { return width_; }
     int GetWidth() const { return width_; }
     /// Return window height
     /// Return window height
     int GetHeight() const { return height_; }
     int GetHeight() const { return height_; }
-    /// Return multisample mode (0 = no multisampling)
+    /// Return multisample mode (1 = no multisampling)
     int GetMultiSample() const { return multiSample_; }
     int GetMultiSample() const { return multiSample_; }
     /// Return whether window is fullscreen
     /// Return whether window is fullscreen
     bool GetFullscreen() const { return fullscreen_; }
     bool GetFullscreen() const { return fullscreen_; }

+ 1 - 1
Engine/Graphics/View.cpp

@@ -786,7 +786,7 @@ void View::RenderBatchesDeferred()
     Texture2D* depthBuffer = graphics_->GetDepthBuffer();
     Texture2D* depthBuffer = graphics_->GetDepthBuffer();
     
     
     // Check for deferred antialiasing (edge filter) in deferred mode. Only use it on the main view (null rendertarget)
     // Check for deferred antialiasing (edge filter) in deferred mode. Only use it on the main view (null rendertarget)
-    bool edgeFilter = (!renderTarget_) && (graphics_->GetMultiSample() > 0);
+    bool edgeFilter = (!renderTarget_) && (graphics_->GetMultiSample() > 1);
     RenderSurface* renderBuffer = edgeFilter ? graphics_->GetScreenBuffer()->GetRenderSurface() : renderTarget_;
     RenderSurface* renderBuffer = edgeFilter ? graphics_->GetScreenBuffer()->GetRenderSurface() : renderTarget_;
     
     
     // Calculate shader parameters needed only in deferred rendering
     // Calculate shader parameters needed only in deferred rendering