mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-07-23 03:02:50 +03:00
Cleaned up the Core Profile renderer, now use its own shaders.
Some minor fixes.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<eeRectf> mPlanesClipped;
|
||||
private:
|
||||
void WriteExtension( Uint8 Pos, Uint32 BitWrite );
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 2.8.1, 2013-11-03T04:15:15. -->
|
||||
<!-- Written by QtCreator 2.8.1, 2013-11-03T22:20:01. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
35
src/eepp/graphics/renderer/shaders/basegl3cp.frag
Normal file
35
src/eepp/graphics/renderer/shaders/basegl3cp.frag
Normal file
@@ -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\
|
||||
";
|
||||
34
src/eepp/graphics/renderer/shaders/basegl3cp.vert
Normal file
34
src/eepp/graphics/renderer/shaders/basegl3cp.vert
Normal file
@@ -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\
|
||||
";
|
||||
Reference in New Issue
Block a user