Browse Source

Moved ResetCanvas Into C++

If C++ is calling a C++ function, it shouldn't have to call it through a scrap of script code sitting in the app core. Engine code goes in C++.
Peter Robinson 3 years ago
parent
commit
8f313450a6

+ 31 - 24
engine/source/platform/platformVideo.cc

@@ -46,9 +46,9 @@ bool        DisplayDevice::smIsFullScreen;
 void Video::init()
 {
     Con::printSeparator();
-    
+
     Con::printf("Video initialization:");
-    
+
     destroy();
 }
 
@@ -194,9 +194,7 @@ bool Video::setDevice( const char *renderName, U32 width, U32 height, U32 bpp, b
          Game->textureResurrect();
          smNeedResurrect = false;
       }
-      //if (sgOriginalGamma != -1.0 || Video::getGammaCorrection(sgOriginalGamma))
-         //Video::setGammaCorrection(sgOriginalGamma + sgGammaCorrection);
-      Con::evaluate("resetCanvas();");
+      Video::resetCanvas();
    }
 
     // Show Maximum Texture Size reported by the graphics hardware.
@@ -211,6 +209,15 @@ bool Video::setDevice( const char *renderName, U32 width, U32 height, U32 bpp, b
    return( result );
 }
 
+void Video::resetCanvas()
+{
+    GuiCanvas* Canvas = Sim::findObject<GuiCanvas>("Canvas");
+    if (Canvas != NULL)
+    {
+        Canvas->paint();
+    }
+}
+
 extern bool retinaEnabled;
 
 //------------------------------------------------------------------------------
@@ -226,13 +233,13 @@ bool Video::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen )
          height = IOS_DEFAULT_RESOLUTION_Y;
       if(bpp == 0)
          bpp = IOS_DEFAULT_RESOLUTION_BIT_DEPTH;
-      
+
       //if(retinaEnabled)
       //{
       //    width *=2;
       //    height *=2;
       //}
-       
+
 #elif TORQUE_OS_ANDROID
       if(width == 0)
 	     width = _AndroidGetScreenWidth();
@@ -248,15 +255,15 @@ bool Video::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen )
       if(bpp == 0)
          bpp = MIN_RESOLUTION_BIT_DEPTH;
 #endif// TORQUE_OS_IOS
-      
+
       smCritical = true;
-      bool result = smCurrentDevice->setScreenMode( width, height, bpp, fullScreen );		
+      bool result = smCurrentDevice->setScreenMode( width, height, bpp, fullScreen );
     smCritical = false;
 
        return( result );
    }
 
-   return( false );	
+   return( false );
 }
 
 
@@ -264,7 +271,7 @@ bool Video::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen )
 void Video::deactivate( bool force )
 {
    if ( smCritical ) return;
-   
+
    bool doDeactivate = force ? true : DisplayDevice::isFullScreen();
 
    Game->gameDeactivate( doDeactivate );
@@ -284,7 +291,7 @@ void Video::deactivate( bool force )
 void Video::reactivate( bool force )
 {
    if ( smCritical ) return;
-   
+
    bool doReactivate = force ? true : DisplayDevice::isFullScreen();
 
    if ( smCurrentDevice && doReactivate )
@@ -317,7 +324,7 @@ bool Video::setResolution( U32 width, U32 height, U32 bpp )
 
       return( result );
    }
-   return( false );	
+   return( false );
 }
 
 
@@ -332,7 +339,7 @@ bool Video::toggleFullScreen()
 
       return( result );
    }
-   return( false );	
+   return( false );
 }
 
 
@@ -345,7 +352,7 @@ DisplayDevice* Video::getDevice( const char* renderName )
             return( smDeviceList[i] );
    }
 
-    return( NULL );	
+    return( NULL );
 }
 
 
@@ -360,7 +367,7 @@ bool Video::prevRes()
 
       return( result );
    }
-   return( false );	
+   return( false );
 }
 
 
@@ -375,7 +382,7 @@ bool Video::nextRes()
 
       return( result );
    }
-   return( false );	
+   return( false );
 }
 
 
@@ -391,7 +398,7 @@ const char* Video::getDeviceList()
 {
     U32 deviceCount = smDeviceList.size();
     if ( deviceCount > 0 ) // It better be...
-    {		
+    {
         U32 strLen = 0, i;
         for ( i = 0; i < deviceCount; i++ )
             strLen += ( dStrlen( smDeviceList[i]->mDeviceName ) + 1 );
@@ -404,7 +411,7 @@ const char* Video::getDeviceList()
             dStrcat( returnString, smDeviceList[i]->mDeviceName );
         }
 
-        return( returnString );				
+        return( returnString );
     }
 
     return( NULL );
@@ -452,7 +459,7 @@ bool Video::getGammaCorrection(F32 &g)
    if (smCurrentDevice)
       return smCurrentDevice->getGammaCorrection(g);
 
-   return false;	
+   return false;
 }
 
 
