Merge commit 'f3e2da881a4d394c4ca902548e788f5b4c0bdd81'

* commit 'f3e2da881a4d394c4ca902548e788f5b4c0bdd81':
  Do not build shadow shader without gs support.
  Add a function to query supported glsl ver
  Some drivers dont support const array
This commit is contained in:
Vincent Lejeune 2014-03-22 18:54:51 +01:00
commit 29749d5dbd
10 changed files with 97 additions and 31 deletions

View File

@ -1,4 +1,4 @@
#version 330
#version 140
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,5 +1,5 @@
// Passthrough shader for drawQuad()
#version 330
#version 140
in vec3 Position;
in vec2 Texcoord;

View File

@ -29,7 +29,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
{
//float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
const vec2 shadowoffset[4] = vec2[](
vec2 shadowoffset[4] = vec2[](
vec2(-1., -1.),
vec2(-1., 1.),
vec2(1., -1.),

View File

@ -368,6 +368,65 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand )
}
#endif
static GLXContext getMeAGLContext(Display *display, GLXFBConfig glxFBConfig)
{
GLXContext Context;
int compat33ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int core33ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int core31ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int legacyctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
None
};
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
// create compat 3.3 context (for proprietary drivers)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, compat33ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// create core 3.3 context (for mesa)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, core33ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// create core 3.1 context (for older mesa)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, core31ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// fall back to legacy context
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, legacyctx);
return Context;
}
bool CIrrDeviceLinux::createWindow()
{
@ -741,30 +800,7 @@ bool CIrrDeviceLinux::createWindow()
glxWin=glXCreateWindow(display,glxFBConfig,window,NULL);
if (glxWin)
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //GLX_CONTEXT_CORE_PROFILE_BIT_ARB
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
// create glx context
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
if (XErrorSignaled)
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
None
};
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
XErrorSignaled = false;
}
Context = getMeAGLContext(display, glxFBConfig);
if (Context)
{
if (!glXMakeContextCurrent(display, glxWin, glxWin, Context))

View File

@ -210,7 +210,9 @@ void initGL()
GLuint LoadShader(const char * file, unsigned type)
{
GLuint Id = glCreateShader(type);
std::string Code = "#version 330\n";
char versionString[20];
sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion());
std::string Code = versionString;
std::ifstream Stream(file, std::ios::in);
if (Stream.is_open())
{

View File

@ -422,12 +422,12 @@ void IrrDriver::initDevice()
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();
int GLMajorVersion = 0, GLMinorVersion = 0;
GLMajorVersion = 2;
GLMinorVersion = 1;
glGetIntegerv(GL_MAJOR_VERSION, &GLMajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &GLMinorVersion);
Log::info("IrrDriver", "OPENGL VERSION IS %d.%d", GLMajorVersion, GLMinorVersion);
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion == 3)) && UserConfigParams::m_pixel_shaders;
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1)) && UserConfigParams::m_pixel_shaders;
// This remaps the window, so it has to be done before the clear to avoid flicker
m_device->setResizable(false);

View File

@ -82,6 +82,7 @@ enum STKRenderingPass
class IrrDriver : public IEventReceiver, public NoCopy
{
private:
int GLMajorVersion, GLMinorVersion;
/** The irrlicht device. */
IrrlichtDevice *m_device;
/** Irrlicht scene manager. */
@ -148,6 +149,16 @@ public:
float power;
};
unsigned getGLSLVersion() const
{
if (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion == 3))
return GLMajorVersion * 100 + GLMinorVersion * 10;
else if (GLMajorVersion == 3)
return 100 + (GLMinorVersion + 3) * 10;
else
return 120;
}
private:
std::vector<VideoMode> m_modes;

View File

@ -137,6 +137,8 @@ RTT::RTT()
drv->setRenderTarget(0, false, false);
drv->endScene();
if (irr_driver->getGLSLVersion() < 150)
return;
glGenFramebuffers(1, &shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
glGenTextures(1, &shadowColorTex);

View File

@ -1049,6 +1049,12 @@ namespace MeshShader
void ShadowShader::init()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
{
attrib_position = -1;
return;
}
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
@ -1076,6 +1082,13 @@ namespace MeshShader
void RefShadowShader::init()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
{
attrib_position = -1;
attrib_texcoord = -1;
return;
}
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),

View File

@ -55,6 +55,8 @@ TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE typ
GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride)
{
if (attrib_position == -1)
return 0;
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);