added SetDisplayArea, GetDisplayArea was used in a confusing way
[blender-staging.git] / source / gameengine / Rasterizer / RAS_OpenGLRasterizer / RAS_OpenGLRasterizer.cpp
index 3fe5e26abc367e0149fdefba0932eae655c2f3d7..5b732e802f6847341b3d7ef6eed5c622c13b46f3 100644 (file)
@@ -81,7 +81,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
        m_motionblurvalue(-1.0),
        m_texco_num(0),
        m_attrib_num(0),
-       m_last_blendmode(GPU_BLEND_SOLID),
+       //m_last_blendmode(GPU_BLEND_SOLID),
        m_last_frontface(true),
        m_materialCachingInfo(0)
 {
@@ -118,7 +118,8 @@ bool RAS_OpenGLRasterizer::Init()
 
        glDisable(GL_BLEND);
        glDisable(GL_ALPHA_TEST);
-       m_last_blendmode = GPU_BLEND_SOLID;
+       //m_last_blendmode = GPU_BLEND_SOLID;
+       GPU_set_material_blend_mode(GPU_BLEND_SOLID);
 
        glFrontFace(GL_CCW);
        m_last_frontface = true;
@@ -288,7 +289,8 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
 
        glDisable(GL_BLEND);
        glDisable(GL_ALPHA_TEST);
-       m_last_blendmode = GPU_BLEND_SOLID;
+       //m_last_blendmode = GPU_BLEND_SOLID;
+       GPU_set_material_blend_mode(GPU_BLEND_SOLID);
 
        glFrontFace(GL_CCW);
        m_last_frontface = true;
@@ -384,6 +386,7 @@ void RAS_OpenGLRasterizer::EndFrame()
 
 void RAS_OpenGLRasterizer::SetRenderArea()
 {
+       RAS_Rect area;
        // only above/below stereo method needs viewport adjustment
        switch (m_stereomode)
        {
@@ -392,19 +395,21 @@ void RAS_OpenGLRasterizer::SetRenderArea()
                        {
                                case RAS_STEREO_LEFTEYE:
                                        // upper half of window
-                                       m_2DCanvas->GetDisplayArea().SetLeft(0);
-                                       m_2DCanvas->GetDisplayArea().SetBottom(m_2DCanvas->GetHeight() -
+                                       area.SetLeft(0);
+                                       area.SetBottom(m_2DCanvas->GetHeight() -
                                                int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
        
-                                       m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
-                                       m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
+                                       area.SetRight(int(m_2DCanvas->GetWidth()));
+                                       area.SetTop(int(m_2DCanvas->GetHeight()));
+                                       m_2DCanvas->SetDisplayArea(&area);
                                        break;
                                case RAS_STEREO_RIGHTEYE:
                                        // lower half of window
-                                       m_2DCanvas->GetDisplayArea().SetLeft(0);
-                                       m_2DCanvas->GetDisplayArea().SetBottom(0);
-                                       m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
-                                       m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
+                                       area.SetLeft(0);
+                                       area.SetBottom(0);
+                                       area.SetRight(int(m_2DCanvas->GetWidth()));
+                                       area.SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
+                                       m_2DCanvas->SetDisplayArea(&area);
                                        break;
                        }
                        break;
@@ -413,26 +418,29 @@ void RAS_OpenGLRasterizer::SetRenderArea()
                        {
                                case RAS_STEREO_LEFTEYE:
                                        // Left half of window
-                                       m_2DCanvas->GetDisplayArea().SetLeft(0);
-                                       m_2DCanvas->GetDisplayArea().SetBottom(0);
-                                       m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth()/2);
-                                       m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
+                                       area.SetLeft(0);
+                                       area.SetBottom(0);
+                                       area.SetRight(m_2DCanvas->GetWidth()/2);
+                                       area.SetTop(m_2DCanvas->GetHeight());
+                                       m_2DCanvas->SetDisplayArea(&area);
                                        break;
                                case RAS_STEREO_RIGHTEYE:
                                        // Right half of window
-                                       m_2DCanvas->GetDisplayArea().SetLeft(m_2DCanvas->GetWidth()/2);
-                                       m_2DCanvas->GetDisplayArea().SetBottom(0);
-                                       m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth());
-                                       m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
+                                       area.SetLeft(m_2DCanvas->GetWidth()/2);
+                                       area.SetBottom(0);
+                                       area.SetRight(m_2DCanvas->GetWidth());
+                                       area.SetTop(m_2DCanvas->GetHeight());
+                                       m_2DCanvas->SetDisplayArea(&area);
                                        break;
                        }
                        break;
                default:
                        // every available pixel
-                       m_2DCanvas->GetDisplayArea().SetLeft(0);
-                       m_2DCanvas->GetDisplayArea().SetBottom(0);
-                       m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
-                       m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
+                       area.SetLeft(0);
+                       area.SetBottom(0);
+                       area.SetRight(int(m_2DCanvas->GetWidth()));
+                       area.SetTop(int(m_2DCanvas->GetHeight()));
+                       m_2DCanvas->SetDisplayArea(&area);
                        break;
        }
 }
@@ -449,10 +457,10 @@ RAS_IRasterizer::StereoMode RAS_OpenGLRasterizer::GetStereoMode()
 
 bool RAS_OpenGLRasterizer::Stereo()
 {
-       if(m_stereomode == RAS_STEREO_NOSTEREO || m_stereomode == RAS_STEREO_DOME)
-               return false;
-       else
+       if(m_stereomode > RAS_STEREO_NOSTEREO) // > 0
                return true;
+       else
+               return false;
 }
 
 bool RAS_OpenGLRasterizer::InterlacedStereo()
@@ -787,7 +795,10 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi)
                                GPU_material_vertex_attributes(GPU_material_from_blender(blscene, blmat), &current_gpu_attribs);
                        else
                                memset(&current_gpu_attribs, 0, sizeof(current_gpu_attribs));
+                       // DM draw can mess up blending mode, restore at the end
+                       int current_blend_mode = GPU_get_material_blend_mode();
                        ms.m_pDerivedMesh->drawFacesGLSL(ms.m_pDerivedMesh, CheckMaterialDM);
+                       GPU_set_material_blend_mode(current_blend_mode);
                } else {
                        ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol);
                }
@@ -1096,6 +1107,8 @@ void RAS_OpenGLRasterizer::DisableMotionBlur()
 
 void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
 {
+       GPU_set_material_blend_mode(blendmode);
+/*
        if(blendmode == m_last_blendmode)
                return;
 
@@ -1122,6 +1135,7 @@ void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
        }
 
        m_last_blendmode = blendmode;
+*/
 }
 
 void RAS_OpenGLRasterizer::SetFrontFace(bool ccw)