Merge of GL-AutoChoose.

This branch is the final step of fully supporting both OpenGL and OpenGL ES in the same binary.
This of course only applies to EGL and won't work for GLX/AGL/WGL since they don't really support GL ES.
The changes here actually aren't too terrible, basically change every #ifdef USE_GLES to a runtime check.

This adds a DetectMode() function to the EGL context backend.
EGL will iterate through each of the configs and check for GL, GLES3_KHR, and GLES2 bits
After that it'll change the mode from _DETECT to whichever one is the best supported.
After that point we'll just create a context with the mode that was detected
This commit is contained in:
Ryan Houdek 2014-01-18 04:11:59 +00:00
parent 0a5bd83af2
commit 839df31347
17 changed files with 189 additions and 177 deletions

View file

@ -7,8 +7,6 @@ option(ANDROID "Enables a build for Android" OFF)
option(USE_EGL "Enables EGL OpenGL Interface" OFF) option(USE_EGL "Enables EGL OpenGL Interface" OFF)
option(USE_X11 "Enables X11 Support" ON) option(USE_X11 "Enables X11 Support" ON)
option(USE_WAYLAND "Enables Wayland Support" OFF) option(USE_WAYLAND "Enables Wayland Support" OFF)
option(USE_GLES "Enables GLES2 And EGL, disables OGL" OFF)
option(USE_GLES3 "Enables GLES3 and EGL" OFF)
option(USE_UPNP "Enables UPnP port mapping support" ON) option(USE_UPNP "Enables UPnP port mapping support" ON)
option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF) option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF)
option(ENABLE_PCH "Use PCH to speed up compilation" ON) option(ENABLE_PCH "Use PCH to speed up compilation" ON)
@ -125,8 +123,6 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
if(${ANDROID_NDK_ABI_NAME} MATCHES "armeabi-v7a") if(${ANDROID_NDK_ABI_NAME} MATCHES "armeabi-v7a")
add_definitions(-marm -march=armv7-a) add_definitions(-marm -march=armv7-a)
endif() endif()
# Set generic options so you don't have to pass anything to cmake to build ARM
set(USE_GLES 1)
endif() endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips") if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
@ -290,27 +286,12 @@ if(ANDROID)
set(USE_X11 0) set(USE_X11 0)
set(USE_WAYLAND 0) set(USE_WAYLAND 0)
set(USE_UPNP 0) set(USE_UPNP 0)
set(USE_GLES3 1) set(USE_EGL True)
add_definitions(-DUSE_EGL=1)
endif() endif()
include_directories(Externals/GL) include_directories(Externals/GL)
# For now GLES and EGL are tied to each other.
# Enabling GLES also disables the OpenGL plugin.
if(USE_GLES3)
message("GLES3 rendering enabled")
add_definitions(-DUSE_GLES=1 -DUSE_EGL=1 -DUSE_GLES3=1)
include_directories(Externals/GLES3)
set(USE_EGL True)
set(USE_GLES True)
else()
if(USE_GLES)
message("GLES2 rendering enabled. OpenGL disabled")
add_definitions(-DUSE_GLES=1)
add_definitions(-DUSE_EGL=1)
set(USE_EGL True)
endif()
endif()
# For now Wayland and EGL are tied to each other. # For now Wayland and EGL are tied to each other.
# The alternative would be an shm path # The alternative would be an shm path
if(USE_WAYLAND) if(USE_WAYLAND)
@ -352,11 +333,8 @@ endif()
if(NOT ANDROID) if(NOT ANDROID)
if(NOT USE_GLES3) include(FindOpenGL)
include(FindOpenGL) include_directories(${OPENGL_INCLUDE_DIR})
else()
set(X11_FOUND 1)
endif()
include(FindALSA OPTIONAL) include(FindALSA OPTIONAL)
if(ALSA_FOUND) if(ALSA_FOUND)

View file

@ -228,11 +228,7 @@ if(_M_ARM)
) )
endif() endif()
set(LIBS bdisasm inputcommon videosoftware sfml-network) set(LIBS bdisasm inputcommon videoogl videosoftware sfml-network)
if(NOT USE_GLES OR USE_GLES3)
set(LIBS ${LIBS} videoogl)
endif()
if(LIBUSB_FOUND) if(LIBUSB_FOUND)
# Using shared LibUSB # Using shared LibUSB

View file

@ -702,7 +702,7 @@ void UpdateTitle()
// Settings are shown the same for both extended and summary info // Settings are shown the same for both extended and summary info
std::string SSettings = StringFromFormat("%s %s | %s | %s", cpu_core_base->GetName(), _CoreParameter.bCPUThread ? "DC" : "SC", std::string SSettings = StringFromFormat("%s %s | %s | %s", cpu_core_base->GetName(), _CoreParameter.bCPUThread ? "DC" : "SC",
g_video_backend->GetName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE"); g_video_backend->GetDisplayName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");
// Use extended or summary information. The summary information does not print the ticks data, // Use extended or summary information. The summary information does not print the ticks data,
// that's more of a debugging interest, it can always be optional of course if someone is interested. // that's more of a debugging interest, it can always be optional of course if someone is interested.

View file

@ -51,11 +51,6 @@ typedef struct {
#endif #endif
} GLWindow; } GLWindow;
enum GLInterfaceMode {
MODE_OPENGL = 0,
MODE_OPENGLES2,
MODE_OPENGLES3,
};
extern cInterfaceBase *GLInterface; extern cInterfaceBase *GLInterface;
extern GLWindow GLWin; extern GLWindow GLWin;

View file

@ -40,15 +40,96 @@ void* cInterfaceEGL::GetProcAddress(std::string name)
return (void*)eglGetProcAddress(name.c_str()); return (void*)eglGetProcAddress(name.c_str());
} }
void cInterfaceEGL::DetectMode()
{
if (s_opengl_mode != MODE_DETECT)
return;
EGLint num_configs;
EGLConfig *config = NULL;
bool supportsGL = false, supportsGLES2 = false, supportsGLES3 = false;
// attributes for a visual in RGBA format with at least
// 8 bits per color
int attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_NONE };
// Get how many configs there are
if (!eglChooseConfig( GLWin.egl_dpy, attribs, NULL, 0, &num_configs)) {
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
goto err_exit;
}
config = new EGLConfig[num_configs];
// Get all the configurations
if (!eglChooseConfig(GLWin.egl_dpy, attribs, config, num_configs, &num_configs))
{
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
goto err_exit;
}
for (int i = 0; i < num_configs; ++i)
{
EGLint attribVal;
bool ret;
ret = eglGetConfigAttrib(GLWin.egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal);
if (ret)
{
if (attribVal & EGL_OPENGL_BIT)
supportsGL = true;
if (attribVal & (1 << 6)) /* EGL_OPENGL_ES3_BIT_KHR */
supportsGLES3 = true;
if (attribVal & EGL_OPENGL_ES2_BIT)
supportsGLES2 = true;
}
}
if (supportsGL)
s_opengl_mode = GLInterfaceMode::MODE_OPENGL;
else if (supportsGLES3)
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES3;
else if (supportsGLES2)
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES2;
err_exit:
if (s_opengl_mode == GLInterfaceMode::MODE_DETECT) // Errored before we found a mode
s_opengl_mode = GLInterfaceMode::MODE_OPENGL; // Fall back to OpenGL
if (config)
delete[] config;
}
// Create rendering window. // Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceEGL::Create(void *&window_handle) bool cInterfaceEGL::Create(void *&window_handle)
{ {
const char *s; const char *s;
EGLint egl_major, egl_minor; EGLint egl_major, egl_minor;
if(!Platform.SelectDisplay())
return false;
GLWin.egl_dpy = Platform.EGLGetDisplay();
if (!GLWin.egl_dpy) {
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n");
return false;
}
GLWin.platform = Platform.platform;
if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) {
INFO_LOG(VIDEO, "Error: eglInitialize() failed\n");
return false;
}
/* Detection code */
EGLConfig config; EGLConfig config;
EGLint num_configs; EGLint num_configs;
DetectMode();
// attributes for a visual in RGBA format with at least // attributes for a visual in RGBA format with at least
// 8 bits per color // 8 bits per color
int attribs[] = { int attribs[] = {
@ -82,21 +163,9 @@ bool cInterfaceEGL::Create(void *&window_handle)
break; break;
} }
if(!Platform.SelectDisplay()) if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) {
return false; INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
exit(1);
GLWin.egl_dpy = Platform.EGLGetDisplay();
if (!GLWin.egl_dpy) {
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n");
return false;
}
GLWin.platform = Platform.platform;
if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) {
INFO_LOG(VIDEO, "Error: eglInitialize() failed\n");
return false;
} }
if (s_opengl_mode == MODE_OPENGL) if (s_opengl_mode == MODE_OPENGL)
@ -104,10 +173,6 @@ bool cInterfaceEGL::Create(void *&window_handle)
else else
eglBindAPI(EGL_OPENGL_ES_API); eglBindAPI(EGL_OPENGL_ES_API);
if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) {
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
exit(1);
}
if (!Platform.Init(config)) if (!Platform.Init(config))
return false; return false;

