diff --git a/include/eepp/ee.hpp b/include/eepp/ee.hpp index 05b0c3cac..61ab8c35e 100755 --- a/include/eepp/ee.hpp +++ b/include/eepp/ee.hpp @@ -47,8 +47,6 @@ @todo Improve Premake4 support. It should be really easy to compile eepp in Windows and OS X ( Linux is always easy thanks to package managers ). STATE: Need to implement on App Bundles for OS X. - @todo Add Thread-local storage class. - Middle-term plans: @todo Add audio recording from the SFML implementation, adapted to the engine coding style. diff --git a/include/eepp/graphics/renderer/cgl.hpp b/include/eepp/graphics/renderer/cgl.hpp index ac5e85a91..a8f0fa186 100644 --- a/include/eepp/graphics/renderer/cgl.hpp +++ b/include/eepp/graphics/renderer/cgl.hpp @@ -200,6 +200,12 @@ class EE_API cGL { void ColorMask ( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); + void BindVertexArray ( GLuint array ); + + void DeleteVertexArrays ( GLsizei n, const GLuint *arrays ); + + void GenVertexArrays ( GLsizei n, GLuint *arrays ); + const bool& QuadsSupported() const; const int& QuadVertexs() const; @@ -215,6 +221,8 @@ class EE_API cGL { bool mQuadsSupported; int mQuadVertexs; GLfloat mLineWidth; + GLuint mCurVAO; + std::list mPlanesClipped; private: void WriteExtension( Uint8 Pos, Uint32 BitWrite ); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 0b33ac4af..00e1917d0 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 47c915f0c..89cf92df3 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -666,3 +666,5 @@ ../../assets/ee.ini ../../src/eepp/graphics/renderer/crenderergl3cp.cpp ../../include/eepp/graphics/renderer/crenderergl3cp.hpp +../../src/eepp/graphics/renderer/shaders/basegl3cp.vert +../../src/eepp/graphics/renderer/shaders/basegl3cp.frag diff --git a/src/eepp/graphics/cshader.cpp b/src/eepp/graphics/cshader.cpp index 93c00d0b8..40411a84e 100644 --- a/src/eepp/graphics/cshader.cpp +++ b/src/eepp/graphics/cshader.cpp @@ -137,11 +137,25 @@ void cShader::EnsureVersion() { } } else { if ( mSource.find( "gl_FragColor" ) != std::string::npos ) { + if ( GLi->Version() != GLv_3CP ) { - mSource = "#ifdef GL_ES\nprecision mediump float;\nprecision lowp int;\n#endif\nvarying vec4 gl_Color;\nvarying vec4 gl_TexCoord[ 1 ];\n" + mSource; + #ifdef EE_GLES + std::string preSource = "#ifdef GL_ES\nprecision mediump float;\nprecision lowp int;\n#endif"; + #else + std::string preSource = "#version 120"; + #endif + + mSource = preSource + "\nvarying vec4 gl_Color;\nvarying vec4 gl_TexCoord[ 1 ];\n" + mSource; + } else { + mSource = "#version 330\nin vec4 gl_Color;\nin vec4 gl_TexCoord[ 1 ];\nout vec4 gl_FragColor;\n" + mSource; + } String::ReplaceSubStr( mSource, "gl_Color" , "dgl_Color" ); String::ReplaceSubStr( mSource, "gl_TexCoord" , "dgl_TexCoord" ); + + if ( GLi->Version() == GLv_3CP ) { + String::ReplaceSubStr( mSource, "gl_FragColor" , "dgl_FragColor" ); + } } } } diff --git a/src/eepp/graphics/cshaderprogram.cpp b/src/eepp/graphics/cshaderprogram.cpp index 49addc1f7..635952abe 100644 --- a/src/eepp/graphics/cshaderprogram.cpp +++ b/src/eepp/graphics/cshaderprogram.cpp @@ -242,10 +242,10 @@ bool cShaderProgram::Link() { #endif if ( !mValid ) { - eePRINTL( "cShaderProgram::Link(): %s: Couldn't link program. Log follows:\n", mName.c_str(), mLinkLog.c_str() ); + eePRINTL( "cShaderProgram::Link(): %s: Couldn't link program. Log follows:\n%s", mName.c_str(), mLinkLog.c_str() ); } else { if ( mLinkLog.size() > 1 ) { - eePRINTL( "cShaderProgram::Link() %s: Program linked, but received some log:\n", mName.c_str(), mLinkLog.c_str() ); + eePRINTL( "cShaderProgram::Link() %s: Program linked, but received some log:\n%s", mName.c_str(), mLinkLog.c_str() ); } mUniformLocations.clear(); diff --git a/src/eepp/graphics/csubtexture.cpp b/src/eepp/graphics/csubtexture.cpp index 4356e42d2..6dedf98c0 100644 --- a/src/eepp/graphics/csubtexture.cpp +++ b/src/eepp/graphics/csubtexture.cpp @@ -355,11 +355,11 @@ bool cSubTexture::SaveToFile(const std::string& filepath, const EE_SAVE_TYPE& Fo if ( NULL != mTexture ) { if ( SAVE_TYPE_JPG != Format ) { - Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, RealSize().Width(), RealSize().Height(), 4, GetPixelsPtr() ) ); + Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, RealSize().Width(), RealSize().Height(), mTexture->Channels(), GetPixelsPtr() ) ); } else { jpge::params params; params.m_quality = cImage::JpegQuality(); - Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), RealSize().Width(), RealSize().Height(), 4, GetPixelsPtr(), params); + Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), RealSize().Width(), RealSize().Height(), mTexture->Channels(), GetPixelsPtr(), params); } } diff --git a/src/eepp/graphics/cvertexbuffervbo.cpp b/src/eepp/graphics/cvertexbuffervbo.cpp index a2e4b3505..557e781ac 100644 --- a/src/eepp/graphics/cvertexbuffervbo.cpp +++ b/src/eepp/graphics/cvertexbuffervbo.cpp @@ -28,11 +28,9 @@ cVertexBufferVBO::~cVertexBufferVBO() { glDeleteBuffersARB( 1, (GLuint *)&mElementHandle ); } - #ifndef EE_GLES if ( GLv_3CP == GLi->Version() && mVAO ) { - glDeleteVertexArrays( 1, &mVAO ); + GLi->DeleteVertexArrays( 1, &mVAO ); } - #endif } void cVertexBufferVBO::Bind() { @@ -55,8 +53,8 @@ bool cVertexBufferVBO::Compile() { if ( GLv_3CP == GLi->Version() ) { glGetIntegerv( GL_VERTEX_ARRAY_BINDING, &curVAO ); - glGenVertexArrays( 1, &mVAO ); - glBindVertexArray( mVAO ); + GLi->GenVertexArrays( 1, &mVAO ); + GLi->BindVertexArray( mVAO ); } #endif @@ -100,11 +98,9 @@ bool cVertexBufferVBO::Compile() { mCompiled = true; mBuffersSet = false; - #ifndef EE_GLES if ( GLv_3CP == GLi->Version() ) { - glBindVertexArray( curVAO ); + GLi->BindVertexArray( curVAO ); } - #endif return true; } @@ -118,7 +114,7 @@ void cVertexBufferVBO::Draw() { if ( GLv_3CP == GLi->Version() ) { glGetIntegerv( GL_VERTEX_ARRAY_BINDING, &curVAO ); - glBindVertexArray( mVAO ); + GLi->BindVertexArray( mVAO ); } #endif @@ -143,11 +139,9 @@ void cVertexBufferVBO::Draw() { glDrawArrays( mDrawType, 0, GetVertexCount() ); } - #ifndef EE_GLES if ( GLv_3CP == GLi->Version() ) { - glBindVertexArray( curVAO ); + GLi->BindVertexArray( curVAO ); } - #endif } void cVertexBufferVBO::SetVertexStates() { @@ -164,7 +158,7 @@ void cVertexBufferVBO::SetVertexStates() { } glGetIntegerv( GL_VERTEX_ARRAY_BINDING, &curVAO ); - glBindVertexArray( mVAO ); + GLi->BindVertexArray( mVAO ); } #endif @@ -284,11 +278,9 @@ void cVertexBufferVBO::SetVertexStates() { mBuffersSet = true; - #ifndef EE_GLES if ( GLv_3CP == GLi->Version() ) { - glBindVertexArray( curVAO ); + GLi->BindVertexArray( curVAO ); } - #endif } void cVertexBufferVBO::Update( const Uint32& Types, bool Indices ) { diff --git a/src/eepp/graphics/renderer/cgl.cpp b/src/eepp/graphics/renderer/cgl.cpp index fcee0dd2e..68d016a17 100644 --- a/src/eepp/graphics/renderer/cgl.cpp +++ b/src/eepp/graphics/renderer/cgl.cpp @@ -98,7 +98,9 @@ cGL::cGL() : mStateFlags( 1 << GLSF_LINE_SMOOTH ), mPushClip( true ), mQuadsSupported( true ), - mQuadVertexs( 4 ) + mQuadVertexs( 4 ), + mLineWidth( 1 ), + mCurVAO( 0 ) { GLi = this; } @@ -555,6 +557,28 @@ const int& cGL::QuadVertexs() const { return mQuadVertexs; } +void cGL::BindVertexArray ( GLuint array ) { +#ifndef EE_GLES + if ( mCurVAO != array ) { + glBindVertexArray( array ); + + mCurVAO = array; + } +#endif +} + +void cGL::DeleteVertexArrays ( GLsizei n, const GLuint *arrays ) { +#ifndef EE_GLES + glDeleteVertexArrays( n, arrays ); +#endif +} + +void cGL::GenVertexArrays ( GLsizei n, GLuint *arrays ) { +#ifndef EE_GLES + glGenVertexArrays( n, arrays ); +#endif +} + const bool& cGL::QuadsSupported() const { return mQuadsSupported; } diff --git a/src/eepp/graphics/renderer/crenderergl3cp.cpp b/src/eepp/graphics/renderer/crenderergl3cp.cpp index ddc55ecd4..d05f480d2 100644 --- a/src/eepp/graphics/renderer/crenderergl3cp.cpp +++ b/src/eepp/graphics/renderer/crenderergl3cp.cpp @@ -38,10 +38,10 @@ const char * EEGL3CP_PLANES_NAME[] = { }; const GLchar * EEGL3CP_SHADER_BASE_VS = -#include "shaders/basegl3.vert" +#include "shaders/basegl3cp.vert" const GLchar * EEGL3CP_SHADER_BASE_FS = -#include "shaders/basegl3.frag" +#include "shaders/basegl3cp.frag" cRendererGL3CP::cRendererGL3CP() : mProjectionMatrix_id(0), @@ -76,9 +76,7 @@ cRendererGL3CP::~cRendererGL3CP() { } } - #ifndef EE_GLES - glDeleteVertexArrays( 1, &mVAO ); - #endif + DeleteVertexArrays( 1, &mVAO ); eeSAFE_DELETE( mStack ); @@ -136,10 +134,8 @@ void cRendererGL3CP::Init() { mShaders[ EEGL3CP_SHADER_BASE ]->Reload(); } - #ifndef EE_GLES - glGenVertexArrays( 1, &mVAO ); - glBindVertexArray( mVAO ); - #endif + GenVertexArrays( 1, &mVAO ); + BindVertexArray( mVAO ); glGenBuffersARB( EEGL_ARRAY_STATES_COUNT+5, &mVBO[0] ); @@ -374,9 +370,7 @@ void cRendererGL3CP::VertexPointer ( GLint size, GLenum type, GLsizei stride, co #endif if ( -1 != index ) { - #ifndef EE_GLES - glBindVertexArray( mVAO ); - #endif + BindVertexArray( mVAO ); if ( allocate > mVBOSizeAlloc ) { AllocateBuffers( allocate ); @@ -407,9 +401,7 @@ void cRendererGL3CP::ColorPointer ( GLint size, GLenum type, GLsizei stride, con #endif if ( -1 != index ) { - #ifndef EE_GLES - glBindVertexArray( mVAO ); - #endif + BindVertexArray( mVAO ); if ( allocate > mVBOSizeAlloc ) { AllocateBuffers( allocate ); @@ -440,9 +432,7 @@ void cRendererGL3CP::TexCoordPointer ( GLint size, GLenum type, GLsizei stride, #endif if ( -1 != index ) { - #ifndef EE_GLES - glBindVertexArray( mVAO ); - #endif + BindVertexArray( mVAO ); if ( allocate > mVBOSizeAlloc ) { AllocateBuffers( allocate ); @@ -746,9 +736,7 @@ GLint cRendererGL3CP::UnProject( GLfloat winx, GLfloat winy, GLfloat winz, const } void cRendererGL3CP::BindGlobalVAO() { - #ifndef EE_GLES - glBindVertexArray( mVAO ); - #endif + BindVertexArray( mVAO ); } void cRendererGL3CP::AllocateBuffers( const Uint32& size ) { diff --git a/src/eepp/graphics/renderer/shaders/basegl3cp.frag b/src/eepp/graphics/renderer/shaders/basegl3cp.frag new file mode 100644 index 000000000..01a8ab881 --- /dev/null +++ b/src/eepp/graphics/renderer/shaders/basegl3cp.frag @@ -0,0 +1,35 @@ +#ifdef EE_GLES2 +"precision mediump float;\n" +"precision lowp int;\n" +#else +"#version 330\n" +#endif +"#define MAX_CLIP_PLANES 6\n\ +uniform sampler2D textureUnit0;\n\ +uniform int dgl_TexActive;\n\ +uniform int dgl_PointSpriteActive;\n\ +uniform int dgl_ClippingEnabled;\n\ +uniform int dgl_ClipEnabled[ MAX_CLIP_PLANES ];\n\ +uniform vec4 dgl_ClipPlane[ MAX_CLIP_PLANES ];\n\ +in vec4 dgl_Color;\n\ +in vec4 dgl_TexCoord[ 1 ];\n\ +in float dgl_ClipDistance[ MAX_CLIP_PLANES ];\n\ +out vec4 dgl_FragColor;\n\ +void main(void)\n\ +{\n\ + if ( 1 == dgl_ClippingEnabled ) {\n\ + for ( int i = 0; i < MAX_CLIP_PLANES; i++ ) {\n\ + if ( 1 == dgl_ClipEnabled[i] )\n\ + if ( dgl_ClipDistance[i] < 0.0 )\n\ + discard;\n\ + }\n\ + }\n\ + if ( 0 == dgl_PointSpriteActive ) {\n\ + if ( 1 == dgl_TexActive )\n\ + dgl_FragColor = dgl_Color * texture2D( textureUnit0, dgl_TexCoord[ 0 ].xy );\n\ + else\n\ + dgl_FragColor = dgl_Color;\n\ + } else\n\ + dgl_FragColor = dgl_Color * texture2D( textureUnit0, gl_PointCoord );\n\ +}\n\ +"; diff --git a/src/eepp/graphics/renderer/shaders/basegl3cp.vert b/src/eepp/graphics/renderer/shaders/basegl3cp.vert new file mode 100644 index 000000000..d0aa32baf --- /dev/null +++ b/src/eepp/graphics/renderer/shaders/basegl3cp.vert @@ -0,0 +1,34 @@ +#ifdef EE_GLES2 +"precision mediump float;\n" +"precision lowp int;\n" +#else +"#version 330\n" +#endif +"#define MAX_CLIP_PLANES 6\n\ +uniform mat4 dgl_ProjectionMatrix;\n\ +uniform mat4 dgl_ModelViewMatrix;\n\ +uniform int dgl_ClippingEnabled;\n\ +uniform int dgl_ClipEnabled[ MAX_CLIP_PLANES ];\n\ +uniform vec4 dgl_ClipPlane[ MAX_CLIP_PLANES ];\n\ +uniform float dgl_PointSize;\n\ +in vec4 dgl_Vertex;\n\ +in vec4 dgl_FrontColor;\n\ +in vec4 dgl_MultiTexCoord0;\n\ +out vec4 dgl_Color;\n\ +out vec4 dgl_TexCoord[ 1 ];\n\ +out float dgl_ClipDistance[ MAX_CLIP_PLANES ];\n\ +void main(void)\n\ +{\n\ + gl_PointSize = dgl_PointSize;\n\ + dgl_Color = dgl_FrontColor;\n\ + dgl_TexCoord[0] = dgl_MultiTexCoord0;\n\ + vec4 vEye = dgl_ModelViewMatrix * dgl_Vertex;\n\ + gl_Position = dgl_ProjectionMatrix * vEye;\n\ + if ( 1 == dgl_ClippingEnabled ) {\n\ + for ( int i = 0; i < MAX_CLIP_PLANES; i++ ) {\n\ + if ( 1 == dgl_ClipEnabled[i] )\n\ + dgl_ClipDistance[i] = dot( vEye, dgl_ClipPlane[i] );\n\ + }\n\ + }\n\ +}\n\ +";