@@ -462,7 +469,7 @@ bool Video::setGammaCorrection(F32 g)
    if (smCurrentDevice)
       return smCurrentDevice->setGammaCorrection(g);
 
-   return false;	
+   return false;
 }
 
 //------------------------------------------------------------------------------
@@ -470,7 +477,7 @@ bool Video::getVerticalSync()
 {
     if (smCurrentDevice)
         return smCurrentDevice->getVerticalSync();
-    
+
     return( false );
 }
 
@@ -513,7 +520,7 @@ bool DisplayDevice::prevRes()
    if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp )
       return( Video::setResolution( mResolutionList[resIndex].w, mResolutionList[resIndex].h, mResolutionList[resIndex].bpp ) );
 
-    return( false );	
+    return( false );
 }
 
 
@@ -532,7 +539,7 @@ bool DisplayDevice::nextRes()
    if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp )
       return( Video::setResolution( mResolutionList[resIndex].w, mResolutionList[resIndex].h, mResolutionList[resIndex].bpp ) );
 
-    return( false );	
+    return( false );
 }
 
 

+ 1 - 0
engine/source/platform/platformVideo.h

@@ -59,6 +59,7 @@ public:
    static void destroy();                             // clean up and shut down
    static bool installDevice( DisplayDevice *dev );
    static bool setDevice( const char *renderName, U32 width, U32 height, U32 bpp, bool fullScreen );   // set the current display device
+   static void resetCanvas();
    static bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen );
    static void deactivate( bool force = false );      // deactivate current display device
    static void reactivate( bool force = false );      // reactivate current display device

+ 36 - 36
engine/source/platformAndroid/AndroidOGLVideo.cpp

@@ -72,7 +72,7 @@ OpenGLDevice::OpenGLDevice()
 {
     // Set the device name:
     mDeviceName = "OpenGL";
-    
+
     // macs games are not generally full screen only
     mFullScreenOnly = false;
 }
@@ -81,37 +81,37 @@ OpenGLDevice::OpenGLDevice()
 void OpenGLDevice::initDevice()
 {
     //instead of caling enum monitors and enumdisplaymodes on that, we're just going to put in the ones that we know we have
-    
+
     mResolutionList.push_back(Resolution(320, 480, 16));
     mResolutionList.push_back(Resolution(480, 320, 16));
-    
+
     mResolutionList.push_back(Resolution(320, 480, 32));
     mResolutionList.push_back(Resolution(480, 320, 32));
-    
+
     mResolutionList.push_back(Resolution(640, 960, 16));
     mResolutionList.push_back(Resolution(960, 640, 16));
-    
+
     mResolutionList.push_back(Resolution(640, 960, 32));
     mResolutionList.push_back(Resolution(960, 640, 32));
-    
+
     mResolutionList.push_back(Resolution(768, 1024, 16));
     mResolutionList.push_back(Resolution(1024, 768, 16));
-    
+
     mResolutionList.push_back(Resolution(768, 1024, 32));
     mResolutionList.push_back(Resolution(1024, 768, 32));
-    
+
     mResolutionList.push_back(Resolution(1536, 2048, 16));
     mResolutionList.push_back(Resolution(2048, 1536, 16));
-    
+
     mResolutionList.push_back(Resolution(1536, 2048, 32));
     mResolutionList.push_back(Resolution(2048, 1536, 32));
-    
+
     mResolutionList.push_back(Resolution(640, 1136, 16));
     mResolutionList.push_back(Resolution(1136, 640, 16));
-    
+
     mResolutionList.push_back(Resolution(640, 1136, 32));
     mResolutionList.push_back(Resolution(1136, 640, 32));
-    
+
 }
 
 //------------------------------------------------------------------------------
@@ -122,22 +122,22 @@ void OpenGLDevice::initDevice()
 bool OpenGLDevice::activate(U32 width, U32 height, U32 bpp, bool fullScreen)
 {
     Con::printf(" OpenGLDevice activating...");
-    
+
     // gets opengl rendering capabilities of the screen pointed to by platState.hDisplay
     // sets up dgl with the capabilities info, & reports opengl status.
-    
+
     getGLCapabilities();
-    
+
     // Create the window or capture fullscreen
     if (!setScreenMode(width, height, bpp, fullScreen, true, false))
         return false;
-    
+
     // set the displayDevice pref to "OpenGL"
     Con::setVariable("$pref::Video::displayDevice", mDeviceName);
-    
+
     // set vertical sync now because it doesnt need setting every time we setScreenMode()
     setVerticalSync(!Con::getBoolVariable("$pref::Video::disableVerticalSync"));
-    
+
     return true;
 }
 