View file

@ -26,10 +26,12 @@ class cInterfaceEGL : public cInterfaceBase
{ {
private: private:
cPlatform Platform; cPlatform Platform;
void DetectMode();
public: public:
friend class cPlatform; friend class cPlatform;
void SwapInterval(int Interval); void SwapInterval(int Interval);
void Swap(); void Swap();
void SetMode(u32 mode) { s_opengl_mode = GLInterfaceMode::MODE_DETECT; }
void UpdateFPSDisplay(const char *Text); void UpdateFPSDisplay(const char *Text);
void* GetProcAddress(std::string name); void* GetProcAddress(std::string name);
bool Create(void *&window_handle); bool Create(void *&window_handle);

View file

@ -4,6 +4,13 @@
#ifndef _GLINTERFACEBASE_H_ #ifndef _GLINTERFACEBASE_H_
#define _GLINTERFACEBASE_H_ #define _GLINTERFACEBASE_H_
enum GLInterfaceMode {
MODE_DETECT = 0,
MODE_OPENGL,
MODE_OPENGLES2,
MODE_OPENGLES3,
};
class cInterfaceBase class cInterfaceBase
{ {
protected: protected:
@ -15,7 +22,7 @@ protected:
public: public:
virtual void Swap() {} virtual void Swap() {}
virtual void UpdateFPSDisplay(const char *Text) {} virtual void UpdateFPSDisplay(const char *Text) {}
virtual void SetMode(u32 mode) { s_opengl_mode = mode; } virtual void SetMode(u32 mode) { s_opengl_mode = GLInterfaceMode::MODE_OPENGL; }
virtual u32 GetMode() { return s_opengl_mode; } virtual u32 GetMode() { return s_opengl_mode; }
virtual void* GetProcAddress(std::string name) { return NULL; } virtual void* GetProcAddress(std::string name) { return NULL; }
virtual bool Create(void *&window_handle) { return true; } virtual bool Create(void *&window_handle) { return true; }

View file

@ -155,12 +155,6 @@ typedef struct {
#endif #endif
} GLWindow; } GLWindow;
enum GLInterfaceMode {
MODE_OPENGL = 0,
MODE_OPENGLES2,
MODE_OPENGLES3,
};
extern cInterfaceBase *GLInterface; extern cInterfaceBase *GLInterface;
extern GLWindow GLWin; extern GLWindow GLWin;

View file

@ -1,5 +1,3 @@
if(NOT USE_GLES OR USE_GLES3) add_subdirectory(OGL)
add_subdirectory(OGL)
endif()
add_subdirectory(Software) add_subdirectory(Software)
# TODO: Add other backends here! # TODO: Add other backends here!

View file

@ -29,7 +29,7 @@ unsigned int VideoBackend::PeekMessages()
void VideoBackend::UpdateFPSDisplay(const char *text) void VideoBackend::UpdateFPSDisplay(const char *text)
{ {
char temp[100]; char temp[100];
snprintf(temp, sizeof temp, "%s | OpenGL | %s", scm_rev_str, text); snprintf(temp, sizeof temp, "%s | %s | %s", scm_rev_str, GetDisplayName().c_str(), text);
return GLInterface->UpdateFPSDisplay(temp); return GLInterface->UpdateFPSDisplay(temp);
} }
@ -122,21 +122,6 @@ GLuint OpenGL_ReportGLError(const char *function, const char *file, int line)
return err; return err;
} }
void OpenGL_ReportARBProgramError()
{
#ifndef USE_GLES
const GLubyte* pstr = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
if (pstr != NULL && pstr[0] != 0)
{
GLint loc = 0;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &loc);
ERROR_LOG(VIDEO, "Program error at %d: ", loc);
ERROR_LOG(VIDEO, "%s", (char*)pstr);
ERROR_LOG(VIDEO, "\n");
}
#endif
}
bool OpenGL_ReportFBOError(const char *function, const char *file, int line) bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
{ {
unsigned int fbo_status = glCheckFramebufferStatus(GL_FRAMEBUFFER); unsigned int fbo_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@ -151,14 +136,12 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
error = "INCOMPLETE_MISSING_ATTACHMENT"; error = "INCOMPLETE_MISSING_ATTACHMENT";
break; break;
#ifndef USE_GLES
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
error = "INCOMPLETE_DRAW_BUFFER"; error = "INCOMPLETE_DRAW_BUFFER";
break; break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
error = "INCOMPLETE_READ_BUFFER"; error = "INCOMPLETE_READ_BUFFER";
break; break;
#endif
case GL_FRAMEBUFFER_UNSUPPORTED: case GL_FRAMEBUFFER_UNSUPPORTED:
error = "UNSUPPORTED"; error = "UNSUPPORTED";
break; break;

View file

@ -17,19 +17,6 @@
#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 #define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
#endif #endif
#ifdef USE_GLES
#define TEX2D GL_TEXTURE_2D
#define PREC "highp"
#define TEXTYPE "sampler2D"
#define TEXFUNC "texture2D"
#else
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
#define PREC
#define TEXTYPE "sampler2DRect"
#define TEXFUNC "texture2DRect"
#endif
#ifndef _WIN32 #ifndef _WIN32
#include <sys/types.h> #include <sys/types.h>
@ -41,7 +28,6 @@ void InitInterface();
GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader); GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader);
// Error reporting - use the convenient macros. // Error reporting - use the convenient macros.
void OpenGL_ReportARBProgramError();
GLuint OpenGL_ReportGLError(const char *function, const char *file, int line); GLuint OpenGL_ReportGLError(const char *function, const char *file, int line);
bool OpenGL_ReportFBOError(const char *function, const char *file, int line); bool OpenGL_ReportFBOError(const char *function, const char *file, int line);
@ -49,12 +35,10 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line);
#define GL_REPORT_ERROR() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__) #define GL_REPORT_ERROR() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__)
#define GL_REPORT_ERRORD() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__) #define GL_REPORT_ERRORD() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__)
#define GL_REPORT_FBO_ERROR() OpenGL_ReportFBOError(__FUNCTION__, __FILE__, __LINE__) #define GL_REPORT_FBO_ERROR() OpenGL_ReportFBOError(__FUNCTION__, __FILE__, __LINE__)
#define GL_REPORT_PROGRAM_ERROR() OpenGL_ReportARBProgramError()
#else #else
__forceinline GLenum GL_REPORT_ERROR() { return GL_NO_ERROR; } __forceinline GLenum GL_REPORT_ERROR() { return GL_NO_ERROR; }
#define GL_REPORT_ERRORD() (void)GL_NO_ERROR #define GL_REPORT_ERRORD() (void)GL_NO_ERROR
#define GL_REPORT_FBO_ERROR() (void)true #define GL_REPORT_FBO_ERROR() (void)true
#define GL_REPORT_PROGRAM_ERROR() (void)0
#endif #endif
// this should be removed in future, but as long as glsl is unstable, we should really read this messages // this should be removed in future, but as long as glsl is unstable, we should really read this messages

View file

@ -98,7 +98,10 @@ std::string VideoBackend::GetName()
std::string VideoBackend::GetDisplayName() std::string VideoBackend::GetDisplayName()
{ {
return "OpenGL"; if (g_renderer && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
return "OpenGLES";
else
return "OpenGL";
} }
void GetShaders(std::vector<std::string> &shaders) void GetShaders(std::vector<std::string> &shaders)
@ -179,10 +182,7 @@ bool VideoBackend::Initialize(void *&window_handle)
UpdateActiveConfig(); UpdateActiveConfig();
InitInterface(); InitInterface();
GLInterface->SetMode(GLInterfaceMode::MODE_OPENGL); GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
#ifdef USE_GLES3
GLInterface->SetMode(GLInterfaceMode::MODE_OPENGLES3);
#endif
if (!GLInterface->Create(window_handle)) if (!GLInterface->Create(window_handle))
return false; return false;

View file

@ -10,6 +10,7 @@ set(SRCS ../OGL/GLExtensions/GLExtensions.cpp
SWmain.cpp SWmain.cpp
OpcodeDecoder.cpp OpcodeDecoder.cpp
SWPixelEngine.cpp SWPixelEngine.cpp
RasterFont.cpp
Rasterizer.cpp Rasterizer.cpp
SWRenderer.cpp SWRenderer.cpp
SetupUnit.cpp SetupUnit.cpp
@ -30,20 +31,7 @@ set(LIBS videocommon
SOIL SOIL
common common
${X11_LIBRARIES} ${X11_LIBRARIES}
${OPENGL_LIBRARIES}
${wxWidgets_LIBRARIES}) ${wxWidgets_LIBRARIES})
if(USE_EGL)
set(LIBS ${LIBS}
EGL)
endif()
if(USE_GLES)
set(SRCS ${SRCS} ../OGL/GLUtil.cpp)
set(LIBS ${LIBS}
GLESv2)
else()
set(SRCS ${SRCS} RasterFont.cpp)
set(LIBS ${LIBS}
${OPENGL_LIBRARIES})
endif()
add_dolphin_library(videosoftware "${SRCS}" "${LIBS}") add_dolphin_library(videosoftware "${SRCS}" "${LIBS}")

View file

@ -25,6 +25,9 @@ namespace HwRasterizer
// Programs // Programs
static GLuint colProg, texProg, clearProg; static GLuint colProg, texProg, clearProg;
// Texture type
static GLenum texType;
// Color // Color
static GLint col_apos = -1, col_atex = -1; static GLint col_apos = -1, col_atex = -1;
// Tex // Tex
@ -36,20 +39,31 @@ namespace HwRasterizer
{ {
// Color Vertices // Color Vertices
static const char *fragcolText = static const char *fragcolText =
"varying " PREC " vec4 TexCoordOut;\n" "#if GL_ES\n"
"precision highp float;\n"
"#endif\n"
"varying vec4 TexCoordOut;\n"
"void main() {\n" "void main() {\n"
" gl_FragColor = TexCoordOut;\n" " gl_FragColor = TexCoordOut;\n"
"}\n"; "}\n";
// Texture Vertices // Texture Vertices
static const char *fragtexText = static const char *fragtexText =
"varying " PREC " vec4 TexCoordOut;\n" "#if GL_ES\n"
"uniform " TEXTYPE " Texture;\n" "precision highp float;\n"
"#define texture2DRect texture2D\n"
"#define sampler2DRect sampler2D\n"
"#endif\n"
"varying vec4 TexCoordOut;\n"
"uniform sampler2DRect Texture;\n"
"void main() {\n" "void main() {\n"
" gl_FragColor = " TEXFUNC "(Texture, TexCoordOut.xy);\n" " gl_FragColor = texture2DRect(Texture, TexCoordOut.xy);\n"
"}\n"; "}\n";
// Clear shader // Clear shader
static const char *fragclearText = static const char *fragclearText =
"uniform " PREC " vec4 Color;\n" "#if GL_ES\n"
"precision highp float;\n"
"#endif\n"
"uniform vec4 Color;\n"
"void main() {\n" "void main() {\n"
" gl_FragColor = Color;\n" " gl_FragColor = Color;\n"
"}\n"; "}\n";
@ -107,24 +121,25 @@ namespace HwRasterizer
//legacy multitexturing: select texture channel only. //legacy multitexturing: select texture channel only.
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
#ifndef USE_GLES if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
glShadeModel(GL_SMOOTH); {
glDisable(GL_BLEND); glShadeModel(GL_SMOOTH);
glClearDepth(1.0f); glDisable(GL_BLEND);
glEnable(GL_SCISSOR_TEST); glClearDepth(1.0f);
glDisable(GL_LIGHTING); glEnable(GL_SCISSOR_TEST);
glMatrixMode(GL_PROJECTION); glDisable(GL_LIGHTING);
glLoadIdentity(); glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glLoadIdentity(); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClientActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_RECTANGLE_ARB);
glStencilFunc(GL_ALWAYS, 0, 0); glStencilFunc(GL_ALWAYS, 0, 0);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
#endif }
// used by hw rasterizer if it enables blending and depth test // used by hw rasterizer if it enables blending and depth test
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -132,6 +147,11 @@ namespace HwRasterizer
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateShaders(); CreateShaders();
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
texType = GL_TEXTURE_RECTANGLE;
else
texType = GL_TEXTURE_2D;
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
static float width, height; static float width, height;
@ -141,19 +161,22 @@ namespace HwRasterizer
u32 imageAddr = texUnit.texImage3[0].image_base; u32 imageAddr = texUnit.texImage3[0].image_base;
// Texture Rectangle uses pixel coordinates // Texture Rectangle uses pixel coordinates
// While GLES uses texture coordinates // While GLES uses texture coordinates
#ifdef USE_GLES if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
width = texUnit.texImage0[0].width; {
height = texUnit.texImage0[0].height; width = texUnit.texImage0[0].width;
#else height = texUnit.texImage0[0].height;
width = 1; }
height = 1; else
#endif {
width = 1;
height = 1;
}
TexCacheEntry &cacheEntry = textures[imageAddr]; TexCacheEntry &cacheEntry = textures[imageAddr];
cacheEntry.Update(); cacheEntry.Update();
glBindTexture(TEX2D, cacheEntry.texture); glBindTexture(texType, cacheEntry.texture);
glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST); glTexParameteri(texType, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST);
glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST); glTexParameteri(texType, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
@ -171,7 +194,7 @@ namespace HwRasterizer
void EndTriangles() void EndTriangles()
{ {
glBindTexture(TEX2D, 0); glBindTexture(texType, 0);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
@ -332,8 +355,8 @@ namespace HwRasterizer
DebugUtil::GetTextureRGBA(temp, 0, 0, image_width, image_height); DebugUtil::GetTextureRGBA(temp, 0, 0, image_width, image_height);
glGenTextures(1, (GLuint *)&texture); glGenTextures(1, (GLuint *)&texture);
glBindTexture(TEX2D, texture); glBindTexture(texType, texture);
glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)image_width, (GLsizei)image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp); glTexImage2D(texType, 0, GL_RGBA, (GLsizei)image_width, (GLsizei)image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }

View file

@ -25,9 +25,7 @@ static std::string s_sScreenshotName;
// Rasterfont isn't compatible with GLES // Rasterfont isn't compatible with GLES
// degasus: I think it does, but I can't test it // degasus: I think it does, but I can't test it
#ifndef USE_GLES
RasterFont* s_pfont = NULL; RasterFont* s_pfont = NULL;
#endif
void SWRenderer::Init() void SWRenderer::Init()
{ {
@ -38,23 +36,28 @@ void SWRenderer::Shutdown()
{ {
glDeleteProgram(program); glDeleteProgram(program);
glDeleteTextures(1, &s_RenderTarget); glDeleteTextures(1, &s_RenderTarget);
#ifndef USE_GLES if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
delete s_pfont; {
s_pfont = 0; delete s_pfont;
#endif s_pfont = 0;
}
} }
void CreateShaders() void CreateShaders()
{ {
static const char *fragShaderText = static const char *fragShaderText =
"varying " PREC " vec2 TexCoordOut;\n" "#if GL_ES\n"
"precision highp float;\n"
"#endif\n"
"varying vec2 TexCoordOut;\n"
"uniform sampler2D Texture;\n" "uniform sampler2D Texture;\n"
"void main() {\n" "void main() {\n"
" " PREC " vec4 tmpcolor;\n" " gl_FragColor = texture2D(Texture, TexCoordOut);\n"
" tmpcolor = texture2D(Texture, TexCoordOut);\n"
" gl_FragColor = tmpcolor;\n"
"}\n"; "}\n";
static const char *vertShaderText = static const char *vertShaderText =
"#if GL_ES\n"
"precision highp float;\n"
"#endif\n"
"attribute vec4 pos;\n" "attribute vec4 pos;\n"
"attribute vec2 TexCoordIn;\n " "attribute vec2 TexCoordIn;\n "
"varying vec2 TexCoordOut;\n " "varying vec2 TexCoordOut;\n "
@ -80,10 +83,11 @@ void SWRenderer::Prepare()
CreateShaders(); CreateShaders();
// TODO: Enable for GLES once RasterFont supports GLES // TODO: Enable for GLES once RasterFont supports GLES
#ifndef USE_GLES if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
s_pfont = new RasterFont(); {
glEnable(GL_TEXTURE_2D); s_pfont = new RasterFont();
#endif glEnable(GL_TEXTURE_2D);
}
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
@ -96,7 +100,8 @@ void SWRenderer::SetScreenshot(const char *_szFilename)
void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color) void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
{ {
#ifndef USE_GLES if (GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL)
return;
int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth(); int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight(); int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f, glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f,
@ -105,7 +110,6 @@ void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
left * 2.0f / (float)nBackbufferWidth - 1, left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight, 1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight); 0, nBackbufferWidth, nBackbufferHeight);
#endif
} }
void SWRenderer::DrawDebugText() void SWRenderer::DrawDebugText()

View file

@ -63,10 +63,7 @@ bool VideoSoftware::Initialize(void *&window_handle)
g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str()); g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str());
InitInterface(); InitInterface();
GLInterface->SetMode(GLInterfaceMode::MODE_OPENGL); GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
#ifdef USE_GLES
GLInterface->SetMode(GLInterfaceMode::MODE_OPENGLES2);
#endif
if (!GLInterface->Create(window_handle)) if (!GLInterface->Create(window_handle))
{ {
INFO_LOG(VIDEO, "%s", "SWRenderer::Create failed\n"); INFO_LOG(VIDEO, "%s", "SWRenderer::Create failed\n");

View file

@ -8,9 +8,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include "../VideoBackends/D3D/VideoBackend.h" #include "../VideoBackends/D3D/VideoBackend.h"
#endif #endif
#if !defined(USE_GLES) || USE_GLES3
#include "../VideoBackends/OGL/VideoBackend.h" #include "../VideoBackends/OGL/VideoBackend.h"
#endif
#include "../VideoBackends/Software/VideoBackend.h" #include "../VideoBackends/Software/VideoBackend.h"
std::vector<VideoBackend*> g_available_video_backends; std::vector<VideoBackend*> g_available_video_backends;