Cocoa Port: Simplify OpenGL context handling.

This commit is contained in:
rogerman 2017-01-09 13:57:59 -08:00
parent 91f2bb9ee5
commit 34656d977c
9 changed files with 119 additions and 93 deletions

View File

@ -4281,11 +4281,6 @@ void GetGLVersionOGL(GLint *outMajor, GLint *outMinor, GLint *outRevision)
} }
} }
OGLInfo* OGLInfoCreate_Legacy()
{
return new OGLInfo_Legacy;
}
void glBindVertexArray_LegacyAPPLE(GLuint vaoID) void glBindVertexArray_LegacyAPPLE(GLuint vaoID)
{ {
glBindVertexArrayAPPLE(vaoID); glBindVertexArrayAPPLE(vaoID);
@ -4301,7 +4296,6 @@ void glGenVertexArrays_LegacyAPPLE(GLsizei n, GLuint *vaoIDs)
glGenVertexArraysAPPLE(n, vaoIDs); glGenVertexArraysAPPLE(n, vaoIDs);
} }
OGLInfo* (*OGLInfoCreate_Func)() = &OGLInfoCreate_Legacy;
void (*glBindVertexArrayDESMUME)(GLuint id) = &glBindVertexArray_LegacyAPPLE; void (*glBindVertexArrayDESMUME)(GLuint id) = &glBindVertexArray_LegacyAPPLE;
void (*glDeleteVertexArraysDESMUME)(GLsizei n, const GLuint *ids) = &glDeleteVertexArrays_LegacyAPPLE; void (*glDeleteVertexArraysDESMUME)(GLsizei n, const GLuint *ids) = &glDeleteVertexArrays_LegacyAPPLE;
void (*glGenVertexArraysDESMUME)(GLsizei n, GLuint *ids) = &glGenVertexArrays_LegacyAPPLE; void (*glGenVertexArraysDESMUME)(GLsizei n, GLuint *ids) = &glGenVertexArrays_LegacyAPPLE;
@ -4452,7 +4446,7 @@ static void InitHQnxLUTs()
#pragma mark - #pragma mark -
OGLInfo::OGLInfo() OGLContextInfo::OGLContextInfo()
{ {
GetGLVersionOGL(&_versionMajor, &_versionMinor, &_versionRevision); GetGLVersionOGL(&_versionMajor, &_versionMinor, &_versionRevision);
_shaderSupport = ShaderSupport_Unsupported; _shaderSupport = ShaderSupport_Unsupported;
@ -4464,42 +4458,42 @@ OGLInfo::OGLInfo()
_isFBOSupported = false; _isFBOSupported = false;
} }
ShaderSupportTier OGLInfo::GetShaderSupport() ShaderSupportTier OGLContextInfo::GetShaderSupport()
{ {
return this->_shaderSupport; return this->_shaderSupport;
} }
bool OGLInfo::IsUsingShader150() bool OGLContextInfo::IsUsingShader150()
{ {
return this->_useShader150; return this->_useShader150;
} }
bool OGLInfo::IsVBOSupported() bool OGLContextInfo::IsVBOSupported()
{ {
return this->_isVBOSupported; return this->_isVBOSupported;
} }
bool OGLInfo::IsVAOSupported() bool OGLContextInfo::IsVAOSupported()
{ {
return this->_isVAOSupported; return this->_isVAOSupported;
} }
bool OGLInfo::IsPBOSupported() bool OGLContextInfo::IsPBOSupported()
{ {
return this->_isPBOSupported; return this->_isPBOSupported;
} }
bool OGLInfo::IsShaderSupported() bool OGLContextInfo::IsShaderSupported()
{ {
return (this->_shaderSupport != ShaderSupport_Unsupported); return (this->_shaderSupport != ShaderSupport_Unsupported);
} }
bool OGLInfo::IsFBOSupported() bool OGLContextInfo::IsFBOSupported()
{ {
return this->_isFBOSupported; return this->_isFBOSupported;
} }
OGLInfo_Legacy::OGLInfo_Legacy() OGLContextInfo_Legacy::OGLContextInfo_Legacy()
{ {
_shaderSupport = ShaderSupport_Unsupported; _shaderSupport = ShaderSupport_Unsupported;
_useShader150 = false; _useShader150 = false;
@ -4595,7 +4589,7 @@ OGLInfo_Legacy::OGLInfo_Legacy()
_isFBOSupported = this->IsExtensionPresent(oglExtensionSet, "GL_EXT_framebuffer_object"); _isFBOSupported = this->IsExtensionPresent(oglExtensionSet, "GL_EXT_framebuffer_object");
} }
void OGLInfo_Legacy::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet) void OGLContextInfo_Legacy::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet)
{ {
std::string oglExtensionString = std::string((const char *)glGetString(GL_EXTENSIONS)); std::string oglExtensionString = std::string((const char *)glGetString(GL_EXTENSIONS));
@ -4617,7 +4611,7 @@ void OGLInfo_Legacy::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet)
} }
} }
bool OGLInfo_Legacy::IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const bool OGLContextInfo_Legacy::IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const
{ {
if (oglExtensionSet.size() == 0) if (oglExtensionSet.size() == 0)
{ {
@ -4910,6 +4904,7 @@ bool OGLShaderProgram::LinkOGL()
OGLVideoOutput::OGLVideoOutput() OGLVideoOutput::OGLVideoOutput()
{ {
_contextInfo = NULL;
_needUpdateViewport = true; _needUpdateViewport = true;
_layerList = new std::vector<OGLVideoLayer *>; _layerList = new std::vector<OGLVideoLayer *>;
_layerList->reserve(8); _layerList->reserve(8);
@ -4927,9 +4922,6 @@ OGLVideoOutput::~OGLVideoOutput()
delete this->_layerList; delete this->_layerList;
this->_layerList = NULL; this->_layerList = NULL;
} }
delete this->_info;
this->_info = NULL;
} }
void OGLVideoOutput::_UpdateNormalSize() void OGLVideoOutput::_UpdateNormalSize()
@ -4979,15 +4971,14 @@ void OGLVideoOutput::_UpdateViewport()
this->_needUpdateViewport = false; this->_needUpdateViewport = false;
} }
OGLInfo* OGLVideoOutput::GetInfo() OGLContextInfo* OGLVideoOutput::GetContextInfo()
{ {
return this->_info; return this->_contextInfo;
} }
void OGLVideoOutput::Init() void OGLVideoOutput::Init()
{ {
this->_info = OGLInfoCreate_Func(); this->_canFilterOnGPU = ( this->_contextInfo->IsShaderSupported() && this->_contextInfo->IsFBOSupported() );
this->_canFilterOnGPU = ( this->_info->IsShaderSupported() && this->_info->IsFBOSupported() );
this->_filtersPreferGPU = this->_canFilterOnGPU; this->_filtersPreferGPU = this->_canFilterOnGPU;
this->_willFilterOnGPU = false; this->_willFilterOnGPU = false;
@ -5009,7 +5000,7 @@ void OGLVideoOutput::Init()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Set up fixed-function pipeline render states. // Set up fixed-function pipeline render states.
if (!this->_info->IsShaderSupported()) if (!this->_contextInfo->IsShaderSupported())
{ {
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
@ -5427,7 +5418,7 @@ GLuint OGLFilterDeposterize::RunFilterOGL(GLuint srcTexID)
#pragma mark - #pragma mark -
OGLImage::OGLImage(OGLInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GLsizei viewportWidth, GLsizei viewportHeight) OGLImage::OGLImage(OGLContextInfo *contextInfo, GLsizei imageWidth, GLsizei imageHeight, GLsizei viewportWidth, GLsizei viewportHeight)
{ {
_needUploadVertices = true; _needUploadVertices = true;
_useDeposterize = false; _useDeposterize = false;
@ -5483,7 +5474,7 @@ OGLImage::OGLImage(OGLInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GL
glGenVertexArraysDESMUME(1, &_vaoMainStatesID); glGenVertexArraysDESMUME(1, &_vaoMainStatesID);
glBindVertexArrayDESMUME(_vaoMainStatesID); glBindVertexArrayDESMUME(_vaoMainStatesID);
if (oglInfo->IsShaderSupported()) if (contextInfo->IsShaderSupported())
{ {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID); glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_INT, GL_FALSE, 0, 0); glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_INT, GL_FALSE, 0, 0);
@ -5508,10 +5499,10 @@ OGLImage::OGLImage(OGLInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GL
_isVAOPresent = true; _isVAOPresent = true;
_pixelScaler = VideoFilterTypeID_None; _pixelScaler = VideoFilterTypeID_None;
_useShader150 = oglInfo->IsUsingShader150(); _useShader150 = contextInfo->IsUsingShader150();
_shaderSupport = oglInfo->GetShaderSupport(); _shaderSupport = contextInfo->GetShaderSupport();
_canUseShaderOutput = oglInfo->IsShaderSupported(); _canUseShaderOutput = contextInfo->IsShaderSupported();
if (_canUseShaderOutput) if (_canUseShaderOutput)
{ {
_finalOutputProgram = new OGLShaderProgram; _finalOutputProgram = new OGLShaderProgram;
@ -5530,7 +5521,7 @@ OGLImage::OGLImage(OGLInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GL
_finalOutputProgram = NULL; _finalOutputProgram = NULL;
} }
_canUseShaderBasedFilters = (oglInfo->IsShaderSupported() && oglInfo->IsFBOSupported()); _canUseShaderBasedFilters = (contextInfo->IsShaderSupported() && contextInfo->IsFBOSupported());
if (_canUseShaderBasedFilters) if (_canUseShaderBasedFilters)
{ {
_filterDeposterize = new OGLFilterDeposterize(_vf->GetSrcWidth(), _vf->GetSrcHeight(), _shaderSupport, _useShader150); _filterDeposterize = new OGLFilterDeposterize(_vf->GetSrcWidth(), _vf->GetSrcHeight(), _shaderSupport, _useShader150);
@ -6252,11 +6243,11 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO)
_glyphSize = 0.0f; _glyphSize = 0.0f;
_glyphTileSize = 0.0f; _glyphTileSize = 0.0f;
if (_output->GetInfo()->IsShaderSupported()) if (_output->GetContextInfo()->IsShaderSupported())
{ {
_program = new OGLShaderProgram; _program = new OGLShaderProgram;
_program->SetShaderSupport(oglVO->GetInfo()->GetShaderSupport()); _program->SetShaderSupport(oglVO->GetContextInfo()->GetShaderSupport());
_program->SetVertexAndFragmentShaderOGL(HUDOutputVertShader_100, HUDOutputFragShader_110, oglVO->GetInfo()->IsUsingShader150()); _program->SetVertexAndFragmentShaderOGL(HUDOutputVertShader_100, HUDOutputFragShader_110, oglVO->GetContextInfo()->IsUsingShader150());
glUseProgram(_program->GetProgramID()); glUseProgram(_program->GetProgramID());
_uniformViewSize = glGetUniformLocation(_program->GetProgramID(), "viewSize"); _uniformViewSize = glGetUniformLocation(_program->GetProgramID(), "viewSize");
@ -6301,7 +6292,7 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO)
glGenVertexArraysDESMUME(1, &_vaoMainStatesID); glGenVertexArraysDESMUME(1, &_vaoMainStatesID);
glBindVertexArrayDESMUME(_vaoMainStatesID); glBindVertexArrayDESMUME(_vaoMainStatesID);
if (oglVO->GetInfo()->IsShaderSupported()) if (oglVO->GetContextInfo()->IsShaderSupported())
{ {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID); glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, NULL); glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, NULL);
@ -6329,7 +6320,7 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO)
OGLHUDLayer::~OGLHUDLayer() OGLHUDLayer::~OGLHUDLayer()
{ {
if (_output->GetInfo()->IsShaderSupported()) if (_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(0); glUseProgram(0);
delete this->_program; delete this->_program;
@ -6455,7 +6446,7 @@ void OGLHUDLayer::_UpdateVerticesOGL()
void OGLHUDLayer::UpdateViewportOGL() void OGLHUDLayer::UpdateViewportOGL()
{ {
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(this->_program->GetProgramID()); glUseProgram(this->_program->GetProgramID());
glUniform2f(this->_uniformViewSize, this->_output->GetViewProperties().clientWidth, this->_output->GetViewProperties().clientHeight); glUniform2f(this->_uniformViewSize, this->_output->GetViewProperties().clientWidth, this->_output->GetViewProperties().clientHeight);
@ -6492,7 +6483,7 @@ void OGLHUDLayer::RenderOGL()
return; return;
} }
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(this->_program->GetProgramID()); glUseProgram(this->_program->GetProgramID());
} }
@ -6634,7 +6625,7 @@ OGLDisplayLayer::OGLDisplayLayer(OGLVideoOutput *oglVO)
glGenVertexArraysDESMUME(1, &this->_vaoMainStatesID); glGenVertexArraysDESMUME(1, &this->_vaoMainStatesID);
glBindVertexArrayDESMUME(this->_vaoMainStatesID); glBindVertexArrayDESMUME(this->_vaoMainStatesID);
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID); glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
@ -6657,9 +6648,9 @@ OGLDisplayLayer::OGLDisplayLayer(OGLVideoOutput *oglVO)
glBindVertexArrayDESMUME(0); glBindVertexArrayDESMUME(0);
_useShader150 = _output->GetInfo()->IsUsingShader150(); _useShader150 = _output->GetContextInfo()->IsUsingShader150();
_shaderSupport = _output->GetInfo()->GetShaderSupport(); _shaderSupport = _output->GetContextInfo()->GetShaderSupport();
if (_output->GetInfo()->IsShaderSupported()) if (_output->GetContextInfo()->IsShaderSupported())
{ {
_finalOutputProgram = new OGLShaderProgram; _finalOutputProgram = new OGLShaderProgram;
_finalOutputProgram->SetShaderSupport(_shaderSupport); _finalOutputProgram->SetShaderSupport(_shaderSupport);
@ -6702,7 +6693,7 @@ OGLDisplayLayer::OGLDisplayLayer(OGLVideoOutput *oglVO)
OGLDisplayLayer::~OGLDisplayLayer() OGLDisplayLayer::~OGLDisplayLayer()
{ {
if (_output->GetInfo()->IsVAOSupported()) if (_output->GetContextInfo()->IsVAOSupported())
{ {
glDeleteVertexArraysDESMUME(1, &this->_vaoMainStatesID); glDeleteVertexArraysDESMUME(1, &this->_vaoMainStatesID);
} }
@ -6721,7 +6712,7 @@ OGLDisplayLayer::~OGLDisplayLayer()
glDeleteTextures(1, &this->_texHQ4xLUT); glDeleteTextures(1, &this->_texHQ4xLUT);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
if (_output->GetInfo()->IsShaderSupported()) if (_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(0); glUseProgram(0);
delete this->_finalOutputProgram; delete this->_finalOutputProgram;
@ -6906,7 +6897,7 @@ void OGLDisplayLayer::_UpdateRotationScaleOGL()
const double r = cdv.rotation; const double r = cdv.rotation;
const double s = cdv.viewScale; const double s = cdv.viewScale;
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glUniform1f(this->_uniformFinalOutputAngleDegrees, r); glUniform1f(this->_uniformFinalOutputAngleDegrees, r);
glUniform1f(this->_uniformFinalOutputScalar, s); glUniform1f(this->_uniformFinalOutputScalar, s);
@ -7461,7 +7452,7 @@ void OGLDisplayLayer::UpdateViewportOGL()
const double w = cdv.clientWidth; const double w = cdv.clientWidth;
const double h = cdv.clientHeight; const double h = cdv.clientHeight;
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(this->_finalOutputProgram->GetProgramID()); glUseProgram(this->_finalOutputProgram->GetProgramID());
glUniform2f(this->_uniformFinalOutputViewSize, w, h); glUniform2f(this->_uniformFinalOutputViewSize, w, h);
@ -7598,7 +7589,7 @@ void OGLDisplayLayer::ProcessOGL()
void OGLDisplayLayer::RenderOGL() void OGLDisplayLayer::RenderOGL()
{ {
if (this->_output->GetInfo()->IsShaderSupported()) if (this->_output->GetContextInfo()->IsShaderSupported())
{ {
glUseProgram(this->_finalOutputProgram->GetProgramID()); glUseProgram(this->_finalOutputProgram->GetProgramID());
} }

View File

@ -50,7 +50,7 @@ enum ShaderSupportTier
ShaderSupport_FutureTier = 6, ShaderSupport_FutureTier = 6,
}; };
class OGLInfo class OGLContextInfo
{ {
protected: protected:
GLint _versionMajor; GLint _versionMajor;
@ -65,8 +65,8 @@ protected:
bool _isFBOSupported; bool _isFBOSupported;
public: public:
OGLInfo(); OGLContextInfo();
virtual ~OGLInfo() {}; virtual ~OGLContextInfo() {};
bool IsUsingShader150(); bool IsUsingShader150();
bool IsVBOSupported(); bool IsVBOSupported();
@ -80,10 +80,10 @@ public:
virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const = 0; virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const = 0;
}; };
class OGLInfo_Legacy : public OGLInfo class OGLContextInfo_Legacy : public OGLContextInfo
{ {
public: public:
OGLInfo_Legacy(); OGLContextInfo_Legacy();
virtual void GetExtensionSetOGL(std::set<std::string> *oglExtensionSet); virtual void GetExtensionSetOGL(std::set<std::string> *oglExtensionSet);
virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const; virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const;
@ -229,7 +229,7 @@ protected:
public: public:
OGLImage() {}; OGLImage() {};
OGLImage(OGLInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GLsizei viewportWidth, GLsizei viewportHeight); OGLImage(OGLContextInfo *oglInfo, GLsizei imageWidth, GLsizei imageHeight, GLsizei viewportWidth, GLsizei viewportHeight);
virtual ~OGLImage(); virtual ~OGLImage();
bool GetFiltersPreferGPU(); bool GetFiltersPreferGPU();
@ -388,7 +388,7 @@ public:
class OGLVideoOutput : public ClientDisplay3DView class OGLVideoOutput : public ClientDisplay3DView
{ {
protected: protected:
OGLInfo *_info; OGLContextInfo *_contextInfo;
GLsizei _viewportWidth; GLsizei _viewportWidth;
GLsizei _viewportHeight; GLsizei _viewportHeight;
bool _needUpdateViewport; bool _needUpdateViewport;
@ -406,7 +406,7 @@ public:
OGLVideoOutput(); OGLVideoOutput();
~OGLVideoOutput(); ~OGLVideoOutput();
OGLInfo* GetInfo(); OGLContextInfo* GetContextInfo();
GLsizei GetViewportWidth(); GLsizei GetViewportWidth();
GLsizei GetViewportHeight(); GLsizei GetViewportHeight();
@ -437,9 +437,6 @@ public:
virtual void FrameFinish(); virtual void FrameFinish();
}; };
OGLInfo* OGLInfoCreate_Legacy();
extern OGLInfo* (*OGLInfoCreate_Func)();
extern void (*glBindVertexArrayDESMUME)(GLuint id); extern void (*glBindVertexArrayDESMUME)(GLuint id);
extern void (*glDeleteVertexArraysDESMUME)(GLsizei n, const GLuint *ids); extern void (*glDeleteVertexArraysDESMUME)(GLsizei n, const GLuint *ids);
extern void (*glGenVertexArraysDESMUME)(GLsizei n, GLuint *ids); extern void (*glGenVertexArraysDESMUME)(GLsizei n, GLuint *ids);

View File

@ -23,11 +23,6 @@ enum OGLVertexAttributeID
OGLVertexAttributeID_TexCoord0 = 8 OGLVertexAttributeID_TexCoord0 = 8
}; };
OGLInfo* OGLInfoCreate_3_2()
{
return new OGLInfo_3_2;
}
void glBindVertexArray_3_2(GLuint vaoID) void glBindVertexArray_3_2(GLuint vaoID)
{ {
glBindVertexArray(vaoID); glBindVertexArray(vaoID);
@ -43,7 +38,7 @@ void glGenVertexArrays_3_2(GLsizei n, GLuint *vaoIDs)
glGenVertexArrays(n, vaoIDs); glGenVertexArrays(n, vaoIDs);
} }
OGLInfo_3_2::OGLInfo_3_2() OGLContextInfo_3_2::OGLContextInfo_3_2()
{ {
_useShader150 = true; _useShader150 = true;
_isVBOSupported = true; _isVBOSupported = true;
@ -70,7 +65,7 @@ OGLInfo_3_2::OGLInfo_3_2()
} }
} }
void OGLInfo_3_2::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet) void OGLContextInfo_3_2::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet)
{ {
GLint extensionCount = 0; GLint extensionCount = 0;
@ -82,7 +77,7 @@ void OGLInfo_3_2::GetExtensionSetOGL(std::set<std::string> *oglExtensionSet)
} }
} }
bool OGLInfo_3_2::IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const bool OGLContextInfo_3_2::IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const
{ {
if (oglExtensionSet.size() == 0) if (oglExtensionSet.size() == 0)
{ {

View File

@ -26,15 +26,13 @@
#include "OGLDisplayOutput.h" #include "OGLDisplayOutput.h"
class OGLInfo_3_2 : public OGLInfo class OGLContextInfo_3_2 : public OGLContextInfo
{ {
public: public:
OGLInfo_3_2(); OGLContextInfo_3_2();
virtual void GetExtensionSetOGL(std::set<std::string> *oglExtensionSet); virtual void GetExtensionSetOGL(std::set<std::string> *oglExtensionSet);
virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const; virtual bool IsExtensionPresent(const std::set<std::string> &oglExtensionSet, const std::string &extensionName) const;
}; };
OGLInfo* OGLInfoCreate_3_2();
#endif #endif

View File

@ -61,6 +61,7 @@ class OGLVideoOutput;
@property (assign) NSInteger outputFilter; @property (assign) NSInteger outputFilter;
@property (assign) NSInteger pixelScaler; @property (assign) NSInteger pixelScaler;
- (void) initContext;
- (BOOL) handleKeyPress:(NSEvent *)theEvent keyPressed:(BOOL)keyPressed; - (BOOL) handleKeyPress:(NSEvent *)theEvent keyPressed:(BOOL)keyPressed;
- (BOOL) handleMouseButton:(NSEvent *)theEvent buttonPressed:(BOOL)buttonPressed; - (BOOL) handleMouseButton:(NSEvent *)theEvent buttonPressed:(BOOL)buttonPressed;
- (void) requestScreenshot:(NSURL *)fileURL fileType:(NSBitmapImageFileType)fileType; - (void) requestScreenshot:(NSURL *)fileURL fileType:(NSBitmapImageFileType)fileType;

View File

@ -1261,10 +1261,12 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
[self setMasterWindow:[self window]]; [self setMasterWindow:[self window]];
[masterWindow setTitle:(NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]]; [masterWindow setTitle:(NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
[masterWindow setInitialFirstResponder:view]; [masterWindow setInitialFirstResponder:view];
[view setInputManager:[emuControl inputManager]];
[[emuControl windowList] addObject:self]; [[emuControl windowList] addObject:self];
[emuControl updateAllWindowTitles]; [emuControl updateAllWindowTitles];
[view initContext];
[view setInputManager:[emuControl inputManager]];
// Set up the scaling factor if this is a Retina window // Set up the scaling factor if this is a Retina window
float scaleFactor = 1.0f; float scaleFactor = 1.0f;
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) #if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
@ -1609,11 +1611,6 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
cdsVideoOutput = nil; cdsVideoOutput = nil;
_cdv = new MacOGLDisplayView(); _cdv = new MacOGLDisplayView();
_cdv->Init();
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
_cdv->SetHUDFontUsingPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
localContext = [[NSOpenGLContext alloc] initWithCGLContextObj:((MacOGLDisplayView *)_cdv)->GetContext()]; localContext = [[NSOpenGLContext alloc] initWithCGLContextObj:((MacOGLDisplayView *)_cdv)->GetContext()];
return self; return self;
@ -1763,6 +1760,16 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
return [[self cdsVideoOutput] pixelScaler]; return [[self cdsVideoOutput] pixelScaler];
} }
#pragma mark Class Methods
- (void) initContext
{
[localContext setView:self];
_cdv->Init();
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
_cdv->SetHUDFontUsingPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
}
#pragma mark InputHIDManagerTarget Protocol #pragma mark InputHIDManagerTarget Protocol
- (BOOL) handleHIDQueue:(IOHIDQueueRef)hidQueue hidManager:(InputHIDManager *)hidManager - (BOOL) handleHIDQueue:(IOHIDQueueRef)hidQueue hidManager:(InputHIDManager *)hidManager
{ {

View File

@ -36,6 +36,7 @@ protected:
public: public:
void operator delete(void *ptr); void operator delete(void *ptr);
MacOGLDisplayView();
virtual void Init(); virtual void Init();

View File

@ -21,18 +21,24 @@
void MacOGLDisplayView::operator delete(void *ptr) void MacOGLDisplayView::operator delete(void *ptr)
{ {
CGLContextObj context = ((MacOGLDisplayView *)ptr)->GetContext(); CGLContextObj context = ((MacOGLDisplayView *)ptr)->GetContext();
OGLContextInfo *contextInfo = ((MacOGLDisplayView *)ptr)->GetContextInfo();
CGLContextObj prevContext = CGLGetCurrentContext(); if (context != NULL)
CGLSetCurrentContext(context); {
::operator delete(ptr); CGLContextObj prevContext = CGLGetCurrentContext();
CGLSetCurrentContext(prevContext); CGLSetCurrentContext(context);
::operator delete(ptr);
CGLReleaseContext(context); CGLSetCurrentContext(prevContext);
delete contextInfo;
CGLReleaseContext(context);
}
} }
void MacOGLDisplayView::Init() MacOGLDisplayView::MacOGLDisplayView()
{ {
// Initialize the OpenGL context // Initialize the OpenGL context
bool useContext_3_2 = false;
CGLPixelFormatAttribute attributes[] = { CGLPixelFormatAttribute attributes[] = {
kCGLPFAColorSize, (CGLPixelFormatAttribute)24, kCGLPFAColorSize, (CGLPixelFormatAttribute)24,
kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8,
@ -42,16 +48,14 @@ void MacOGLDisplayView::Init()
(CGLPixelFormatAttribute)0, (CGLPixelFormatAttribute)0, (CGLPixelFormatAttribute)0, (CGLPixelFormatAttribute)0,
(CGLPixelFormatAttribute)0 }; (CGLPixelFormatAttribute)0 };
OGLInfoCreate_Func = &OGLInfoCreate_Legacy;
#ifdef _OGLDISPLAYOUTPUT_3_2_H_ #ifdef _OGLDISPLAYOUTPUT_3_2_H_
// If we can support a 3.2 Core Profile context, then request that in our // If we can support a 3.2 Core Profile context, then request that in our
// pixel format attributes. // pixel format attributes.
if (IsOSXVersionSupported(10, 7, 0)) useContext_3_2 = IsOSXVersionSupported(10, 70, 0);
if (useContext_3_2)
{ {
attributes[9] = kCGLPFAOpenGLProfile; attributes[9] = kCGLPFAOpenGLProfile;
attributes[10] = (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core; attributes[10] = (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core;
OGLInfoCreate_Func = &OGLInfoCreate_3_2;
} }
#endif #endif
@ -63,9 +67,9 @@ void MacOGLDisplayView::Init()
{ {
// If we can't get a 3.2 Core Profile context, then switch to using a // If we can't get a 3.2 Core Profile context, then switch to using a
// legacy context instead. // legacy context instead.
useContext_3_2 = false;
attributes[9] = (CGLPixelFormatAttribute)0; attributes[9] = (CGLPixelFormatAttribute)0;
attributes[10] = (CGLPixelFormatAttribute)0; attributes[10] = (CGLPixelFormatAttribute)0;
OGLInfoCreate_Func = &OGLInfoCreate_Legacy;
CGLChoosePixelFormat(attributes, &cglPixFormat, &virtualScreenCount); CGLChoosePixelFormat(attributes, &cglPixFormat, &virtualScreenCount);
} }
@ -74,6 +78,25 @@ void MacOGLDisplayView::Init()
CGLContextObj prevContext = CGLGetCurrentContext(); CGLContextObj prevContext = CGLGetCurrentContext();
CGLSetCurrentContext(this->_context); CGLSetCurrentContext(this->_context);
#ifdef _OGLDISPLAYOUTPUT_3_2_H_
if (useContext_3_2)
{
this->_contextInfo = new OGLContextInfo_3_2;
}
else
#endif
{
this->_contextInfo = new OGLContextInfo_Legacy;
}
CGLSetCurrentContext(prevContext);
}
void MacOGLDisplayView::Init()
{
CGLContextObj prevContext = CGLGetCurrentContext();
CGLSetCurrentContext(this->_context);
this->OGLVideoOutput::Init(); this->OGLVideoOutput::Init();
CGLSetCurrentContext(prevContext); CGLSetCurrentContext(prevContext);
} }

View File

@ -60,6 +60,7 @@
isPreviewImageLoaded = false; isPreviewImageLoaded = false;
// Initialize the OpenGL context // Initialize the OpenGL context
bool useContext_3_2 = false;
NSOpenGLPixelFormatAttribute attributes[] = { NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24, NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8, NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
@ -71,11 +72,11 @@
#ifdef _OGLDISPLAYOUTPUT_3_2_H_ #ifdef _OGLDISPLAYOUTPUT_3_2_H_
// If we can support a 3.2 Core Profile context, then request that in our // If we can support a 3.2 Core Profile context, then request that in our
// pixel format attributes. // pixel format attributes.
if (IsOSXVersionSupported(10, 7, 0)) useContext_3_2 = IsOSXVersionSupported(10, 7, 0);
if (useContext_3_2)
{ {
attributes[8] = NSOpenGLPFAOpenGLProfile; attributes[8] = NSOpenGLPFAOpenGLProfile;
attributes[9] = NSOpenGLProfileVersion3_2Core; attributes[9] = NSOpenGLProfileVersion3_2Core;
OGLInfoCreate_Func = &OGLInfoCreate_3_2;
} }
#endif #endif
@ -84,9 +85,9 @@
{ {
// If we can't get a 3.2 Core Profile context, then switch to using a // If we can't get a 3.2 Core Profile context, then switch to using a
// legacy context instead. // legacy context instead.
useContext_3_2 = false;
attributes[8] = (NSOpenGLPixelFormatAttribute)0; attributes[8] = (NSOpenGLPixelFormatAttribute)0;
attributes[9] = (NSOpenGLPixelFormatAttribute)0; attributes[9] = (NSOpenGLPixelFormatAttribute)0;
OGLInfoCreate_Func = &OGLInfoCreate_Legacy;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
} }
@ -103,8 +104,20 @@
const NSRect newViewportRect = frameRect; const NSRect newViewportRect = frameRect;
#endif #endif
OGLInfo *oglInfo = OGLInfoCreate_Func(); OGLContextInfo *contextInfo = NULL;
oglImage = new OGLImage(oglInfo, 64, 64, newViewportRect.size.width, newViewportRect.size.height);
#ifdef _OGLDISPLAYOUTPUT_3_2_H_
if (useContext_3_2)
{
contextInfo = new OGLContextInfo_3_2;
}
else
#endif
{
contextInfo = new OGLContextInfo_Legacy;
}
oglImage = new OGLImage(contextInfo, 64, 64, newViewportRect.size.width, newViewportRect.size.height);
oglImage->SetFiltersPreferGPUOGL(true); oglImage->SetFiltersPreferGPUOGL(true);
oglImage->SetSourceDeposterize(false); oglImage->SetSourceDeposterize(false);
oglImage->SetOutputFilterOGL(OutputFilterTypeID_Bilinear); oglImage->SetOutputFilterOGL(OutputFilterTypeID_Bilinear);