@@ -168,40 +168,40 @@ bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen
                 forceIt ? "force it" : "dont force it",
                 repaint ? "repaint" : "dont repaint"
                 );
-    
+
     // validation, early outs --------------------------------------------------
     // sanity check. some scripts are liable to pass in bad values.
     if (!bpp)
         bpp = platState.desktopBitsPixel;
-    
+
     Resolution newRes = Resolution(width, height, bpp);
-    
+
     // if no values changing and we're not forcing a change, kick out. prevents thrashing.
     if (!forceIt && smIsFullScreen == fullScreen && smCurrentRes == newRes)
         return (true);
-    
+
     // we have a new context, this is now safe to do:
     // delete any contexts or windows that exist, and kill the texture manager.
     bool needResurrect = cleanupContextAndWindow();
-    
+
     Con::printf(">> Attempting to change display settings to %s %dx%dx%d...",
                 fullScreen ? "fullscreen" : "windowed", newRes.w, newRes.h, newRes.bpp);
-    
+
     // set torque variables ----------------------------------------------------
     // save window size for dgl
     Platform::setWindowSize(newRes.w, newRes.h);
-    
+
     // update smIsFullScreen and pref
     smIsFullScreen = fullScreen;
-    
+
     Con::setBoolVariable("$pref::Video::fullScreen", smIsFullScreen);
-    
+
     // save resolution
     smCurrentRes = newRes;
-    
+
     // save resolution to prefs
     char buf[32];
-    
+
     if (fullScreen)
     {
         dSprintf(buf, sizeof(buf), "%d %d %d", newRes.w, newRes.h, newRes.bpp);
@@ -212,7 +212,7 @@ bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen
         dSprintf(buf, sizeof(buf), "%d %d", newRes.w, newRes.h);
         Con::setVariable("$pref::Video::windowedRes", buf);
     }
-    
+
     // begin rendering again ----------------------------------------------------
     if (needResurrect)
     {
@@ -220,10 +220,10 @@ bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen
         Con::printf("Resurrecting the texture manager...");
         Game->textureResurrect();
     }
-    
+
     if (repaint)
-        Con::evaluate("resetCanvas();");
-    
+        Video::resetCanvas();
+
     return true;
 }
 
@@ -283,11 +283,11 @@ DisplayDevice *OpenGLDevice::create()
     // this will be replaced later with the window's context,
     // but we need agl_ctx to be valid at all times,
     // since some things try to make gl calls before the device is activated.
-    
+
     // create the DisplayDevice
     OpenGLDevice *newOGLDevice = new OpenGLDevice();
-    
+
     newOGLDevice->initDevice();
-    
+
     return newOGLDevice;
 }

+ 1 - 2
engine/source/platformEmscripten/EmscriptenOGLVideo.cpp

@@ -386,7 +386,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp,
 
    // repaint
    if ( repaint )
-      Con::evaluate( "resetCanvas();" );
+      Video::resetCanvas();
 
    return true;
 }
@@ -459,4 +459,3 @@ DisplayDevice* OpenGLDevice::create()
 {
    return new OpenGLDevice();
 }
-

+ 78 - 78
engine/source/platformOSX/osxOpenGLDevice.mm

@@ -35,13 +35,13 @@ osxOpenGLDevice::osxOpenGLDevice()
 
     // pick a monitor to run on
     enumMonitors();
-    
+
     platState = [osxPlatState sharedPlatState];
-    
+
     CGDirectDisplayID display = chooseMonitor();
-    
+
     [platState setCgDisplay:display];
-    
+
     enumDisplayModes(display);
 }
 
@@ -51,28 +51,28 @@ bool osxOpenGLDevice::enumDisplayModes( CGDirectDisplayID display )
 {
     // Clear the resolution list.
     mResolutionList.clear();
-    
+
     // Fetch a list of all available modes for the specified display.
     CFArrayRef modeArray = CGDisplayCopyAllDisplayModes(display, NULL);
-    
+
     // Fetch the mode count.
     const S32 modeCount = (const S32)CFArrayGetCount(modeArray);
-    
+
     // Iterate the modes.
     for( S32 modeIndex = 0; modeIndex < modeCount; modeIndex++ )
     {
         // Fetch the display mode.
         CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modeArray, modeIndex);
-        
+
         // Get the mode width.
         const S32 width = (const S32)CGDisplayModeGetWidth(mode);
-        
+
         // Get the mode height.
         const S32 height = (const S32)CGDisplayModeGetHeight(mode);
-        
+
         // Get the pixel encoding.
         CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
-        
+
         // Is it a 32 bpp?
         S32 bitDepth;
         if ( CFStringCompare( pixelEncoding, CFSTR(IO32BitDirectPixels), 0 ) == kCFCompareEqualTo )
@@ -110,7 +110,7 @@ bool osxOpenGLDevice::enumDisplayModes( CGDirectDisplayID display )
         // Store the resolution.
         mResolutionList.push_back( Resolution( width, height, bitDepth ) );
     }
-    
+
     return true;
 }
 
@@ -125,9 +125,9 @@ void osxOpenGLDevice::initDevice()
 bool osxOpenGLDevice::cleanUpContext()
 {
     bool needResurrect = false;
-    
+
     platState = [osxPlatState sharedPlatState];
-    
+
     if ([[platState torqueView] contextInitialized])
     {
         if (!Video::smNeedResurrect)
@@ -136,33 +136,33 @@ bool osxOpenGLDevice::cleanUpContext()
             Game->textureKill();
             needResurrect = true;
         }
-        
+
         [[platState torqueView] clearContext];
     }
-    
+
     // clear the Resolution state, so setScreenMode() will know not to early-out.
     smCurrentRes = Resolution(0, 0, 0);
-    
+
     return needResurrect;
 }
 
 //-----------------------------------------------------------------------------
-// 
+//
 bool osxOpenGLDevice::activate( U32 width, U32 height, U32 bpp, bool fullScreen )
 {
     Con::printf( " OpenGLDevice activating..." );
-        
+
     // gets opengl rendering capabilities of the screen pointed to by platState.hDisplay
     // sets up dgl with the capabilities info, & reports opengl status.
     getGLCapabilities();
-    
+
     // Create the window or capture fullscreen
     if(!setScreenMode(width, height, bpp, fullScreen, true, false))
         return false;
-    
+
     // set the displayDevice pref to "OpenGL"
     Con::setVariable( "$pref::Video::displayDevice", mDeviceName );
-    
+
     // set vertical sync now because it doesnt need setting every time we setScreenMode()
     setVerticalSync( !Con::getBoolVariable( "$pref::Video::disableVerticalSync" ));
 
@@ -182,22 +182,22 @@ void osxOpenGLDevice::shutdown()
 NSOpenGLPixelFormat* osxOpenGLDevice::generateValidPixelFormat(bool fullscreen, U32 bpp, U32 samples)
 {
     AssertWarn(samples <= 6, "An unusual multisample depth was requested in findValidPixelFormat(). clamping to 0...6");
-    
+
     samples = samples > 6 ? 6 : samples;
-    
+
     int i = 0;
     NSOpenGLPixelFormatAttribute attr[64];
-    
+
     attr[i++] = NSOpenGLPFADoubleBuffer;
     attr[i++] = NSOpenGLPFANoRecovery;
     attr[i++] = NSOpenGLPFAAccelerated;
-        
+
     if(bpp != 0)
     {
         // native pixel formats are argb 1555 & argb 8888.
         U32 colorbits = 0;
         U32 alphabits = 0;
-        
+
         if(bpp == 16)
         {
             colorbits = 5;             // ARGB 1555
@@ -205,7 +205,7 @@ NSOpenGLPixelFormat* osxOpenGLDevice::generateValidPixelFormat(bool fullscreen,
         }
         else if(bpp == 32)
             colorbits = alphabits = 8; // ARGB 8888
-        
+
         attr[i++] = NSOpenGLPFADepthSize;
         attr[i++] = (NSOpenGLPixelFormatAttribute)bpp;
         attr[i++] = NSOpenGLPFAColorSize;
@@ -213,7 +213,7 @@ NSOpenGLPixelFormat* osxOpenGLDevice::generateValidPixelFormat(bool fullscreen,
         attr[i++] = NSOpenGLPFAAlphaSize;
         attr[i++] = (NSOpenGLPixelFormatAttribute)alphabits;
     }
-    
+
     if (samples != 0)
     {
         attr[i++] = NSOpenGLPFAMultisample;
@@ -221,11 +221,11 @@ NSOpenGLPixelFormat* osxOpenGLDevice::generateValidPixelFormat(bool fullscreen,
         attr[i++] = NSOpenGLPFASamples;
         attr[i++] = (NSOpenGLPixelFormatAttribute)samples;
     }
-    
+
     attr[i++] = 0;
- 
+
     NSOpenGLPixelFormat* format = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease];
-    
+
     return format;
 }
 
@@ -238,93 +238,93 @@ bool osxOpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullSc
                 fullScreen  ? "fullscreen" : "windowed",
                 forceIt     ? "force it" : "dont force it",
                 repaint     ? "repaint"  : "dont repaint");
- 
+
     bool needResurrect = cleanUpContext();
-    
+
     // Get the global OSX platform state
     osxPlatState * platState = [osxPlatState sharedPlatState];
-    
+
     // Validation, early outs
     // Sanity check. Some scripts are liable to pass in bad values.
     if (!bpp)
         bpp = [platState desktopBitsPixel];
-    
+
     if (bpp)
         bpp = bpp > 16 ? 32 : 16;
-    
+
     Resolution newRes = Resolution(width, height, bpp);
-    
+
     // If no values changing and we're not forcing a change, kick out. prevents thrashing.
     if (!forceIt && smIsFullScreen == fullScreen && smCurrentRes == newRes)
         return true;
-    
+
     // Create a pixel format to be used with the context
     NSOpenGLPixelFormat* pixelFormat = generateValidPixelFormat(fullScreen, bpp, 0);
-    
+
     if (!pixelFormat)
     {
         Con::printf("osxOpenGLDevice::setScreenMode error: No OpenGL pixel format");
         return false;
     }
-    
+
     [platState setFullScreen:fullScreen];
-    
+
     if (fullScreen)
     {
-        
+
         NSRect mainDisplayRect = [[NSScreen mainScreen] frame];
-        
+
         newRes.w = mainDisplayRect.size.width;
         newRes.h = mainDisplayRect.size.height;
-        
+
         [[platState window] setStyleMask:NSBorderlessWindowMask];
-        
+
         [[platState window] setFrame:mainDisplayRect display:YES];
-        
+
         [[platState window] setLevel:NSMainMenuWindowLevel+1];
     }
     else
     {
 #if __MAC_OS_X_VERSION_MAX_ALLOWED < 1070
         [[platState window] setStyleMask:NSTitledWindowMask | NSClosableWindowMask] ;
-        
+
         // Calculate the actual center
         CGFloat x = ([[NSScreen mainScreen] frame].size.width - width) / 2;
         CGFloat y = ([[NSScreen mainScreen] frame].size.height - height) / 2;
-        
+
         // Create a rect to send to the window
         NSRect newFrame = NSMakeRect(x, y, width, height);
-        
+
         // Send message to the window to resize/relocate
         [[platState window] setFrame:newFrame display:YES animate:NO];
 #else
         [[platState window] setStyleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask];
 #endif
     }
-    
+
     [[platState torqueView] createContextWithPixelFormat:pixelFormat];
-    
+
     [platState setWindowSize:newRes.w height:newRes.h];
-        
+
     // clear out garbage from the gl window.
     glClearColor(0,0,0,1);
     glClear(GL_COLOR_BUFFER_BIT );
-    
+
     // set opengl options & other options ---------------------------------------
     // ensure data is packed tightly in memory. this defaults to 4.
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-    
+
     // TODO: set gl arb multisample enable & hint
     //dglSetFSAASamples(gFSAASamples);
-        
+
     // update smIsFullScreen and pref
     smIsFullScreen = fullScreen;
-    
+
     Con::setBoolVariable( "$pref::Video::fullScreen", smIsFullScreen );
-    
+
     // save resolution
     smCurrentRes = newRes;
-    
+
     // save resolution to prefs
     char buf[32];
     if (fullScreen)
@@ -337,17 +337,17 @@ bool osxOpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullSc
         dSprintf( buf, sizeof(buf), "%d %d", newRes.w, newRes.h);
         Con::setVariable("$pref::Video::windowedRes", buf);
     }
-    
+
     if (needResurrect)
     {
         // Reload the textures gl names
         Con::printf( "Resurrecting the texture manager..." );
         Game->textureResurrect();
     }
-    
+
     if( repaint )
-        Con::evaluate( "resetCanvas();" );
-    
+        Video::resetCanvas();
+
     return true;
 }
 
