Commit b97ad2e8 by Nicolas Capens

Enable OpenGL ES 3.0 context creation.

Bug 19362672 Change-Id: Ie948dd0c26a6a5f65f6e15b75f2376d598129c28 Reviewed-on: https://swiftshader-review.googlesource.com/2287Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 792950af
...@@ -81,7 +81,7 @@ Config::Config(const DisplayMode &displayMode, EGLint minInterval, EGLint maxInt ...@@ -81,7 +81,7 @@ Config::Config(const DisplayMode &displayMode, EGLint minInterval, EGLint maxInt
mColorBufferType = EGL_RGB_BUFFER; mColorBufferType = EGL_RGB_BUFFER;
mConfigCaveat = isSlowConfig() ? EGL_SLOW_CONFIG : EGL_NONE; mConfigCaveat = isSlowConfig() ? EGL_SLOW_CONFIG : EGL_NONE;
mConfigID = 0; mConfigID = 0;
mConformant = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; mConformant = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
switch (depthStencilFormat) switch (depthStencilFormat)
{ {
...@@ -139,7 +139,7 @@ Config::Config(const DisplayMode &displayMode, EGLint minInterval, EGLint maxInt ...@@ -139,7 +139,7 @@ Config::Config(const DisplayMode &displayMode, EGLint minInterval, EGLint maxInt
mNativeRenderable = EGL_FALSE; mNativeRenderable = EGL_FALSE;
mNativeVisualID = 0; mNativeVisualID = 0;
mNativeVisualType = 0; mNativeVisualType = 0;
mRenderableType = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; mRenderableType = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
mSampleBuffers = multiSample ? 1 : 0; mSampleBuffers = multiSample ? 1 : 0;
mSamples = multiSample; mSamples = multiSample;
mSurfaceType = EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; mSurfaceType = EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
......
...@@ -400,11 +400,12 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh ...@@ -400,11 +400,12 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh
context = es1::createContext(config, shareContext); context = es1::createContext(config, shareContext);
} }
} }
else if(clientVersion == 2 && config->mRenderableType & EGL_OPENGL_ES2_BIT) else if((clientVersion == 2 && config->mRenderableType & EGL_OPENGL_ES2_BIT) ||
(clientVersion == 3 && config->mRenderableType & EGL_OPENGL_ES3_BIT))
{ {
if(es2::createContext != 0) if(es2::createContext != 0)
{ {
context = es2::createContext(config, shareContext); context = es2::createContext(config, shareContext, clientVersion);
} }
} }
else else
......
...@@ -104,7 +104,7 @@ CONSTRUCTOR static bool eglAttachProcess() ...@@ -104,7 +104,7 @@ CONSTRUCTOR static bool eglAttachProcess()
#endif #endif
libGLESv2 = loadLibrary(libGLESv2_lib); libGLESv2 = loadLibrary(libGLESv2_lib);
es2::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*))getProcAddress(libGLESv2, "glCreateContext"); es2::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*, EGLint))getProcAddress(libGLESv2, "glCreateContext");
es2::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress"); es2::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress");
es::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLES_CM, "createBackBuffer"); es::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLES_CM, "createBackBuffer");
...@@ -342,7 +342,7 @@ namespace es1 ...@@ -342,7 +342,7 @@ namespace es1
namespace es2 namespace es2
{ {
egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 0; egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext, EGLint clientVersion) = 0;
__eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0; __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;
} }
......
...@@ -92,7 +92,7 @@ namespace es1 ...@@ -92,7 +92,7 @@ namespace es1
// libGLESv2 dependencies // libGLESv2 dependencies
namespace es2 namespace es2
{ {
extern egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext); extern egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext, EGLint clientVersion);
extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname); extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname);
} }
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
namespace es2 namespace es2
{ {
Context::Context(const egl::Config *config, const Context *shareContext) : mConfig(config) Context::Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion)
: mConfig(config), clientVersion(clientVersion)
{ {
sw::Context *context = new sw::Context(); sw::Context *context = new sw::Context();
device = new es2::Device(context); device = new es2::Device(context);
...@@ -272,9 +273,9 @@ void Context::destroy() ...@@ -272,9 +273,9 @@ void Context::destroy()
delete this; delete this;
} }
int Context::getClientVersion() EGLint Context::getClientVersion()
{ {
return 2; return clientVersion;
} }
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw. // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
...@@ -3245,8 +3246,8 @@ Device *Context::getDevice() ...@@ -3245,8 +3246,8 @@ Device *Context::getDevice()
// Exported functions for use by EGL // Exported functions for use by EGL
extern "C" extern "C"
{ {
es2::Context *glCreateContext(const egl::Config *config, const es2::Context *shareContext) es2::Context *glCreateContext(const egl::Config *config, const es2::Context *shareContext, int clientVersion)
{ {
return new es2::Context(config, shareContext); return new es2::Context(config, shareContext, clientVersion);
} }
} }
...@@ -251,11 +251,11 @@ struct State ...@@ -251,11 +251,11 @@ struct State
class Context : public egl::Context class Context : public egl::Context
{ {
public: public:
Context(const egl::Config *config, const Context *shareContext); Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);
virtual void makeCurrent(egl::Surface *surface); virtual void makeCurrent(egl::Surface *surface);
virtual void destroy(); virtual void destroy();
virtual int getClientVersion(); virtual EGLint getClientVersion();
void markAllStateDirty(); void markAllStateDirty();
...@@ -459,6 +459,7 @@ private: ...@@ -459,6 +459,7 @@ private:
bool cullSkipsDraw(GLenum drawMode); bool cullSkipsDraw(GLenum drawMode);
bool isTriangleMode(GLenum drawMode); bool isTriangleMode(GLenum drawMode);
const EGLint clientVersion;
const egl::Config *const mConfig; const egl::Config *const mConfig;
State mState; State mState;
......
...@@ -4086,106 +4086,109 @@ void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, ...@@ -4086,106 +4086,109 @@ void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat,
return error(GL_INVALID_VALUE); return error(GL_INVALID_VALUE);
} }
if(internalformat != format) es2::Context *context = es2::getContext();
{
return error(GL_INVALID_OPERATION);
}
switch(format) if(context)
{ {
case GL_ALPHA: if(context->getClientVersion() < 3)
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
switch(type)
{ {
case GL_UNSIGNED_BYTE: if(internalformat != format)
case GL_FLOAT: {
case GL_HALF_FLOAT_OES: return error(GL_INVALID_OPERATION);
break; }
default:
return error(GL_INVALID_ENUM);
} }
break;
case GL_RGB: switch(format)
switch(type)
{ {
case GL_UNSIGNED_BYTE: case GL_ALPHA:
case GL_UNSIGNED_SHORT_5_6_5: case GL_LUMINANCE:
case GL_FLOAT: case GL_LUMINANCE_ALPHA:
case GL_HALF_FLOAT_OES: switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_FLOAT:
case GL_HALF_FLOAT_OES:
break;
default:
return error(GL_INVALID_ENUM);
}
break; break;
default: case GL_RGB:
return error(GL_INVALID_ENUM); switch(type)
} {
break; case GL_UNSIGNED_BYTE:
case GL_RGBA: case GL_UNSIGNED_SHORT_5_6_5:
switch(type) case GL_FLOAT:
{ case GL_HALF_FLOAT_OES:
case GL_UNSIGNED_BYTE: break;
case GL_UNSIGNED_SHORT_4_4_4_4: default:
case GL_UNSIGNED_SHORT_5_5_5_1: return error(GL_INVALID_ENUM);
case GL_FLOAT: }
case GL_HALF_FLOAT_OES:
break; break;
default: case GL_RGBA:
return error(GL_INVALID_ENUM); switch(type)
} {
break; case GL_UNSIGNED_BYTE:
case GL_BGRA_EXT: case GL_UNSIGNED_SHORT_4_4_4_4:
switch(type) case GL_UNSIGNED_SHORT_5_5_5_1:
{ case GL_FLOAT:
case GL_UNSIGNED_BYTE: case GL_HALF_FLOAT_OES:
break;
default:
return error(GL_INVALID_ENUM);
}
break; break;
default: case GL_BGRA_EXT:
return error(GL_INVALID_ENUM); switch(type)
} {
break; case GL_UNSIGNED_BYTE:
case GL_ETC1_RGB8_OES: break;
return error(GL_INVALID_OPERATION); default:
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return error(GL_INVALID_ENUM);
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: }
case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: break;
case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: case GL_ETC1_RGB8_OES:
if(S3TC_SUPPORT)
{
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
else case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
{ case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
return error(GL_INVALID_ENUM); case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
} if(S3TC_SUPPORT)
case GL_DEPTH_COMPONENT: {
switch(type) return error(GL_INVALID_OPERATION);
{ }
case GL_UNSIGNED_SHORT: else
case GL_UNSIGNED_INT: {
return error(GL_INVALID_ENUM);
}
case GL_DEPTH_COMPONENT:
switch(type)
{
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_INT:
break;
default:
return error(GL_INVALID_ENUM);
}
break; break;
default: case GL_DEPTH_STENCIL_OES:
return error(GL_INVALID_ENUM); switch(type)
} {
break; case GL_UNSIGNED_INT_24_8_OES:
case GL_DEPTH_STENCIL_OES: break;
switch(type) default:
{ return error(GL_INVALID_ENUM);
case GL_UNSIGNED_INT_24_8_OES: }
break; break;
default: default:
return error(GL_INVALID_ENUM); return error(GL_INVALID_VALUE);
} }
break;
default:
return error(GL_INVALID_VALUE);
}
if(border != 0) if(border != 0)
{ {
return error(GL_INVALID_VALUE); return error(GL_INVALID_VALUE);
} }
es2::Context *context = es2::getContext();
if(context)
{
switch(target) switch(target)
{ {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
......
...@@ -109,7 +109,8 @@ es2::Context *getContext() ...@@ -109,7 +109,8 @@ es2::Context *getContext()
{ {
egl::Context *context = egl::getCurrentContext(); egl::Context *context = egl::getCurrentContext();
if(context && context->getClientVersion() == 2) if(context && (context->getClientVersion() == 2 ||
context->getClientVersion() == 3))
{ {
return static_cast<es2::Context*>(context); return static_cast<es2::Context*>(context);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment