more fixes for retina + glfw + opengl2 fallback
This commit is contained in:
Binary file not shown.
@@ -920,10 +920,16 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
const char* optMode = "Release build";
|
||||
#endif
|
||||
|
||||
#ifdef B3_USE_GLFW
|
||||
const char* glContext = "[glfw]";
|
||||
#else
|
||||
const char* glContext = "[btgl]";
|
||||
#endif
|
||||
|
||||
if (sUseOpenGL2 )
|
||||
{
|
||||
char title[1024];
|
||||
sprintf(title,"%s using limited OpenGL2 fallback. %s", appTitle,optMode);
|
||||
sprintf(title,"%s using limited OpenGL2 fallback %s %s", appTitle,glContext, optMode);
|
||||
s_app = new SimpleOpenGL2App(title,width,height);
|
||||
s_app->m_renderer = new SimpleOpenGL2Renderer(width,height);
|
||||
}
|
||||
@@ -932,7 +938,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
char title[1024];
|
||||
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
|
||||
sprintf(title,"%s using OpenGL3+ %s %s", appTitle,glContext, optMode);
|
||||
simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina);
|
||||
s_app = simpleApp;
|
||||
}
|
||||
@@ -1001,7 +1007,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
|
||||
if (sUseOpenGL2)
|
||||
{
|
||||
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(s_window->getRetinaScale());
|
||||
}
|
||||
#ifndef NO_OPENGL3
|
||||
else
|
||||
@@ -1341,7 +1347,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
if (sUseOpenGL2)
|
||||
{
|
||||
|
||||
saveOpenGLState(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
|
||||
saveOpenGLState(s_instancingRenderer->getScreenWidth()*s_window->getRetinaScale(), s_instancingRenderer->getScreenHeight()*s_window->getRetinaScale());
|
||||
}
|
||||
|
||||
if (m_internalData->m_gui)
|
||||
|
||||
@@ -241,12 +241,14 @@ void GLFWOpenGLWindow::mouseCursorCallbackInternal(double xPos, double yPos)
|
||||
|
||||
void GLFWOpenGLWindow::resizeInternal(int width,int height)
|
||||
{
|
||||
if (getResizeCallback())
|
||||
{
|
||||
getResizeCallback()(width,height);
|
||||
}
|
||||
|
||||
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||
glViewport (0,0,m_data->m_width,m_data->m_height);
|
||||
|
||||
if (getResizeCallback())
|
||||
{
|
||||
getResizeCallback()(m_data->m_width/m_data->m_retinaScaleFactor,m_data->m_height / m_data->m_retinaScaleFactor);
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWOpenGLWindow::createDefaultWindow(int width, int height, const char* title)
|
||||
@@ -272,12 +274,10 @@ void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
||||
|
||||
if (ci.m_openglVersion==2)
|
||||
{
|
||||
printf("V2\n");
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
} else
|
||||
{
|
||||
printf("V3\n");
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
@@ -46,9 +46,9 @@ static void Simple2ResizeCallback( float widthf, float heightf)
|
||||
{
|
||||
int width = (int)widthf;
|
||||
int height = (int)heightf;
|
||||
if (gApp2->m_renderer)
|
||||
gApp2->m_renderer->resize(width,height);
|
||||
//gApp2->m_renderer->setScreenSize(width,height);
|
||||
if (gApp2->m_renderer && gApp2->m_window)
|
||||
gApp2->m_renderer->resize(width,height);//*gApp2->m_window->getRetinaScale(),height*gApp2->m_window->getRetinaScale());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -64,13 +64,20 @@ static void Simple2KeyboardCallback(int key, int state)
|
||||
}
|
||||
|
||||
void Simple2MouseButtonCallback( int button, int state, float x, float y)
|
||||
{
|
||||
if (gApp2 && gApp2->m_window)
|
||||
{
|
||||
gApp2->defaultMouseButtonCallback(button,state,x,y);
|
||||
}
|
||||
}
|
||||
void Simple2MouseMoveCallback( float x, float y)
|
||||
{
|
||||
|
||||
if (gApp2 && gApp2->m_window)
|
||||
{
|
||||
gApp2->defaultMouseMoveCallback(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
void Simple2WheelCallback( float deltax, float deltay)
|
||||
{
|
||||
|
||||
@@ -153,7 +153,9 @@ namespace Gwen
|
||||
{
|
||||
namespace Renderer
|
||||
{
|
||||
OpenGL_DebugFont::OpenGL_DebugFont()
|
||||
|
||||
OpenGL_DebugFont::OpenGL_DebugFont(float retinaScale)
|
||||
:m_retinaScale(retinaScale)
|
||||
{
|
||||
m_iVertNum = 0;
|
||||
|
||||
@@ -260,8 +262,8 @@ namespace Gwen
|
||||
Flush();
|
||||
}
|
||||
|
||||
m_Vertices[ m_iVertNum ].x = (float)x;
|
||||
m_Vertices[ m_iVertNum ].y = (float)y;
|
||||
m_Vertices[ m_iVertNum ].x = (float)x*m_retinaScale;
|
||||
m_Vertices[ m_iVertNum ].y = (float)y*m_retinaScale;
|
||||
m_Vertices[ m_iVertNum ].u = u;
|
||||
m_Vertices[ m_iVertNum ].v = v;
|
||||
|
||||
@@ -306,16 +308,19 @@ namespace Gwen
|
||||
Flush();
|
||||
Gwen::Rect rect = ClipRegion();
|
||||
|
||||
float retinaScale = m_retinaScale;
|
||||
// OpenGL's coords are from the bottom left
|
||||
// so we need to translate them here.
|
||||
{
|
||||
GLint view[4];
|
||||
glGetIntegerv( GL_VIEWPORT, &view[0] );
|
||||
rect.y = view[3] - (rect.y + rect.h);
|
||||
rect.y = view[3]/retinaScale - (rect.y + rect.h);
|
||||
}
|
||||
|
||||
glScissor( rect.x * Scale(), rect.y * Scale(), rect.w * Scale(), rect.h * Scale() );
|
||||
glScissor( retinaScale * rect.x * Scale(), retinaScale * rect.y * Scale(), retinaScale * rect.w * Scale(), retinaScale * rect.h * Scale() );
|
||||
glEnable( GL_SCISSOR_TEST );
|
||||
//glDisable( GL_SCISSOR_TEST );
|
||||
|
||||
};
|
||||
|
||||
void OpenGL_DebugFont::EndClip()
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Gwen
|
||||
|
||||
class OpenGL_DebugFont : public Gwen::Renderer::Base
|
||||
{
|
||||
float m_retinaScale;
|
||||
|
||||
public:
|
||||
|
||||
struct Vertex
|
||||
@@ -33,7 +35,7 @@ namespace Gwen
|
||||
|
||||
static const int MaxVerts = 1024;
|
||||
|
||||
OpenGL_DebugFont();
|
||||
OpenGL_DebugFont(float retinaScale);
|
||||
~OpenGL_DebugFont();
|
||||
|
||||
void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text );
|
||||
|
||||
@@ -1852,6 +1852,7 @@ static void load_GL_VERSION_2_0(GLADloadproc load) {
|
||||
glad_glVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC)load("glVertexAttrib4uiv");
|
||||
glad_glVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC)load("glVertexAttrib4usv");
|
||||
glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)load("glVertexAttribPointer");
|
||||
glad_glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)load("glGenerateMipmap");
|
||||
}
|
||||
static void load_GL_VERSION_2_1(GLADloadproc load) {
|
||||
if(!GLAD_GL_VERSION_2_1) return;
|
||||
@@ -1938,7 +1939,7 @@ static void load_GL_VERSION_3_0(GLADloadproc load) {
|
||||
glad_glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)load("glFramebufferTexture3D");
|
||||
glad_glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)load("glFramebufferRenderbuffer");
|
||||
glad_glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)load("glGetFramebufferAttachmentParameteriv");
|
||||
glad_glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)load("glGenerateMipmap");
|
||||
|
||||
glad_glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)load("glBlitFramebuffer");
|
||||
glad_glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)load("glRenderbufferStorageMultisample");
|
||||
glad_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)load("glFramebufferTextureLayer");
|
||||
|
||||
@@ -345,10 +345,12 @@ int main()
|
||||
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
|
||||
}
|
||||
window->setWindowTitle(title);
|
||||
|
||||
float retinaScale = window->getRetinaScale();
|
||||
|
||||
#ifndef NO_OPENGL3
|
||||
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
||||
{
|
||||
float retinaScale = 1.f;
|
||||
#ifndef B3_USE_GLFW
|
||||
#ifndef __APPLE__
|
||||
#ifndef _WIN32
|
||||
@@ -365,8 +367,6 @@ int main()
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
retinaScale = window->getRetinaScale();
|
||||
|
||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
|
||||
sth_stash* font = initFont(primRenderer );
|
||||
@@ -378,7 +378,7 @@ int main()
|
||||
#endif
|
||||
{
|
||||
//OpenGL 2.x
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(retinaScale);
|
||||
|
||||
|
||||
skin.SetRender( gwenRenderer );
|
||||
|
||||
Reference in New Issue
Block a user