@@ -357,12 +357,12 @@ void osxOpenGLDevice::swapBuffers()
 {
     if ([[platState torqueView] contextInitialized])
         [[platState torqueView] flushBuffer];
-    
+
 #if defined(TORQUE_DEBUG)
     if (gOutlineEnabled)
         glClear(GL_COLOR_BUFFER_BIT);
 #endif
-    
+
 }
 
 //-----------------------------------------------------------------------------
@@ -374,20 +374,20 @@ const char* osxOpenGLDevice::getDriverInfo()
     const char* rendererString = (const char*) glGetString( GL_RENDERER );
     const char* versionString  = (const char*) glGetString( GL_VERSION );
     const char* extensionsString = (const char*) glGetString( GL_EXTENSIONS );
-    
+
     U32 bufferLen = ( vendorString ? dStrlen( vendorString ) : 0 )
     + ( rendererString ? dStrlen( rendererString ) : 0 )
     + ( versionString  ? dStrlen( versionString ) : 0 )
     + ( extensionsString ? dStrlen( extensionsString ) : 0 )
     + 4;
-    
+
     char* returnString = Con::getReturnBuffer( bufferLen );
     dSprintf( returnString, bufferLen, "%s\t%s\t%s\t%s",
              ( vendorString ? vendorString : "" ),
              ( rendererString ? rendererString : "" ),
              ( versionString ? versionString : "" ),
              ( extensionsString ? extensionsString : "" ) );
-    
+
     return( returnString );
 }
 
@@ -413,7 +413,7 @@ bool osxOpenGLDevice::getVerticalSync()
     {
         return false;
     }
-    
+
     //Note that this returns the number of frames between Swaps.
     //The function returns 0 / false if SwapInterval has not been specified.
     return getVerticalSync();
@@ -442,18 +442,18 @@ bool osxOpenGLDevice::enumMonitors()
 {
     mMonitorList.clear();
     nAllDevs = 0;
-    
+
     CGDirectDisplayID _displayIDs[32];
     uint32_t _displayCount;
-    
+
     CGGetActiveDisplayList (32, _displayIDs, &_displayCount);
-    
+
     for (int ii = 0 ; ii < _displayCount ; ii++)
     {
         mMonitorList.push_back(_displayIDs[ii]);
         allDevs[nAllDevs++] = _displayIDs[ii];
     }
-    
+
     return true;
 }
 
@@ -466,17 +466,17 @@ CGDirectDisplayID osxOpenGLDevice::chooseMonitor()
     // TODO: choose monitor based on which one contains most of the window.
     // NOTE: do not call cleanup before calling choose, or we won't have a window to consider.
     AssertFatal(!mMonitorList.empty(), "Cannot choose a monitor if the list is empty!");
-    
+
     U32 monNum = Con::getIntVariable("$pref::Video::monitorNum", 0);
-    
+
     if (monNum >= mMonitorList.size())
     {
         Con::errorf("invalid monitor number %i", monNum);
         monNum = 0;
         Con::setIntVariable("$pref::Video::monitorNum", 0);
     }
-    
+
     Con::printf("using display 0x%x", mMonitorList[monNum]);
-    
+
     return mMonitorList[monNum];
-}
+}

+ 7 - 7
engine/source/platformWin32/winOGLVideo.cc

@@ -97,7 +97,7 @@ bool OpenGLDevice::activate( U32 width, U32 height, U32 bpp, bool fullScreen )
          ReleaseDC( winState.appWindow, winState.appDC );
          winState.appDC = NULL;
       }
-   
+
       Con::printf( "Destroying the window..." );
       DestroyWindow( winState.appWindow );
       winState.appWindow = NULL;
@@ -224,7 +224,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
             }
          }
       }
-      
+
    }
 
    //MIN_RESOLUTION defined in platformWin32/platformGL.h
@@ -315,7 +315,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
          ReleaseDC( winState.appWindow, winState.appDC );
          winState.appDC = NULL;
       }
-      
+
       // [neo, 5/31/2007 - #3174]
       if( winState.appMenu )
       {
@@ -371,7 +371,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
       {
          smIsFullScreen = false;
          Con::setBoolVariable( "$pref::Video::fullScreen", false );
-         
+
          ChangeDisplaySettings( NULL, 0 );
          Con::errorf( ConsoleLogEntry::General, "OpenGLDevice::setScreenMode - ChangeDisplaySettings failed." );
          switch( test )
@@ -402,7 +402,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
    }
 
    Con::setBoolVariable( "$pref::Video::fullScreen", smIsFullScreen );
-  
+
 
    bool newWindow = false;
    if ( !winState.appWindow )
@@ -432,7 +432,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
 
       // Center the window on the desktop:
       U32 xPos = 0, yPos = 0;
-      
+
       if(adjWidth < (U32)winState.desktopClientWidth)
          xPos = ( winState.desktopClientWidth - adjWidth ) / 2;
 
@@ -566,7 +566,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScree
     glClear(GL_COLOR_BUFFER_BIT);
 
     if ( repaint )
-      Con::evaluate( "resetCanvas();" );
+      Video::resetCanvas();
 
    return true;
 }

+ 0 - 2
engine/source/platformWin32/winWindow.cc

@@ -1570,8 +1570,6 @@ void Platform::initWindow(const Point2I &initialSize, const char *name)
 {
    MSG msg;
 
-   Con::printSeparator();
-   Con::printf("Video Initialization:");
    Video::init();
 
    PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);

+ 1 - 2
engine/source/platformX86UNIX/x86UNIXOGLVideo.cc

@@ -401,7 +401,7 @@ bool OpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp,
 
    // repaint
    if ( repaint )
-      Con::evaluate( "resetCanvas();" );
+      Video::resetCanvas();
 
    return true;
 }
@@ -519,4 +519,3 @@ DisplayDevice* OpenGLDevice::create()
 {
    return new OpenGLDevice();
 }
-

+ 38 - 38
engine/source/platformiOS/iOSOGLVideo.mm

