smsvn -> ssc-hg glue: rearrange directory structure
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include "global.h"
|
||||
#include "LowLevelWindow.h"
|
||||
#include "arch/arch_default.h"
|
||||
|
||||
LowLevelWindow *LowLevelWindow::Create()
|
||||
{
|
||||
return new ARCH_LOW_LEVEL_WINDOW;
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2002-2005 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef LOW_LEVEL_WINDOW_H
|
||||
#define LOW_LEVEL_WINDOW_H
|
||||
|
||||
/* This handles low-level operations that OGL 1.x doesn't give us. */
|
||||
|
||||
#include <set>
|
||||
|
||||
class DisplayResolution;
|
||||
typedef set<DisplayResolution> DisplayResolutions;
|
||||
class VideoModeParams;
|
||||
class RenderTarget;
|
||||
struct RenderTargetParam;
|
||||
|
||||
class LowLevelWindow
|
||||
{
|
||||
public:
|
||||
static LowLevelWindow *Create();
|
||||
|
||||
virtual ~LowLevelWindow() { }
|
||||
|
||||
virtual void *GetProcAddress( RString s ) = 0;
|
||||
|
||||
// Return "" if mode change was successful, otherwise an error message.
|
||||
// bNewDeviceOut is set true if a new device was created and textures
|
||||
// need to be reloaded.
|
||||
virtual RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut ) = 0;
|
||||
virtual void GetDisplayResolutions( DisplayResolutions &out ) const = 0;
|
||||
|
||||
virtual void LogDebugInformation() const { }
|
||||
virtual bool IsSoftwareRenderer( RString &sError ) { return false; }
|
||||
|
||||
virtual void SwapBuffers() = 0;
|
||||
virtual void Update() { }
|
||||
|
||||
virtual const VideoModeParams &GetActualVideoModeParams() const = 0;
|
||||
|
||||
virtual bool SupportsRenderToTexture() const { return false; }
|
||||
virtual RenderTarget *CreateRenderTarget() { return NULL; }
|
||||
|
||||
virtual bool SupportsThreadedRendering() { return false; }
|
||||
virtual void BeginConcurrentRenderingMainThread() { }
|
||||
virtual void EndConcurrentRenderingMainThread() { }
|
||||
virtual void BeginConcurrentRendering() { }
|
||||
virtual void EndConcurrentRendering() { }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2003-2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef LOW_LEVEL_WINDOW_MACOSX_H
|
||||
#define LOW_LEVEL_WINDOW_MACOSX_H
|
||||
|
||||
#include "LowLevelWindow.h"
|
||||
#include "RageDisplay.h"
|
||||
#include <objc/objc.h>
|
||||
|
||||
typedef const struct __CFDictionary *CFDictionaryRef;
|
||||
/* XXX: This was changed to a uint32_t later and its header file cannot be included
|
||||
* since Style conflicts. Ugh. */
|
||||
typedef struct _CGDirectDisplayID *CGDirectDisplayID;
|
||||
|
||||
class LowLevelWindow_MacOSX : public LowLevelWindow
|
||||
{
|
||||
VideoModeParams m_CurrentParams;
|
||||
id m_WindowDelegate;
|
||||
id m_Context;
|
||||
id m_BGContext;
|
||||
CFDictionaryRef m_CurrentDisplayMode;
|
||||
CGDirectDisplayID m_DisplayID;
|
||||
|
||||
public:
|
||||
LowLevelWindow_MacOSX();
|
||||
~LowLevelWindow_MacOSX();
|
||||
void *GetProcAddress( RString s );
|
||||
RString TryVideoMode( const VideoModeParams& p, bool& newDeviceOut );
|
||||
void GetDisplayResolutions( DisplayResolutions &dr ) const;
|
||||
|
||||
void SwapBuffers();
|
||||
void Update();
|
||||
|
||||
const VideoModeParams &GetActualVideoModeParams() const { return m_CurrentParams; }
|
||||
|
||||
bool SupportsRenderToTexture() const { return true; }
|
||||
RenderTarget *CreateRenderTarget();
|
||||
|
||||
bool SupportsThreadedRendering() { return m_BGContext; }
|
||||
void BeginConcurrentRendering();
|
||||
|
||||
private:
|
||||
void ShutDownFullScreen();
|
||||
int ChangeDisplayMode( const VideoModeParams& p );
|
||||
void SetActualParamsFromMode( CFDictionaryRef mode );
|
||||
};
|
||||
|
||||
#ifdef ARCH_LOW_LEVEL_WINDOW
|
||||
#error "More than one LowLevelWindow selected!"
|
||||
#endif
|
||||
#define ARCH_LOW_LEVEL_WINDOW LowLevelWindow_MacOSX
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2005-2006, 2008 Steve Checkoway
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,630 @@
|
||||
#import "global.h"
|
||||
#import "LowLevelWindow_MacOSX.h"
|
||||
#import "DisplayResolutions.h"
|
||||
#import "RageUtil.h"
|
||||
#import "RageThreads.h"
|
||||
#import "RageDisplay_OGL_Helpers.h"
|
||||
#import "arch/ArchHooks/ArchHooks.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <OpenGl/OpenGl.h>
|
||||
#import <OpenGL/gl.h>
|
||||
#import <mach-o/dyld.h>
|
||||
|
||||
// Bad header!
|
||||
extern "C" {
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
}
|
||||
|
||||
|
||||
static const unsigned int g_iStyleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||
static bool g_bResized;
|
||||
static int g_iWidth;
|
||||
static int g_iHeight;
|
||||
static RageMutex g_ResizeLock( "Window resize lock." );
|
||||
|
||||
// Simple helper class
|
||||
class AutoreleasePool
|
||||
{
|
||||
AutoreleasePool( const AutoreleasePool& );
|
||||
AutoreleasePool &operator=( const AutoreleasePool& );
|
||||
NSAutoreleasePool *m_Pool;
|
||||
|
||||
public:
|
||||
AutoreleasePool() { m_Pool = [[NSAutoreleasePool alloc] init]; }
|
||||
~AutoreleasePool() { [m_Pool release]; }
|
||||
};
|
||||
|
||||
#define POOL AutoreleasePool UNIQUE_NAME(pool)
|
||||
|
||||
// Window delegate class
|
||||
@interface SMWindowDelegate : NSObject
|
||||
{
|
||||
@public
|
||||
NSWindow *m_Window;
|
||||
}
|
||||
- (void) windowDidBecomeKey:(NSNotification *)aNotification;
|
||||
- (void) windowDidResignKey:(NSNotification *)aNotification;
|
||||
- (void) windowWillClose:(NSNotification *)aNotification;
|
||||
- (void) windowDidResize:(NSNotification *)aNotification;
|
||||
// XXX maybe use whichever screen contains the window? Hard for me to test though.
|
||||
//- (void) windowDidChangeScreen:(NSNotification *)aNotification;
|
||||
|
||||
// Helper methods to perform actions on the main thread.
|
||||
- (void) setupWindow;
|
||||
- (void) closeWindow;
|
||||
- (void) setParams:(NSValue *)params;
|
||||
@end
|
||||
|
||||
@implementation SMWindowDelegate
|
||||
|
||||
- (void) windowDidBecomeKey:(NSNotification *)aNotification
|
||||
{
|
||||
HOOKS->SetHasFocus( true );
|
||||
}
|
||||
|
||||
- (void) windowDidResignKey:(NSNotification *)aNotification
|
||||
{
|
||||
HOOKS->SetHasFocus( false );
|
||||
}
|
||||
|
||||
- (void) windowWillClose:(NSNotification *)aNotification
|
||||
{
|
||||
ArchHooks::SetUserQuit();
|
||||
}
|
||||
|
||||
- (void) windowDidResize:(NSNotification *)aNotification
|
||||
{
|
||||
id window = [aNotification object];
|
||||
NSSize size = [NSWindow contentRectForFrameRect:[window frame] styleMask:g_iStyleMask].size;
|
||||
|
||||
LockMut( g_ResizeLock );
|
||||
g_bResized = true;
|
||||
g_iWidth = int( size.width );
|
||||
g_iHeight = int( size.height );
|
||||
}
|
||||
|
||||
- (void) setupWindow
|
||||
{
|
||||
NSRect rect = NSMakeRect( 0, 0, 0, 0 );
|
||||
m_Window = [[NSWindow alloc] initWithContentRect:rect
|
||||
styleMask:g_iStyleMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
|
||||
[m_Window setExcludedFromWindowsMenu:YES];
|
||||
[m_Window useOptimizedDrawing:YES];
|
||||
[m_Window setReleasedWhenClosed:NO];
|
||||
[m_Window setDelegate:self];
|
||||
}
|
||||
|
||||
- (void) closeWindow
|
||||
{
|
||||
[m_Window setDelegate:nil];
|
||||
[m_Window close];
|
||||
[m_Window release];
|
||||
}
|
||||
|
||||
- (void) setParams:(NSValue *)params
|
||||
{
|
||||
const VideoModeParams &p = *(const VideoModeParams *)[params pointerValue];
|
||||
NSRect contentRect = { { 0, 0 }, { p.width, p.height } };
|
||||
|
||||
[m_Window setContentSize:contentRect.size];
|
||||
[m_Window setTitle:[NSString stringWithUTF8String:p.sWindowTitle.c_str()]];
|
||||
[m_Window center];
|
||||
[m_Window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
@end
|
||||
|
||||
enum GLContextType
|
||||
{
|
||||
WINDOWED,
|
||||
FULL_SCREEN,
|
||||
PIXEL_BUFFER
|
||||
};
|
||||
|
||||
static NSOpenGLContext *CreateOGLContext( GLContextType type, int iColorSize, int iAlphaSize, int iDepthSize, NSOpenGLContext *share, bool &bShared )
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attrs[] = {
|
||||
NSOpenGLPFANoRecovery, // so we can share with the full screen context
|
||||
NSOpenGLPFAAccelerated,
|
||||
NSOpenGLPFAMinimumPolicy,
|
||||
NSOpenGLPFAColorSize, NSOpenGLPixelFormatAttribute(iColorSize),
|
||||
NSOpenGLPFAAlphaSize, NSOpenGLPixelFormatAttribute(iAlphaSize),
|
||||
NSOpenGLPFADepthSize, NSOpenGLPixelFormatAttribute(iDepthSize),
|
||||
NSOpenGLPixelFormatAttribute(0), // 9
|
||||
NSOpenGLPixelFormatAttribute(0), // 10
|
||||
NSOpenGLPixelFormatAttribute(0), // 11
|
||||
NSOpenGLPixelFormatAttribute(0), // 12
|
||||
NSOpenGLPixelFormatAttribute(0) // Must be at the end.
|
||||
};
|
||||
const int n = 9; // The first noncommon index.
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case WINDOWED:
|
||||
attrs[n+0] = NSOpenGLPFAWindow;
|
||||
attrs[n+1] = NSOpenGLPFADoubleBuffer;
|
||||
break;
|
||||
case FULL_SCREEN:
|
||||
attrs[n+0] = NSOpenGLPFAFullScreen;
|
||||
attrs[n+1] = NSOpenGLPFADoubleBuffer;
|
||||
attrs[n+2] = NSOpenGLPFAScreenMask;
|
||||
attrs[n+3] = NSOpenGLPixelFormatAttribute( CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay) );
|
||||
break;
|
||||
case PIXEL_BUFFER:
|
||||
attrs[n+0] = NSOpenGLPFAOffScreen;
|
||||
attrs[n+1] = NSOpenGLPFAPixelBuffer;
|
||||
break;
|
||||
}
|
||||
|
||||
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||
|
||||
if( !pixelFormat )
|
||||
return nil;
|
||||
|
||||
NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:share];
|
||||
|
||||
bShared = share && context;
|
||||
if( !context )
|
||||
context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
|
||||
|
||||
[pixelFormat release];
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
class RenderTarget_MacOSX : public RenderTarget
|
||||
{
|
||||
public:
|
||||
RenderTarget_MacOSX( id shareContext );
|
||||
~RenderTarget_MacOSX();
|
||||
void Create( const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut );
|
||||
unsigned GetTexture() const { return m_iTexHandle; }
|
||||
void StartRenderingTo();
|
||||
void FinishRenderingTo();
|
||||
|
||||
private:
|
||||
NSOpenGLContext *m_ShareContext, *m_OldContext, *m_PBufferContext;
|
||||
GLuint m_iTexHandle;
|
||||
int m_iWidth, m_iHeight;
|
||||
};
|
||||
|
||||
RenderTarget_MacOSX::RenderTarget_MacOSX( id shareContext )
|
||||
{
|
||||
m_ShareContext = shareContext;
|
||||
m_OldContext = nil;
|
||||
m_PBufferContext = nil;
|
||||
m_iTexHandle = 0;
|
||||
m_iWidth = 0;
|
||||
m_iHeight = 0;
|
||||
}
|
||||
|
||||
RenderTarget_MacOSX::~RenderTarget_MacOSX()
|
||||
{
|
||||
POOL;
|
||||
[m_PBufferContext release];
|
||||
if( m_iTexHandle )
|
||||
glDeleteTextures( 1, &m_iTexHandle );
|
||||
}
|
||||
|
||||
void RenderTarget_MacOSX::Create( const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut )
|
||||
{
|
||||
POOL;
|
||||
m_iWidth = param.iWidth;
|
||||
m_iHeight = param.iHeight;
|
||||
|
||||
// PBuffer needs to be a power of 2.
|
||||
int iTextureWidth = power_of_two( param.iWidth );
|
||||
int iTextureHeight = power_of_two( param.iHeight );
|
||||
|
||||
// Create the PBuffer.
|
||||
unsigned long format = param.bWithAlpha? GL_RGBA:GL_RGB;
|
||||
NSOpenGLPixelBuffer *PBuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_2D
|
||||
textureInternalFormat:format
|
||||
textureMaxMipMapLevel:0 // No idea.
|
||||
pixelsWide:iTextureWidth
|
||||
pixelsHigh:iTextureHeight];
|
||||
DEBUG_ASSERT( PBuffer );
|
||||
|
||||
// Create an OGL context.
|
||||
bool bShared = false;
|
||||
m_PBufferContext = CreateOGLContext( PIXEL_BUFFER, 24, param.bWithAlpha? 8:0, param.bWithDepthBuffer? 16:0, m_ShareContext, bShared );
|
||||
DEBUG_ASSERT( m_PBufferContext );
|
||||
DEBUG_ASSERT( bShared );
|
||||
[m_PBufferContext setPixelBuffer:PBuffer cubeMapFace:0 mipMapLevel:0
|
||||
currentVirtualScreen:[m_ShareContext currentVirtualScreen]];
|
||||
[PBuffer release]; // XXX: Hopefully this is retained by the PBufferContext.
|
||||
|
||||
glGenTextures( 1, &m_iTexHandle );
|
||||
glBindTexture( GL_TEXTURE_2D, m_iTexHandle );
|
||||
|
||||
while( glGetError() != GL_NO_ERROR )
|
||||
;
|
||||
|
||||
iTextureWidthOut = iTextureWidth;
|
||||
iTextureHeightOut = iTextureHeight;
|
||||
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, param.bWithAlpha? GL_RGBA8:GL_RGB8,
|
||||
iTextureWidth, iTextureHeight, 0, param.bWithAlpha? GL_RGBA:GL_RGB,
|
||||
GL_UNSIGNED_BYTE, NULL );
|
||||
GLenum error = glGetError();
|
||||
ASSERT_M( error == GL_NO_ERROR, RageDisplay_OGL_Helpers::GLToString(error) );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
}
|
||||
|
||||
void RenderTarget_MacOSX::StartRenderingTo()
|
||||
{
|
||||
DEBUG_ASSERT( !m_OldContext );
|
||||
m_OldContext = [NSOpenGLContext currentContext];
|
||||
[m_PBufferContext makeCurrentContext];
|
||||
glViewport( 0, 0, m_iWidth, m_iHeight );
|
||||
}
|
||||
|
||||
void RenderTarget_MacOSX::FinishRenderingTo()
|
||||
{
|
||||
DEBUG_ASSERT( m_OldContext );
|
||||
glBindTexture( GL_TEXTURE_2D, m_iTexHandle );
|
||||
|
||||
while( glGetError() != GL_NO_ERROR )
|
||||
;
|
||||
|
||||
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_iWidth, m_iHeight );
|
||||
|
||||
GLenum error = glGetError();
|
||||
ASSERT_M( error == GL_NO_ERROR, RageDisplay_OGL_Helpers::GLToString(error) );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||
|
||||
[m_OldContext makeCurrentContext];
|
||||
m_OldContext = nil;
|
||||
}
|
||||
|
||||
|
||||
LowLevelWindow_MacOSX::LowLevelWindow_MacOSX() : m_Context(nil), m_BGContext(nil), m_CurrentDisplayMode(NULL), m_DisplayID(0)
|
||||
{
|
||||
POOL;
|
||||
m_WindowDelegate = [[SMWindowDelegate alloc] init];
|
||||
[m_WindowDelegate performSelectorOnMainThread:@selector(setupWindow) withObject:nil waitUntilDone:YES];
|
||||
|
||||
m_CurrentParams.windowed = true; // We are essentially windowed to begin with.
|
||||
SetActualParamsFromMode( CGDisplayCurrentMode(kCGDirectMainDisplay) );
|
||||
HOOKS->SetHasFocus( [NSApp isActive] );
|
||||
}
|
||||
|
||||
LowLevelWindow_MacOSX::~LowLevelWindow_MacOSX()
|
||||
{
|
||||
POOL;
|
||||
ShutDownFullScreen();
|
||||
|
||||
[m_Context clearDrawable];
|
||||
[m_Context release];
|
||||
[m_BGContext clearDrawable];
|
||||
[m_BGContext release];
|
||||
[m_WindowDelegate performSelectorOnMainThread:@selector(closeWindow) withObject:nil waitUntilDone:YES];
|
||||
[m_WindowDelegate release];
|
||||
}
|
||||
|
||||
void *LowLevelWindow_MacOSX::GetProcAddress( RString s )
|
||||
{
|
||||
// http://developer.apple.com/qa/qa2001/qa1188.html
|
||||
// Both functions mentioned in there are deprecated in 10.4.
|
||||
const RString& symbolName( '_' + s );
|
||||
const uint32_t count = _dyld_image_count();
|
||||
NSSymbol symbol = NULL;
|
||||
const uint32_t options = NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR;
|
||||
|
||||
for( uint32_t i = 0; i < count && !symbol; ++i )
|
||||
symbol = NSLookupSymbolInImage( _dyld_get_image_header(i), symbolName, options );
|
||||
return symbol ? NSAddressOfSymbol( symbol ) : NULL;
|
||||
}
|
||||
|
||||
RString LowLevelWindow_MacOSX::TryVideoMode( const VideoModeParams& p, bool& newDeviceOut )
|
||||
{
|
||||
// Always set these params.
|
||||
m_CurrentParams.bSmoothLines = p.bSmoothLines;
|
||||
m_CurrentParams.bTrilinearFiltering = p.bTrilinearFiltering;
|
||||
m_CurrentParams.bAnisotropicFiltering = p.bAnisotropicFiltering;
|
||||
m_CurrentParams.interlaced = p.interlaced;
|
||||
m_CurrentParams.PAL = p.PAL;
|
||||
m_CurrentParams.fDisplayAspectRatio = p.fDisplayAspectRatio;
|
||||
|
||||
#define X(x) p.x != m_CurrentParams.x
|
||||
const bool bRebuildContext = X(bpp) || X(windowed) || !m_Context;
|
||||
const bool bChangeMode = X(width) || X(height) || X(rate) || bRebuildContext;
|
||||
const bool bChangeVsync = X(vsync) || bRebuildContext;
|
||||
#undef X
|
||||
|
||||
if( !bChangeMode && !bChangeVsync )
|
||||
return RString();
|
||||
|
||||
POOL;
|
||||
newDeviceOut = false;
|
||||
|
||||
ASSERT( p.bpp == 16 || p.bpp == 32 );
|
||||
|
||||
// If we don't have focus, we cannot be full screen.
|
||||
if( p.windowed || !HOOKS->AppHasFocus() )
|
||||
{
|
||||
if( bRebuildContext )
|
||||
{
|
||||
bool bShared;
|
||||
NSOpenGLContext *newContext = CreateOGLContext( WINDOWED, p.bpp == 16? 16:24, p.bpp == 16? 1:8, 16, m_Context, bShared );
|
||||
|
||||
if( !newContext )
|
||||
return "Failed to create OGL context.";
|
||||
ShutDownFullScreen();
|
||||
[m_Context release];
|
||||
m_Context = newContext;
|
||||
newDeviceOut = !bShared;
|
||||
m_CurrentParams.bpp = p.bpp;
|
||||
[m_BGContext release];
|
||||
m_BGContext = nil;
|
||||
m_BGContext = CreateOGLContext( WINDOWED, p.bpp == 16? 16:24, p.bpp == 16? 1:8, 16, m_Context, bShared );
|
||||
|
||||
if( m_BGContext && !bShared )
|
||||
{
|
||||
[m_BGContext release];
|
||||
m_BGContext = nil;
|
||||
}
|
||||
}
|
||||
|
||||
[m_WindowDelegate performSelectorOnMainThread:@selector(setParams:) withObject:[NSValue valueWithPointer:&p] waitUntilDone:YES];
|
||||
[m_Context setView:[((SMWindowDelegate *)m_WindowDelegate)->m_Window contentView]];
|
||||
[m_Context update];
|
||||
[m_Context makeCurrentContext];
|
||||
m_CurrentParams.windowed = true;
|
||||
SetActualParamsFromMode( CGDisplayCurrentMode(kCGDirectMainDisplay) );
|
||||
m_CurrentParams.vsync = p.vsync; // hack
|
||||
|
||||
return RString();
|
||||
}
|
||||
if( bChangeMode )
|
||||
{
|
||||
int result = ChangeDisplayMode( p );
|
||||
|
||||
if( result )
|
||||
return ssprintf( "Failed to switch to full screen:%d x %d @ %d. Error %d.",
|
||||
p.width, p.height, p.rate, result );
|
||||
}
|
||||
|
||||
if( bRebuildContext )
|
||||
{
|
||||
bool bShared;
|
||||
NSOpenGLContext *newContext = CreateOGLContext( FULL_SCREEN, p.bpp == 16? 16:24, p.bpp == 16? 1:8, 16, m_Context, bShared );
|
||||
|
||||
if( !newContext )
|
||||
return "Failed to create full screen OGL context.";
|
||||
[m_Context clearDrawable];
|
||||
[m_Context release];
|
||||
m_Context = newContext;
|
||||
newDeviceOut = !bShared;
|
||||
m_CurrentParams.bpp = p.bpp;
|
||||
[m_BGContext release];
|
||||
m_BGContext = CreateOGLContext( FULL_SCREEN, p.bpp == 16? 16:24, p.bpp == 16? 1:8, 16, m_Context, bShared );
|
||||
|
||||
if( m_BGContext && !bShared )
|
||||
{
|
||||
[m_BGContext release];
|
||||
m_BGContext = nil;
|
||||
}
|
||||
}
|
||||
|
||||
[m_Context setFullScreen];
|
||||
[m_Context update];
|
||||
[m_Context makeCurrentContext];
|
||||
|
||||
if( bChangeVsync )
|
||||
{
|
||||
long swap = p.vsync ? 1 : 0;
|
||||
|
||||
[m_Context setValues:&swap forParameter:NSOpenGLCPSwapInterval];
|
||||
m_CurrentParams.vsync = p.vsync;
|
||||
}
|
||||
|
||||
return RString();
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::ShutDownFullScreen()
|
||||
{
|
||||
if( m_CurrentParams.windowed )
|
||||
return;
|
||||
ASSERT( m_CurrentDisplayMode );
|
||||
|
||||
// Clear the front and back framebuffers before switching out of FullScreen mode.
|
||||
// (This is not strictly necessary, but avoids an untidy flash of garbage.)
|
||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
[m_Context flushBuffer];
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
[m_Context flushBuffer];
|
||||
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
[m_Context clearDrawable];
|
||||
[m_BGContext clearDrawable];
|
||||
|
||||
CGDisplayErr err = CGDisplaySwitchToMode( kCGDirectMainDisplay, m_CurrentDisplayMode );
|
||||
|
||||
ASSERT( err == kCGErrorSuccess );
|
||||
CGDisplayShowCursor( kCGDirectMainDisplay );
|
||||
err = CGDisplayRelease( m_DisplayID );
|
||||
ASSERT( err == kCGErrorSuccess );
|
||||
SetActualParamsFromMode( m_CurrentDisplayMode );
|
||||
// We don't own this so we cannot release it.
|
||||
m_CurrentDisplayMode = NULL;
|
||||
m_CurrentParams.windowed = true;
|
||||
}
|
||||
|
||||
int LowLevelWindow_MacOSX::ChangeDisplayMode( const VideoModeParams& p )
|
||||
{
|
||||
CFDictionaryRef mode = NULL;
|
||||
CFDictionaryRef newMode;
|
||||
CGDisplayErr err;
|
||||
|
||||
if( !m_CurrentDisplayMode )
|
||||
{
|
||||
m_DisplayID = CGMainDisplayID();
|
||||
if( (err = CGDisplayCapture(m_DisplayID)) != kCGErrorSuccess )
|
||||
return err;
|
||||
// Only hide the first time we go to full screen.
|
||||
CGDisplayHideCursor( kCGDirectMainDisplay );
|
||||
mode = CGDisplayCurrentMode( kCGDirectMainDisplay );
|
||||
}
|
||||
|
||||
if( p.rate == REFRESH_DEFAULT )
|
||||
newMode = CGDisplayBestModeForParameters( kCGDirectMainDisplay, p.bpp, p.width, p.height, NULL );
|
||||
else
|
||||
newMode = CGDisplayBestModeForParametersAndRefreshRate( kCGDirectMainDisplay, p.bpp,
|
||||
p.width, p.height, p.rate, NULL );
|
||||
|
||||
|
||||
err = CGDisplaySwitchToMode( kCGDirectMainDisplay, newMode );
|
||||
|
||||
if( err != kCGErrorSuccess )
|
||||
return err; // We don't own mode, don't release it.
|
||||
|
||||
if( !m_CurrentDisplayMode )
|
||||
m_CurrentDisplayMode = mode;
|
||||
m_CurrentParams.windowed = false;
|
||||
SetActualParamsFromMode( newMode );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::SetActualParamsFromMode( CFDictionaryRef mode )
|
||||
{
|
||||
SInt32 rate;
|
||||
bool ret = CFNumberGetValue( (CFNumberRef)CFDictionaryGetValue(mode, CFSTR("RefreshRate")),
|
||||
kCFNumberSInt32Type, &rate );
|
||||
|
||||
if( !ret || rate == 0)
|
||||
rate = 60;
|
||||
m_CurrentParams.rate = rate;
|
||||
|
||||
if( !m_CurrentParams.windowed )
|
||||
{
|
||||
long swap;
|
||||
|
||||
m_CurrentParams.width = CGDisplayPixelsWide( kCGDirectMainDisplay );
|
||||
m_CurrentParams.height = CGDisplayPixelsHigh( kCGDirectMainDisplay );
|
||||
CGLGetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &swap );
|
||||
m_CurrentParams.vsync = swap != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSSize size = [[((SMWindowDelegate *)m_WindowDelegate)->m_Window contentView] frame].size;
|
||||
|
||||
m_CurrentParams.width = int(size.width);
|
||||
m_CurrentParams.height = int(size.height);
|
||||
}
|
||||
|
||||
m_CurrentParams.bpp = CGDisplayBitsPerPixel( kCGDirectMainDisplay );
|
||||
}
|
||||
|
||||
static int GetIntValue( CFTypeRef r )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( !r || CFGetTypeID(r) != CFNumberGetTypeID() || !CFNumberGetValue(CFNumberRef(r), kCFNumberIntType, &ret) )
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool GetBoolValue( CFTypeRef r )
|
||||
{
|
||||
return r && CFGetTypeID( r ) == CFBooleanGetTypeID() && CFBooleanGetValue( CFBooleanRef(r) );
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::GetDisplayResolutions( DisplayResolutions &dr ) const
|
||||
{
|
||||
CFArrayRef modes = CGDisplayAvailableModes( kCGDirectMainDisplay );
|
||||
ASSERT( modes );
|
||||
const CFIndex count = CFArrayGetCount( modes );
|
||||
|
||||
for( CFIndex i = 0; i < count; ++i )
|
||||
{
|
||||
CFDictionaryRef dict = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, i );
|
||||
int width = GetIntValue( CFDictionaryGetValue(dict, kCGDisplayWidth) );
|
||||
int height = GetIntValue( CFDictionaryGetValue(dict, kCGDisplayHeight) );
|
||||
CFTypeRef safe = CFDictionaryGetValue( dict, kCGDisplayModeIsSafeForHardware );
|
||||
bool stretched = GetBoolValue( CFDictionaryGetValue(dict, kCGDisplayModeIsStretched) );
|
||||
|
||||
if( !width || !height )
|
||||
continue;
|
||||
if( safe && !GetBoolValue( safe ) )
|
||||
continue;
|
||||
DisplayResolution res = { width, height, stretched };
|
||||
dr.insert( res );
|
||||
}
|
||||
// Do not release modes! We don't own them here.
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::SwapBuffers()
|
||||
{
|
||||
CGLFlushDrawable( CGLGetCurrentContext() );
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::Update()
|
||||
{
|
||||
// Keep the system from sleeping or the screen saver from activating.
|
||||
UpdateSystemActivity( IdleActivity );
|
||||
|
||||
LockMutex lock( g_ResizeLock );
|
||||
if( likely(!g_bResized) )
|
||||
return;
|
||||
g_bResized = false;
|
||||
if( m_CurrentParams.width == g_iWidth && m_CurrentParams.height == g_iHeight )
|
||||
return;
|
||||
m_CurrentParams.width = g_iWidth;
|
||||
m_CurrentParams.height = g_iHeight;
|
||||
lock.Unlock(); // Unlock before calling ResolutionChanged().
|
||||
[m_Context update];
|
||||
DISPLAY->ResolutionChanged();
|
||||
}
|
||||
|
||||
RenderTarget *LowLevelWindow_MacOSX::CreateRenderTarget()
|
||||
{
|
||||
return new RenderTarget_MacOSX( m_Context );
|
||||
}
|
||||
|
||||
void LowLevelWindow_MacOSX::BeginConcurrentRendering()
|
||||
{
|
||||
if( m_CurrentParams.windowed )
|
||||
[m_BGContext setView:[((SMWindowDelegate *)m_WindowDelegate)->m_Window contentView]];
|
||||
else
|
||||
[m_BGContext setFullScreen];
|
||||
[m_BGContext makeCurrentContext];
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2005-2006, 2008 Steve Checkoway
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
#include "global.h"
|
||||
#include "LowLevelWindow_Win32.h"
|
||||
#include "archutils/Win32/DirectXHelpers.h"
|
||||
#include "archutils/Win32/ErrorStrings.h"
|
||||
#include "archutils/Win32/GraphicsWindow.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageDisplay.h"
|
||||
#include "LocalizedString.h"
|
||||
#include "RageDisplay_OGL_Helpers.h"
|
||||
#include "RageDisplay_OGL.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat;
|
||||
static HGLRC g_HGLRC = NULL;
|
||||
static HGLRC g_HGLRC_Background = NULL;
|
||||
|
||||
static void DestroyGraphicsWindowAndOpenGLContext()
|
||||
{
|
||||
if( g_HGLRC != NULL )
|
||||
{
|
||||
wglMakeCurrent( NULL, NULL );
|
||||
wglDeleteContext( g_HGLRC );
|
||||
g_HGLRC = NULL;
|
||||
}
|
||||
|
||||
if( g_HGLRC_Background != NULL )
|
||||
{
|
||||
wglDeleteContext( g_HGLRC_Background );
|
||||
g_HGLRC_Background = NULL;
|
||||
}
|
||||
|
||||
ZERO( g_CurrentPixelFormat );
|
||||
|
||||
GraphicsWindow::DestroyGraphicsWindow();
|
||||
}
|
||||
|
||||
void *LowLevelWindow_Win32::GetProcAddress( RString s )
|
||||
{
|
||||
void *pRet = wglGetProcAddress( s );
|
||||
if( pRet != NULL )
|
||||
return pRet;
|
||||
|
||||
return ::GetProcAddress( GetModuleHandle(NULL), s );
|
||||
}
|
||||
|
||||
LowLevelWindow_Win32::LowLevelWindow_Win32()
|
||||
{
|
||||
ASSERT( g_HGLRC == NULL );
|
||||
ASSERT( g_HGLRC_Background == NULL );
|
||||
|
||||
GraphicsWindow::Initialize( false );
|
||||
}
|
||||
|
||||
LowLevelWindow_Win32::~LowLevelWindow_Win32()
|
||||
{
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
GraphicsWindow::Shutdown();
|
||||
}
|
||||
|
||||
void LowLevelWindow_Win32::GetDisplayResolutions( DisplayResolutions &out ) const
|
||||
{
|
||||
GraphicsWindow::GetDisplayResolutions( out );
|
||||
}
|
||||
|
||||
int ChooseWindowPixelFormat( const VideoModeParams &p, PIXELFORMATDESCRIPTOR *PixelFormat )
|
||||
{
|
||||
ASSERT( GraphicsWindow::GetHwnd() != NULL );
|
||||
ASSERT( GraphicsWindow::GetHDC() != NULL );
|
||||
|
||||
ZERO( *PixelFormat );
|
||||
PixelFormat->nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
PixelFormat->nVersion = 1;
|
||||
PixelFormat->dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL;
|
||||
PixelFormat->iPixelType = PFD_TYPE_RGBA;
|
||||
PixelFormat->cColorBits = p.bpp == 16? 16:24;
|
||||
PixelFormat->cDepthBits = 16;
|
||||
|
||||
return ChoosePixelFormat( GraphicsWindow::GetHDC(), PixelFormat );
|
||||
}
|
||||
|
||||
void DumpPixelFormat( const PIXELFORMATDESCRIPTOR &pfd )
|
||||
{
|
||||
RString str = ssprintf( "Mode: " );
|
||||
bool bInvalidFormat = false;
|
||||
|
||||
if( pfd.dwFlags & PFD_GENERIC_FORMAT )
|
||||
{
|
||||
if( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) str += "MCD ";
|
||||
else { str += "software "; bInvalidFormat = true; }
|
||||
}
|
||||
else
|
||||
{
|
||||
str += "ICD ";
|
||||
}
|
||||
|
||||
if( pfd.iPixelType != PFD_TYPE_RGBA ) { str += "indexed "; bInvalidFormat = true; }
|
||||
if( !(pfd.dwFlags & PFD_SUPPORT_OPENGL) ) { str += "!OPENGL "; bInvalidFormat = true; }
|
||||
if( !(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ) { str += "!window "; bInvalidFormat = true; }
|
||||
if( !(pfd.dwFlags & PFD_DOUBLEBUFFER) ) { str += "!dbuff "; bInvalidFormat = true; }
|
||||
|
||||
str += ssprintf( "%i (%i%i%i) ", pfd.cColorBits, pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits );
|
||||
if( pfd.cAlphaBits ) str += ssprintf( "%i alpha ", pfd.cAlphaBits );
|
||||
if( pfd.cDepthBits ) str += ssprintf( "%i depth ", pfd.cDepthBits );
|
||||
if( pfd.cStencilBits ) str += ssprintf( "%i stencil ", pfd.cStencilBits );
|
||||
if( pfd.cAccumBits ) str += ssprintf( "%i accum ", pfd.cAccumBits );
|
||||
|
||||
if( bInvalidFormat )
|
||||
LOG->Warn( "Invalid format: %s", str.c_str() );
|
||||
else
|
||||
LOG->Info( "%s", str.c_str() );
|
||||
}
|
||||
|
||||
/* This function does not reset the video mode if it fails, because we might be trying
|
||||
* yet another video mode, so we'd just thrash the display. On fatal error,
|
||||
* LowLevelWindow_Win32::~LowLevelWindow_Win32 will call GraphicsWindow::Shutdown(). */
|
||||
RString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut )
|
||||
{
|
||||
//LOG->Warn( "LowLevelWindow_Win32::TryVideoMode" );
|
||||
|
||||
ASSERT_M( p.bpp == 16 || p.bpp == 32, ssprintf("%i", p.bpp) );
|
||||
|
||||
bNewDeviceOut = false;
|
||||
|
||||
/* We're only allowed to change the pixel format of a window exactly once. */
|
||||
bool bCanSetPixelFormat = true;
|
||||
|
||||
/* Do we have an old window? */
|
||||
if( GraphicsWindow::GetHwnd() == NULL )
|
||||
{
|
||||
/* No. Always create and show the window before changing the video mode.
|
||||
* Otherwise, some other window may have focus, and changing the video mode will
|
||||
* cause that window to be resized. */
|
||||
bNewDeviceOut = true;
|
||||
GraphicsWindow::CreateGraphicsWindow( p );
|
||||
} else {
|
||||
/* We already have a window. Assume that it's pixel format has already been
|
||||
* set. */
|
||||
bCanSetPixelFormat = false;
|
||||
}
|
||||
|
||||
ASSERT( GraphicsWindow::GetHwnd() );
|
||||
|
||||
/* Set the display mode: switch to a fullscreen mode or revert to windowed mode. */
|
||||
LOG->Trace("SetScreenMode ...");
|
||||
RString sErr = GraphicsWindow::SetScreenMode( p );
|
||||
if( !sErr.empty() )
|
||||
return sErr;
|
||||
|
||||
PIXELFORMATDESCRIPTOR PixelFormat;
|
||||
int iPixelFormat = ChooseWindowPixelFormat( p, &PixelFormat );
|
||||
if( iPixelFormat == 0 )
|
||||
{
|
||||
/* Destroy the window. */
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
return "Pixel format not found";
|
||||
}
|
||||
|
||||
bool bNeedToSetPixelFormat = false;
|
||||
{
|
||||
/* We'll need to recreate it if the pixel format is going to change. We
|
||||
* aren't allowed to change the pixel format twice. */
|
||||
PIXELFORMATDESCRIPTOR DestPixelFormat;
|
||||
ZERO( DestPixelFormat );
|
||||
DescribePixelFormat( GraphicsWindow::GetHDC(), iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &DestPixelFormat );
|
||||
if( memcmp( &DestPixelFormat, &g_CurrentPixelFormat, sizeof(PIXELFORMATDESCRIPTOR) ) )
|
||||
{
|
||||
LOG->Trace("Reset: pixel format changing" );
|
||||
bNeedToSetPixelFormat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( bNeedToSetPixelFormat && !bCanSetPixelFormat )
|
||||
{
|
||||
/*
|
||||
* The screen mode has changed, so we need to set the pixel format. If we're
|
||||
* not allowed to do so, destroy the window and make a new one.
|
||||
*
|
||||
* For some reason, if we destroy the old window before creating the new one,
|
||||
* the "maximized apps go under the taskbar" glitch will happen when we quit.
|
||||
* We have to create the new window first.
|
||||
*/
|
||||
LOG->Trace( "Mode requires new pixel format, and we've already set one; resetting OpenGL context" );
|
||||
if( g_HGLRC != NULL )
|
||||
{
|
||||
wglMakeCurrent( NULL, NULL );
|
||||
wglDeleteContext( g_HGLRC );
|
||||
g_HGLRC = NULL;
|
||||
wglDeleteContext( g_HGLRC_Background );
|
||||
g_HGLRC_Background = NULL;
|
||||
}
|
||||
|
||||
bNewDeviceOut = true;
|
||||
}
|
||||
|
||||
/* If we deleted the OpenGL context above, also recreate the window. Otherwise, just
|
||||
* reconfigure it. */
|
||||
GraphicsWindow::CreateGraphicsWindow( p, bNewDeviceOut );
|
||||
|
||||
if( bNeedToSetPixelFormat )
|
||||
{
|
||||
/* Set the pixel format. */
|
||||
if( !SetPixelFormat(GraphicsWindow::GetHDC(), iPixelFormat, &PixelFormat) )
|
||||
{
|
||||
/* Destroy the window. */
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
|
||||
return werr_ssprintf( GetLastError(), "Pixel format failed" );
|
||||
}
|
||||
|
||||
DescribePixelFormat( GraphicsWindow::GetHDC(), iPixelFormat, sizeof(g_CurrentPixelFormat), &g_CurrentPixelFormat );
|
||||
|
||||
DumpPixelFormat( g_CurrentPixelFormat );
|
||||
}
|
||||
|
||||
if( g_HGLRC == NULL )
|
||||
{
|
||||
g_HGLRC = wglCreateContext( GraphicsWindow::GetHDC() );
|
||||
if ( g_HGLRC == NULL )
|
||||
{
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
return hr_ssprintf( GetLastError(), "wglCreateContext" );
|
||||
}
|
||||
|
||||
g_HGLRC_Background = wglCreateContext( GraphicsWindow::GetHDC() );
|
||||
if( g_HGLRC_Background == NULL )
|
||||
{
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
return hr_ssprintf( GetLastError(), "wglCreateContext" );
|
||||
}
|
||||
|
||||
if( !wglShareLists(g_HGLRC, g_HGLRC_Background) )
|
||||
{
|
||||
LOG->Warn( werr_ssprintf(GetLastError(), "wglShareLists failed") );
|
||||
wglDeleteContext( g_HGLRC_Background );
|
||||
g_HGLRC_Background = NULL;
|
||||
}
|
||||
|
||||
if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC ) )
|
||||
{
|
||||
DestroyGraphicsWindowAndOpenGLContext();
|
||||
return hr_ssprintf( GetLastError(), "wglCreateContext" );
|
||||
}
|
||||
}
|
||||
return RString(); // we set the video mode successfully
|
||||
}
|
||||
|
||||
bool LowLevelWindow_Win32::SupportsThreadedRendering()
|
||||
{
|
||||
return g_HGLRC_Background != NULL;
|
||||
}
|
||||
|
||||
void LowLevelWindow_Win32::BeginConcurrentRendering()
|
||||
{
|
||||
if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC_Background ) )
|
||||
{
|
||||
LOG->Warn( hr_ssprintf(GetLastError(), "wglMakeCurrent") );
|
||||
FAIL_M( hr_ssprintf(GetLastError(), "wglMakeCurrent") );
|
||||
}
|
||||
}
|
||||
|
||||
void LowLevelWindow_Win32::EndConcurrentRendering()
|
||||
{
|
||||
wglMakeCurrent( NULL, NULL );
|
||||
}
|
||||
|
||||
static LocalizedString OPENGL_NOT_AVAILABLE( "LowLevelWindow_Win32", "OpenGL hardware acceleration is not available." );
|
||||
bool LowLevelWindow_Win32::IsSoftwareRenderer( RString &sError )
|
||||
{
|
||||
RString sVendor = (const char*)glGetString(GL_VENDOR);
|
||||
RString sRenderer = (const char*)glGetString(GL_RENDERER);
|
||||
|
||||
LOG->Trace( "LowLevelWindow_Win32::IsSoftwareRenderer '%s', '%s'", sVendor.c_str(), sRenderer.c_str() );
|
||||
|
||||
if( sVendor == "Microsoft Corporation" && sRenderer == "GDI Generic" )
|
||||
{
|
||||
sError = OPENGL_NOT_AVAILABLE;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LowLevelWindow_Win32::SwapBuffers()
|
||||
{
|
||||
::SwapBuffers( GraphicsWindow::GetHDC() );
|
||||
}
|
||||
|
||||
void LowLevelWindow_Win32::Update()
|
||||
{
|
||||
GraphicsWindow::Update();
|
||||
}
|
||||
|
||||
const VideoModeParams &LowLevelWindow_Win32::GetActualVideoModeParams() const
|
||||
{
|
||||
return GraphicsWindow::GetParams();
|
||||
}
|
||||
|
||||
class RenderTarget_Win32 : public RenderTarget
|
||||
{
|
||||
public:
|
||||
RenderTarget_Win32( LowLevelWindow_Win32 *pWind );
|
||||
virtual ~RenderTarget_Win32();
|
||||
|
||||
void Create( const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut );
|
||||
unsigned int GetTexture() const { return m_texHandle; }
|
||||
void StartRenderingTo();
|
||||
void FinishRenderingTo();
|
||||
|
||||
virtual bool InvertY() const { return true; }
|
||||
|
||||
private:
|
||||
LowLevelWindow_Win32 *m_pWind;
|
||||
int m_width;
|
||||
int m_height;
|
||||
GLuint m_texHandle;
|
||||
HDC m_hOldDeviceContext;
|
||||
HGLRC m_hOldRenderContext;
|
||||
};
|
||||
|
||||
RenderTarget_Win32::RenderTarget_Win32(LowLevelWindow_Win32 *pWind)
|
||||
{
|
||||
m_pWind = pWind;
|
||||
m_texHandle = 0;
|
||||
m_hOldDeviceContext = NULL;
|
||||
m_hOldRenderContext = NULL;
|
||||
}
|
||||
|
||||
RenderTarget_Win32::~RenderTarget_Win32()
|
||||
{
|
||||
glDeleteTextures( 1, &m_texHandle ); // deleting a 0 texture is safe and ignored
|
||||
}
|
||||
|
||||
void RenderTarget_Win32::Create(const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut)
|
||||
{
|
||||
m_Param = param;
|
||||
m_width = param.iWidth;
|
||||
m_height = param.iHeight;
|
||||
|
||||
FlushGLErrors();
|
||||
|
||||
glGenTextures( 1, &m_texHandle );
|
||||
ASSERT(m_texHandle > 0);
|
||||
glBindTexture( GL_TEXTURE_2D, m_texHandle );
|
||||
|
||||
int iTextureWidth = power_of_two( param.iWidth );
|
||||
int iTextureHeight = power_of_two( param.iHeight );
|
||||
iTextureWidthOut = iTextureWidth;
|
||||
iTextureHeightOut = iTextureHeight;
|
||||
|
||||
GLenum internalformat;
|
||||
GLenum type = param.bWithAlpha? GL_RGBA:GL_RGB;
|
||||
if( param.bFloat && GLExt.m_bGL_ARB_texture_float )
|
||||
internalformat = param.bWithAlpha? GL_RGBA16F_ARB:GL_RGB16F_ARB;
|
||||
else
|
||||
internalformat = param.bWithAlpha? GL_RGBA8:GL_RGB8;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, iTextureWidth,
|
||||
iTextureHeight, 0, type, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
|
||||
AssertNoGLError();
|
||||
}
|
||||
|
||||
void RenderTarget_Win32::StartRenderingTo()
|
||||
{
|
||||
m_hOldDeviceContext = wglGetCurrentDC();
|
||||
m_hOldRenderContext = wglGetCurrentContext();
|
||||
|
||||
BOOL successful = wglMakeCurrent(GraphicsWindow::GetHDC(), g_HGLRC);
|
||||
ASSERT_M( successful == TRUE, "wglMakeCurrent failed in RenderTarget_Win32::StartRenderingTo()" );
|
||||
|
||||
FlushGLErrors();
|
||||
glBindTexture( GL_TEXTURE_2D, m_texHandle );
|
||||
AssertNoGLError();
|
||||
}
|
||||
|
||||
void RenderTarget_Win32::FinishRenderingTo()
|
||||
{
|
||||
FlushGLErrors();
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, m_texHandle );
|
||||
AssertNoGLError();
|
||||
|
||||
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||
|
||||
AssertNoGLError();
|
||||
|
||||
BOOL successful = wglMakeCurrent(m_hOldDeviceContext, m_hOldRenderContext);
|
||||
ASSERT_M( successful == TRUE, "wglMakeCurrent failed in RenderTarget_Win32::FinishRenderingTo()" );
|
||||
|
||||
m_hOldDeviceContext = 0;
|
||||
m_hOldRenderContext = 0;
|
||||
}
|
||||
|
||||
RenderTarget* LowLevelWindow_Win32::CreateRenderTarget()
|
||||
{
|
||||
return new RenderTarget_Win32( this );
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef LOW_LEVEL_WINDOW_WIN32_H
|
||||
#define LOW_LEVEL_WINDOW_WIN32_H
|
||||
|
||||
#include "LowLevelWindow.h"
|
||||
|
||||
class LowLevelWindow_Win32: public LowLevelWindow
|
||||
{
|
||||
public:
|
||||
LowLevelWindow_Win32();
|
||||
~LowLevelWindow_Win32();
|
||||
void *GetProcAddress( RString s );
|
||||
RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut );
|
||||
void GetDisplayResolutions( DisplayResolutions &out ) const;
|
||||
bool IsSoftwareRenderer( RString &sError );
|
||||
void SwapBuffers();
|
||||
void Update();
|
||||
bool SupportsThreadedRendering();
|
||||
void BeginConcurrentRendering();
|
||||
void EndConcurrentRendering();
|
||||
virtual bool SupportsRenderToTexture() const { return true; }
|
||||
virtual RenderTarget *CreateRenderTarget();
|
||||
|
||||
const VideoModeParams &GetActualVideoModeParams() const;
|
||||
};
|
||||
|
||||
#ifdef ARCH_LOW_LEVEL_WINDOW
|
||||
#error "More than one LowLevelWindow selected!"
|
||||
#endif
|
||||
#define ARCH_LOW_LEVEL_WINDOW LowLevelWindow_Win32
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,540 @@
|
||||
#include "global.h"
|
||||
#include "LowLevelWindow_X11.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageException.h"
|
||||
#include "archutils/Unix/X11Helper.h"
|
||||
#include "PrefsManager.h" // XXX
|
||||
#include "RageDisplay.h" // VideoModeParams
|
||||
#include "DisplayResolutions.h"
|
||||
#include "LocalizedString.h"
|
||||
|
||||
#include "RageDisplay_OGL_Helpers.h"
|
||||
using namespace RageDisplay_OGL_Helpers;
|
||||
using namespace X11Helper;
|
||||
|
||||
#include <stack>
|
||||
#include <math.h> // ceil()
|
||||
#define GLX_GLXEXT_PROTOTYPES
|
||||
#include <GL/glx.h> // All sorts of stuff...
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
||||
#if defined(HAVE_LIBXTST)
|
||||
#include <X11/extensions/XTest.h>
|
||||
#endif
|
||||
|
||||
static GLXContext g_pContext = NULL;
|
||||
static GLXContext g_pBackgroundContext = NULL;
|
||||
static Window g_AltWindow = None;
|
||||
static Rotation g_OldRotation;
|
||||
static int g_iOldSize;
|
||||
XRRScreenConfiguration *g_pScreenConfig = NULL;
|
||||
|
||||
static LocalizedString FAILED_CONNECTION_XSERVER( "LowLevelWindow_X11", "Failed to establish a connection with the X server" );
|
||||
LowLevelWindow_X11::LowLevelWindow_X11()
|
||||
{
|
||||
if( !OpenXConnection() )
|
||||
RageException::Throw( "%s", FAILED_CONNECTION_XSERVER.GetValue().c_str() );
|
||||
|
||||
const int iScreen = DefaultScreen( Dpy );
|
||||
int iXServerVersion = XVendorRelease( Dpy ); /* eg. 40201001 */
|
||||
int iMajor = iXServerVersion / 10000000; iXServerVersion %= 10000000;
|
||||
int iMinor = iXServerVersion / 100000; iXServerVersion %= 100000;
|
||||
int iRevision = iXServerVersion / 1000; iXServerVersion %= 1000;
|
||||
int iPatch = iXServerVersion;
|
||||
|
||||
|
||||
LOG->Info( "Display: %s (screen %i)", DisplayString(Dpy), iScreen );
|
||||
LOG->Info( "X server vendor: %s [%i.%i.%i.%i]", XServerVendor( Dpy ), iMajor, iMinor, iRevision, iPatch );
|
||||
LOG->Info( "Server GLX vendor: %s [%s]", glXQueryServerString( Dpy, iScreen, GLX_VENDOR ), glXQueryServerString( Dpy, iScreen, GLX_VERSION ) );
|
||||
LOG->Info( "Client GLX vendor: %s [%s]", glXGetClientString( Dpy, GLX_VENDOR ), glXGetClientString( Dpy, GLX_VERSION ) );
|
||||
m_bWasWindowed = true;
|
||||
g_pScreenConfig = XRRGetScreenInfo( Dpy, RootWindow(Dpy, DefaultScreen(Dpy)) );
|
||||
}
|
||||
|
||||
LowLevelWindow_X11::~LowLevelWindow_X11()
|
||||
{
|
||||
// Reset the display
|
||||
if( !m_bWasWindowed )
|
||||
{
|
||||
XRRSetScreenConfig( Dpy, g_pScreenConfig, RootWindow(Dpy, DefaultScreen(Dpy)), g_iOldSize, g_OldRotation, CurrentTime );
|
||||
|
||||
XUngrabKeyboard( Dpy, CurrentTime );
|
||||
}
|
||||
if( g_pContext )
|
||||
{
|
||||
glXDestroyContext( Dpy, g_pContext );
|
||||
g_pContext = NULL;
|
||||
}
|
||||
if( g_pBackgroundContext )
|
||||
{
|
||||
glXDestroyContext( Dpy, g_pBackgroundContext );
|
||||
g_pBackgroundContext = NULL;
|
||||
}
|
||||
XRRFreeScreenConfigInfo( g_pScreenConfig );
|
||||
g_pScreenConfig = NULL;
|
||||
|
||||
XDestroyWindow( Dpy, Win );
|
||||
Win = None;
|
||||
XDestroyWindow( Dpy, g_AltWindow );
|
||||
g_AltWindow = None;
|
||||
CloseXConnection();
|
||||
}
|
||||
|
||||
void *LowLevelWindow_X11::GetProcAddress( RString s )
|
||||
{
|
||||
// XXX: We should check whether glXGetProcAddress or
|
||||
// glXGetProcAddressARB is available, and go by that, instead of
|
||||
// assuming like this.
|
||||
return (void*) glXGetProcAddressARB( (const GLubyte*) s.c_str() );
|
||||
}
|
||||
|
||||
RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut )
|
||||
{
|
||||
#if defined(UNIX)
|
||||
/*
|
||||
* nVidia cards:
|
||||
*
|
||||
* This only works the first time we set up a window; after that, the
|
||||
* drivers appear to cache the value, so you have to actually restart
|
||||
* the program to change it again.
|
||||
*/
|
||||
static char buf[128];
|
||||
strcpy( buf, "__GL_SYNC_TO_VBLANK=" );
|
||||
strcat( buf, p.vsync?"1":"0" );
|
||||
putenv( buf );
|
||||
#endif
|
||||
|
||||
if( g_pContext == NULL || p.bpp != CurrentParams.bpp || m_bWasWindowed != p.windowed )
|
||||
{
|
||||
// Different depth, or we didn't make a window before. New context.
|
||||
bNewDeviceOut = true;
|
||||
|
||||
int visAttribs[32];
|
||||
int i = 0;
|
||||
ASSERT( p.bpp == 16 || p.bpp == 32 );
|
||||
|
||||
if( p.bpp == 32 )
|
||||
{
|
||||
visAttribs[i++] = GLX_RED_SIZE; visAttribs[i++] = 8;
|
||||
visAttribs[i++] = GLX_GREEN_SIZE; visAttribs[i++] = 8;
|
||||
visAttribs[i++] = GLX_BLUE_SIZE; visAttribs[i++] = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
visAttribs[i++] = GLX_RED_SIZE; visAttribs[i++] = 5;
|
||||
visAttribs[i++] = GLX_GREEN_SIZE; visAttribs[i++] = 6;
|
||||
visAttribs[i++] = GLX_BLUE_SIZE; visAttribs[i++] = 5;
|
||||
}
|
||||
|
||||
visAttribs[i++] = GLX_DEPTH_SIZE; visAttribs[i++] = 16;
|
||||
visAttribs[i++] = GLX_RGBA;
|
||||
visAttribs[i++] = GLX_DOUBLEBUFFER;
|
||||
|
||||
visAttribs[i++] = None;
|
||||
|
||||
XVisualInfo *xvi = glXChooseVisual( Dpy, DefaultScreen(Dpy), visAttribs );
|
||||
if( xvi == NULL )
|
||||
return "No visual available for that depth.";
|
||||
|
||||
// I get strange behavior if I add override redirect after creating the window.
|
||||
// So, let's recreate the window when changing that state.
|
||||
if( !MakeWindow(Win, xvi->screen, xvi->depth, xvi->visual, p.width, p.height, !p.windowed) )
|
||||
return "Failed to create the window.";
|
||||
|
||||
if( !MakeWindow(g_AltWindow, xvi->screen, xvi->depth, xvi->visual, p.width, p.height, !p.windowed) )
|
||||
FAIL_M( "Failed to create the alt window." ); // Should this be fatal?
|
||||
|
||||
char *szWindowTitle = const_cast<char *>( p.sWindowTitle.c_str() );
|
||||
XChangeProperty( Dpy, Win, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
|
||||
reinterpret_cast<unsigned char*>(szWindowTitle), strlen(szWindowTitle) );
|
||||
|
||||
if( g_pContext )
|
||||
glXDestroyContext( Dpy, g_pContext );
|
||||
if( g_pBackgroundContext )
|
||||
glXDestroyContext( Dpy, g_pBackgroundContext );
|
||||
g_pContext = glXCreateContext( Dpy, xvi, NULL, True );
|
||||
g_pBackgroundContext = glXCreateContext( Dpy, xvi, g_pContext, True );
|
||||
|
||||
glXMakeCurrent( Dpy, Win, g_pContext );
|
||||
|
||||
XWindowAttributes winAttrib;
|
||||
XGetWindowAttributes( Dpy, Win, &winAttrib );
|
||||
XSelectInput( Dpy, Win, winAttrib.your_event_mask | StructureNotifyMask );
|
||||
XMapWindow( Dpy, Win );
|
||||
|
||||
// XXX: Why do we need to wait for the MapNotify event?
|
||||
while( true )
|
||||
{
|
||||
XEvent event;
|
||||
XMaskEvent( Dpy, StructureNotifyMask, &event );
|
||||
if( event.type == MapNotify )
|
||||
break;
|
||||
}
|
||||
XSelectInput( Dpy, Win, winAttrib.your_event_mask );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're remodeling the existing window, and not touching the
|
||||
// context.
|
||||
bNewDeviceOut = false;
|
||||
}
|
||||
|
||||
g_iOldSize = XRRConfigCurrentConfiguration( g_pScreenConfig, &g_OldRotation );
|
||||
|
||||
if( !p.windowed )
|
||||
{
|
||||
// Find a matching mode.
|
||||
int iSizesXct;
|
||||
XRRScreenSize *pSizesX = XRRSizes( Dpy, DefaultScreen(Dpy), &iSizesXct );
|
||||
ASSERT_M( iSizesXct != 0, "Couldn't get resolution list from X server" );
|
||||
|
||||
int iSizeMatch = -1;
|
||||
|
||||
for( int i = 0; i < iSizesXct; ++i )
|
||||
{
|
||||
if( pSizesX[i].width == p.width && pSizesX[i].height == p.height )
|
||||
{
|
||||
iSizeMatch = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set this mode.
|
||||
// XXX: This doesn't handle if the config has changed since we queried it (see man Xrandr)
|
||||
XRRSetScreenConfig( Dpy, g_pScreenConfig, RootWindow(Dpy, DefaultScreen(Dpy)), iSizeMatch, 1, CurrentTime );
|
||||
|
||||
// Move the window to the corner that the screen focuses in on.
|
||||
XMoveWindow( Dpy, Win, 0, 0 );
|
||||
|
||||
XRaiseWindow( Dpy, Win );
|
||||
|
||||
if( m_bWasWindowed )
|
||||
{
|
||||
// We want to prevent the WM from catching anything that comes from the keyboard.
|
||||
XGrabKeyboard( Dpy, Win, True, GrabModeAsync, GrabModeAsync, CurrentTime );
|
||||
m_bWasWindowed = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !m_bWasWindowed )
|
||||
{
|
||||
XRRSetScreenConfig( Dpy, g_pScreenConfig, RootWindow(Dpy, DefaultScreen(Dpy)), g_iOldSize, g_OldRotation, CurrentTime );
|
||||
// In windowed mode, we actually want the WM to function normally.
|
||||
// Release any previous grab.
|
||||
XUngrabKeyboard( Dpy, CurrentTime );
|
||||
m_bWasWindowed = true;
|
||||
}
|
||||
}
|
||||
int rate = XRRConfigCurrentRate( g_pScreenConfig );
|
||||
|
||||
// Do this before resizing the window so that pane-style WMs (Ion,
|
||||
// ratpoison) don't resize us back inappropriately.
|
||||
{
|
||||
XSizeHints hints;
|
||||
|
||||
hints.flags = PBaseSize;
|
||||
hints.base_width = p.width;
|
||||
hints.base_height = p.height;
|
||||
|
||||
XSetWMNormalHints( Dpy, Win, &hints );
|
||||
}
|
||||
|
||||
// Do this even if we just created the window -- works around Ion2 not
|
||||
// catching WM normal hints changes in mapped windows.
|
||||
XResizeWindow( Dpy, Win, p.width, p.height );
|
||||
|
||||
CurrentParams = p;
|
||||
CurrentParams.rate = rate;
|
||||
return ""; // Success
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::LogDebugInformation() const
|
||||
{
|
||||
LOG->Info( "Direct rendering: %s", glXIsDirect( Dpy, glXGetCurrentContext() )? "yes":"no" );
|
||||
}
|
||||
|
||||
bool LowLevelWindow_X11::IsSoftwareRenderer( RString &sError )
|
||||
{
|
||||
if( glXIsDirect( Dpy, glXGetCurrentContext() ) )
|
||||
return false;
|
||||
|
||||
sError = "Direct rendering is not available.";
|
||||
return true;
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::SwapBuffers()
|
||||
{
|
||||
glXSwapBuffers( Dpy, Win );
|
||||
|
||||
if( PREFSMAN->m_bDisableScreenSaver )
|
||||
{
|
||||
/* Disable the screensaver. */
|
||||
#if defined(HAVE_LIBXTST)
|
||||
/* This causes flicker. */
|
||||
// XForceScreenSaver( Dpy, ScreenSaverReset );
|
||||
|
||||
/*
|
||||
* Instead, send a null relative mouse motion, to trick X into thinking there has been
|
||||
* user activity.
|
||||
*
|
||||
* This also handles XScreenSaver; XForceScreenSaver only handles the internal X11
|
||||
* screen blanker.
|
||||
*
|
||||
* This will delay the X blanker, DPMS and XScreenSaver from activating, and will
|
||||
* disable the blanker and XScreenSaver if they're already active (unless XSS is
|
||||
* locked). For some reason, it doesn't un-blank DPMS if it's already active.
|
||||
*/
|
||||
|
||||
XLockDisplay( Dpy );
|
||||
|
||||
int event_base, error_base, major, minor;
|
||||
if( XTestQueryExtension( Dpy, &event_base, &error_base, &major, &minor ) )
|
||||
{
|
||||
XTestFakeRelativeMotionEvent( Dpy, 0, 0, 0 );
|
||||
XSync( Dpy, False );
|
||||
}
|
||||
|
||||
XUnlockDisplay( Dpy );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::GetDisplayResolutions( DisplayResolutions &out ) const
|
||||
{
|
||||
int iSizesXct;
|
||||
XRRScreenSize *pSizesX = XRRSizes( Dpy, DefaultScreen( Dpy ), &iSizesXct );
|
||||
ASSERT_M( iSizesXct != 0, "Couldn't get resolution list from X server" );
|
||||
|
||||
for( int i = 0; i < iSizesXct; ++i )
|
||||
{
|
||||
DisplayResolution res = { pSizesX[i].width, pSizesX[i].height, true };
|
||||
out.insert( res );
|
||||
}
|
||||
}
|
||||
|
||||
bool LowLevelWindow_X11::SupportsThreadedRendering()
|
||||
{
|
||||
return g_pBackgroundContext != NULL;
|
||||
}
|
||||
|
||||
class RenderTarget_X11: public RenderTarget
|
||||
{
|
||||
public:
|
||||
RenderTarget_X11( LowLevelWindow_X11 *pWind );
|
||||
~RenderTarget_X11();
|
||||
|
||||
void Create( const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut );
|
||||
unsigned GetTexture() const { return m_iTexHandle; }
|
||||
void StartRenderingTo();
|
||||
void FinishRenderingTo();
|
||||
|
||||
/* Copying from the Pbuffer to the texture flips Y. */
|
||||
virtual bool InvertY() const { return true; }
|
||||
|
||||
private:
|
||||
int m_iWidth, m_iHeight;
|
||||
LowLevelWindow_X11 *m_pWind;
|
||||
GLXPbuffer m_iPbuffer;
|
||||
GLXContext m_pPbufferContext;
|
||||
unsigned int m_iTexHandle;
|
||||
|
||||
GLXContext m_pOldContext;
|
||||
GLXDrawable m_pOldDrawable;
|
||||
};
|
||||
|
||||
RenderTarget_X11::RenderTarget_X11( LowLevelWindow_X11 *pWind )
|
||||
{
|
||||
m_pWind = pWind;
|
||||
m_iPbuffer = 0;
|
||||
m_pPbufferContext = NULL;
|
||||
m_iTexHandle = 0;
|
||||
m_pOldContext = NULL;
|
||||
m_pOldDrawable = 0;
|
||||
}
|
||||
|
||||
RenderTarget_X11::~RenderTarget_X11()
|
||||
{
|
||||
if( m_pPbufferContext )
|
||||
glXDestroyContext( Dpy, m_pPbufferContext );
|
||||
if( m_iPbuffer )
|
||||
glXDestroyPbuffer( Dpy, m_iPbuffer );
|
||||
if( m_iTexHandle )
|
||||
glDeleteTextures( 1, reinterpret_cast<GLuint*>(&m_iTexHandle) );
|
||||
}
|
||||
|
||||
/* Note that although the texture size may need to be a power of 2, the Pbuffer
|
||||
* does not. */
|
||||
void RenderTarget_X11::Create( const RenderTargetParam ¶m, int &iTextureWidthOut, int &iTextureHeightOut )
|
||||
{
|
||||
//ASSERT( param.iWidth == power_of_two(param.iWidth) && param.iHeight == power_of_two(param.iHeight) );
|
||||
|
||||
m_iWidth = param.iWidth;
|
||||
m_iHeight = param.iHeight;
|
||||
|
||||
int pConfigAttribs[] =
|
||||
{
|
||||
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_ALPHA_SIZE, param.bWithAlpha? 8:GLX_DONT_CARE,
|
||||
|
||||
GLX_DOUBLEBUFFER, False,
|
||||
GLX_DEPTH_SIZE, param.bWithDepthBuffer? 16:GLX_DONT_CARE,
|
||||
None
|
||||
};
|
||||
int iConfigs;
|
||||
GLXFBConfig *pConfigs = glXChooseFBConfig( Dpy, DefaultScreen(Dpy), pConfigAttribs, &iConfigs );
|
||||
ASSERT( pConfigs );
|
||||
|
||||
const int pPbufferAttribs[] =
|
||||
{
|
||||
GLX_PBUFFER_WIDTH, param.iWidth,
|
||||
GLX_PBUFFER_HEIGHT, param.iHeight,
|
||||
None
|
||||
};
|
||||
|
||||
for( int i = 0; i < iConfigs; ++i )
|
||||
{
|
||||
m_iPbuffer = glXCreatePbuffer( Dpy, pConfigs[i], pPbufferAttribs );
|
||||
if( m_iPbuffer == 0 )
|
||||
continue;
|
||||
|
||||
XVisualInfo *pVisual = glXGetVisualFromFBConfig( Dpy, pConfigs[i] );
|
||||
m_pPbufferContext = glXCreateContext( Dpy, pVisual, g_pContext, True );
|
||||
ASSERT( m_pPbufferContext );
|
||||
XFree( pVisual );
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT( m_iPbuffer );
|
||||
|
||||
// allocate OpenGL texture resource
|
||||
glGenTextures( 1, reinterpret_cast<GLuint*>(&m_iTexHandle) );
|
||||
glBindTexture( GL_TEXTURE_2D, m_iTexHandle );
|
||||
|
||||
LOG->Trace( "n %i, %ix%i", m_iTexHandle, param.iWidth, param.iHeight );
|
||||
while( glGetError() != GL_NO_ERROR )
|
||||
;
|
||||
|
||||
int iTextureWidth = power_of_two( param.iWidth );
|
||||
int iTextureHeight = power_of_two( param.iHeight );
|
||||
iTextureWidthOut = iTextureWidth;
|
||||
iTextureHeightOut = iTextureHeight;
|
||||
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, param.bWithAlpha? GL_RGBA8:GL_RGB8,
|
||||
iTextureWidth, iTextureHeight, 0, param.bWithAlpha? GL_RGBA:GL_RGB, GL_UNSIGNED_BYTE, NULL );
|
||||
GLenum error = glGetError();
|
||||
ASSERT_M( error == GL_NO_ERROR, GLToString(error) );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
}
|
||||
|
||||
void RenderTarget_X11::StartRenderingTo()
|
||||
{
|
||||
m_pOldContext = glXGetCurrentContext();
|
||||
m_pOldDrawable = glXGetCurrentDrawable();
|
||||
glXMakeCurrent( Dpy, m_iPbuffer, m_pPbufferContext );
|
||||
|
||||
glViewport( 0, 0, m_iWidth, m_iHeight );
|
||||
}
|
||||
|
||||
void RenderTarget_X11::FinishRenderingTo()
|
||||
{
|
||||
glFlush();
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, m_iTexHandle );
|
||||
|
||||
while( glGetError() != GL_NO_ERROR )
|
||||
;
|
||||
|
||||
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_iWidth, m_iHeight );
|
||||
|
||||
GLenum error = glGetError();
|
||||
ASSERT_M( error == GL_NO_ERROR, GLToString(error) );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||
|
||||
glXMakeCurrent( Dpy, m_pOldDrawable, m_pOldContext );
|
||||
m_pOldContext = NULL;
|
||||
m_pOldDrawable = 0;
|
||||
|
||||
}
|
||||
|
||||
bool LowLevelWindow_X11::SupportsRenderToTexture() const
|
||||
{
|
||||
/* Server must support pbuffers: */
|
||||
const int iScreen = DefaultScreen( Dpy );
|
||||
float fVersion = strtof( glXQueryServerString(Dpy, iScreen, GLX_VERSION), NULL );
|
||||
if( fVersion < 1.3f )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderTarget *LowLevelWindow_X11::CreateRenderTarget()
|
||||
{
|
||||
return new RenderTarget_X11( this );
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::BeginConcurrentRenderingMainThread()
|
||||
{
|
||||
/* Move the main thread, which is going to be loading textures, etc. but
|
||||
* not rendering, to an undisplayed window. This results in smoother
|
||||
* rendering. */
|
||||
bool b = glXMakeCurrent( Dpy, g_AltWindow, g_pContext );
|
||||
ASSERT(b);
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::EndConcurrentRenderingMainThread()
|
||||
{
|
||||
bool b = glXMakeCurrent( Dpy, Win, g_pContext );
|
||||
ASSERT(b);
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::BeginConcurrentRendering()
|
||||
{
|
||||
bool b = glXMakeCurrent( Dpy, Win, g_pBackgroundContext );
|
||||
ASSERT(b);
|
||||
}
|
||||
|
||||
void LowLevelWindow_X11::EndConcurrentRendering()
|
||||
{
|
||||
bool b = glXMakeCurrent( Dpy, None, NULL );
|
||||
ASSERT(b);
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2005 Ben Anderson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,70 @@
|
||||
/* LowLevelWindow_X11 - OpenGL GLX window driver. */
|
||||
|
||||
#ifndef LOW_LEVEL_WINDOW_X11_H
|
||||
#define LOW_LEVEL_WINDOW_X11_H
|
||||
|
||||
#include "RageDisplay.h" // VideoModeParams
|
||||
#include "LowLevelWindow.h"
|
||||
|
||||
class LowLevelWindow_X11 : public LowLevelWindow
|
||||
{
|
||||
public:
|
||||
LowLevelWindow_X11();
|
||||
~LowLevelWindow_X11();
|
||||
|
||||
void *GetProcAddress(RString s);
|
||||
RString TryVideoMode(const VideoModeParams &p, bool &bNewDeviceOut);
|
||||
void LogDebugInformation() const;
|
||||
bool IsSoftwareRenderer( RString &sError );
|
||||
void SwapBuffers();
|
||||
|
||||
const VideoModeParams &GetActualVideoModeParams() const { return CurrentParams; }
|
||||
|
||||
void GetDisplayResolutions( DisplayResolutions &out ) const;
|
||||
|
||||
bool SupportsRenderToTexture() const;
|
||||
RenderTarget *CreateRenderTarget();
|
||||
|
||||
bool SupportsThreadedRendering();
|
||||
void BeginConcurrentRenderingMainThread();
|
||||
void EndConcurrentRenderingMainThread();
|
||||
void BeginConcurrentRendering();
|
||||
void EndConcurrentRendering();
|
||||
|
||||
private:
|
||||
bool m_bWasWindowed;
|
||||
VideoModeParams CurrentParams;
|
||||
};
|
||||
|
||||
#ifdef ARCH_LOW_LEVEL_WINDOW
|
||||
#error "More than one LowLevelWindow selected!"
|
||||
#endif
|
||||
#define ARCH_LOW_LEVEL_WINDOW LowLevelWindow_X11
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2005 Ben Anderson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
Reference in New Issue
Block a user