@@ -73,7 +73,7 @@ OpenGLDevice::OpenGLDevice()
 {
     // Set the device name:
     mDeviceName = "OpenGL";
-    
+
     // macs games are not generally full screen only
     mFullScreenOnly = false;
 }
@@ -82,37 +82,37 @@ OpenGLDevice::OpenGLDevice()
 void OpenGLDevice::initDevice()
 {
     //instead of caling enum monitors and enumdisplaymodes on that, we're just going to put in the ones that we know we have
-    
+
     mResolutionList.push_back(Resolution(320, 480, 16));
     mResolutionList.push_back(Resolution(480, 320, 16));
-    
+
     mResolutionList.push_back(Resolution(320, 480, 32));
     mResolutionList.push_back(Resolution(480, 320, 32));
-    
+
     mResolutionList.push_back(Resolution(640, 960, 16));
     mResolutionList.push_back(Resolution(960, 640, 16));
-    
+
     mResolutionList.push_back(Resolution(640, 960, 32));
     mResolutionList.push_back(Resolution(960, 640, 32));
-    
+
     mResolutionList.push_back(Resolution(768, 1024, 16));
     mResolutionList.push_back(Resolution(1024, 768, 16));
-    
+
     mResolutionList.push_back(Resolution(768, 1024, 32));
     mResolutionList.push_back(Resolution(1024, 768, 32));
-    
+
     mResolutionList.push_back(Resolution(1536, 2048, 16));
     mResolutionList.push_back(Resolution(2048, 1536, 16));
-    
+
     mResolutionList.push_back(Resolution(1536, 2048, 32));
     mResolutionList.push_back(Resolution(2048, 1536, 32));
-    
+
     mResolutionList.push_back(Resolution(640, 1136, 16));
     mResolutionList.push_back(Resolution(1136, 640, 16));
-    
+
     mResolutionList.push_back(Resolution(640, 1136, 32));
     mResolutionList.push_back(Resolution(1136, 640, 32));
-    
+
 }
 
 //------------------------------------------------------------------------------
@@ -123,22 +123,22 @@ void OpenGLDevice::initDevice()
 bool OpenGLDevice::activate(U32 width, U32 height, U32 bpp, bool fullScreen)
 {
     Con::printf(" OpenGLDevice activating...");
-    
+
     // gets opengl rendering capabilities of the screen pointed to by platState.hDisplay
     // sets up dgl with the capabilities info, & reports opengl status.
-    
+
     getGLCapabilities();
-    
+
     // Create the window or capture fullscreen
     if (!setScreenMode(width, height, bpp, fullScreen, true, false))
         return false;
-    
+
     // set the displayDevice pref to "OpenGL"
     Con::setVariable("$pref::Video::displayDevice", mDeviceName);
-    
+
     // set vertical sync now because it doesnt need setting every time we setScreenMode()
     setVerticalSync(!Con::getBoolVariable("$pref::Video::disableVerticalSync"));
-    
+
     return true;
 }
 
@@ -164,46 +164,46 @@ void OpenGLDevice::shutdown()
 //
 bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt, bool repaint)
 {
-    
+
     Con::printf(" set screen mode %i x %i x %i, %s, %s, %s", width, height, bpp,
                 fullScreen ? "fullscreen" : "windowed",
                 forceIt ? "force it" : "dont force it",
                 repaint ? "repaint" : "dont repaint"
                 );
-    
+
     // validation, early outs --------------------------------------------------
     // sanity check. some scripts are liable to pass in bad values.
     if (!bpp)
         bpp = platState.desktopBitsPixel;
-    
+
     Resolution newRes = Resolution(width, height, bpp);
-    
+
     // if no values changing and we're not forcing a change, kick out. prevents thrashing.
     if (!forceIt && smIsFullScreen == fullScreen && smCurrentRes == newRes)
         return (true);
-    
+
     // we have a new context, this is now safe to do:
     // delete any contexts or windows that exist, and kill the texture manager.
     bool needResurrect = cleanupContextAndWindow();
-    
+
     Con::printf(">> Attempting to change display settings to %s %dx%dx%d...",
                 fullScreen ? "fullscreen" : "windowed", newRes.w, newRes.h, newRes.bpp);
-    
+
     // set torque variables ----------------------------------------------------
     // save window size for dgl
     Platform::setWindowSize(newRes.w, newRes.h);
-    
+
     // update smIsFullScreen and pref
     smIsFullScreen = fullScreen;
-    
+
     Con::setBoolVariable("$pref::Video::fullScreen", smIsFullScreen);
-    
+
     // save resolution
     smCurrentRes = newRes;
-    
+
     // save resolution to prefs
     char buf[32];
-    
+
     if (fullScreen)
     {
         dSprintf(buf, sizeof(buf), "%d %d %d", newRes.w, newRes.h, newRes.bpp);
@@ -214,7 +214,7 @@ bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen
         dSprintf(buf, sizeof(buf), "%d %d", newRes.w, newRes.h);
         Con::setVariable("$pref::Video::windowedRes", buf);
     }
-    
+
     // begin rendering again ----------------------------------------------------
     if (needResurrect)
     {
@@ -222,10 +222,10 @@ bool OpenGLDevice::setScreenMode(U32 width, U32 height, U32 bpp, bool fullScreen
         Con::printf("Resurrecting the texture manager...");
         Game->textureResurrect();
     }
-    
+
     if (repaint)
-        Con::evaluate("resetCanvas();");
-    
+        Video::resetCanvas();
+
     return true;
 }
 
@@ -285,11 +285,11 @@ DisplayDevice *OpenGLDevice::create()
     // this will be replaced later with the window's context,
     // but we need agl_ctx to be valid at all times,
     // since some things try to make gl calls before the device is activated.
-    
+
     // create the DisplayDevice
     OpenGLDevice *newOGLDevice = new OpenGLDevice();
-    
+
     newOGLDevice->initDevice();
-    
+
     return newOGLDevice;
-}
+}

+ 0 - 4
library/AppCore/appCore.cs

@@ -34,10 +34,6 @@ function AppCore::create( %this )
     // Initialize the canvas
     %this.initializeCanvas("Torque2D: Rocket Edition");
 
-    // Set the canvas color
-    Canvas.BackgroundColor = "Black";
-    Canvas.UseBackgroundColor = true;
-
 	// Load other modules
     ModuleDatabase.loadGroup("gameBase");
 

+ 38 - 48
library/AppCore/scripts/canvas.cs

@@ -27,58 +27,48 @@
 function AppCore::initializeCanvas(%this, %windowName)
 {
     // Don't duplicate the canvas.
-    if(%this.canvasCreated)
+    if(!isObject(Canvas))
     {
-        error("Cannot instantiate more than one canvas!");
-        return;
-    }
-
-    videoSetGammaCorrection($pref::OpenGL::gammaCorrection);
-
-    if ( !createCanvas(%windowName) )
-    {
-        error("Canvas creation failed. Shutting down.");
-        quit();
-    }
+	    videoSetGammaCorrection($pref::OpenGL::gammaCorrection);
 
-    $pref::iOS::ScreenDepth = 32;
+	    if ( !createCanvas(%windowName) )
+	    {
+	        error("Canvas creation failed. Shutting down.");
+	        quit();
+	    }
 
-    if ($platform $= "iOS")
-    {
-        %resolution = $pref::iOS::Width SPC $pref::iOS::Height SPC 32;
-    }
-    else if ($platform $= "Android")
-    {
-    	%resolution = GetAndroidResolution();
-    }
-    else
-    {
-        if ( $pref::Video::windowedRes !$= "" )
-            %resolution = $pref::Video::windowedRes;
-        else
-            %resolution = $pref::Video::defaultResolution;
-    }
+	    if ($platform $= "iOS")
+	    {
+	        %resolution = $pref::iOS::Width SPC $pref::iOS::Height SPC $pref::iOS::ScreenDepth;
+	    }
+	    else if ($platform $= "Android")
+	    {
+	    	%resolution = GetAndroidResolution();
+	    }
+	    else
+	    {
+	        if ( $pref::Video::windowedRes !$= "" )
+	            %resolution = $pref::Video::windowedRes;
+	        else
+	            %resolution = $pref::Video::defaultResolution;
+	    }
 
-    if ($platform $= "windows" || $platform $= "macos")
-    {
-        setScreenMode( %resolution._0, %resolution._1, %resolution._2, $pref::Video::fullScreen );
-    }
-    else
-    {
-        setScreenMode( %resolution._0, %resolution._1, %resolution._2, false );
-    }
-
-    $canvasCreated = true;
-}
-
-//------------------------------------------------------------------------------
-// resetCanvas
-// Forces the canvas to redraw itself.
-//------------------------------------------------------------------------------
-function AppCore::resetCanvas(%this)
-{
-    if (isObject(Canvas))
-        Canvas.repaint();
+	    if ($platform $= "windows" || $platform $= "macos")
+	    {
+	        setScreenMode( %resolution._0, %resolution._1, %resolution._2, $pref::Video::fullScreen );
+	    }
+	    else
+	    {
+	        setScreenMode( %resolution._0, %resolution._1, %resolution._2, false );
+	    }
+	}
+	else
+	{
+		Canvas.setCanvasTitle(%windowName);
+		Canvas.repaint();
+	}
+    Canvas.UseBackgroundColor = true;
+    Canvas.BackgroundColor = "Black";
 }
 
 //------------------------------------------------------------------------------