mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Some work on the OpenGL 3 renderer.
This commit is contained in:
3
Makefile
3
Makefile
@@ -78,7 +78,7 @@ SRCHAIKUTTF = $(wildcard ./src/helper/haikuttf/*.cpp)
|
||||
SRCBASE = $(wildcard ./src/base/*.cpp)
|
||||
SRCAUDIO = $(wildcard ./src/audio/*.cpp)
|
||||
SRCGAMING = $(wildcard ./src/gaming/*.cpp)
|
||||
SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp)
|
||||
SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp) $(wildcard ./src/graphics/renderer/*.cpp)
|
||||
SRCMATH = $(wildcard ./src/math/*.cpp)
|
||||
SRCSYSTEM = $(wildcard ./src/system/*.cpp)
|
||||
SRCUI = $(wildcard ./src/ui/*.cpp)
|
||||
@@ -153,6 +153,7 @@ dirs:
|
||||
@mkdir -p $(OBJDIR)/src/audio
|
||||
@mkdir -p $(OBJDIR)/src/gaming
|
||||
@mkdir -p $(OBJDIR)/src/graphics
|
||||
@mkdir -p $(OBJDIR)/src/graphics/renderer
|
||||
@mkdir -p $(OBJDIR)/src/math
|
||||
@mkdir -p $(OBJDIR)/src/system
|
||||
@mkdir -p $(OBJDIR)/src/ui
|
||||
|
||||
3
src/ee.h
3
src/ee.h
@@ -90,6 +90,9 @@
|
||||
using namespace EE::Window;
|
||||
|
||||
// Graphics
|
||||
#include "graphics/renderer/cgl.hpp"
|
||||
#include "graphics/renderer/crenderergl.hpp"
|
||||
#include "graphics/renderer/crenderergl3.hpp"
|
||||
#include "graphics/renders.hpp"
|
||||
#include "graphics/cimage.hpp"
|
||||
#include "graphics/ctexture.hpp"
|
||||
|
||||
@@ -85,23 +85,27 @@ void cBatchRenderer::SetBlendMode( EE_DRAW_MODE Mode, const bool& Force ) {
|
||||
}
|
||||
}
|
||||
|
||||
void cBatchRenderer::Flush() {
|
||||
void cBatchRenderer::Flush() {
|
||||
if ( mNumVertex == 0 )
|
||||
return;
|
||||
|
||||
Uint32 NumVertex = mNumVertex;
|
||||
mNumVertex = 0;
|
||||
|
||||
bool CreateMatrix = ( mRotation || mScale != 1.0f || mPosition.x || mPosition.y );
|
||||
|
||||
if ( NULL != mTexture )
|
||||
if ( NULL != mTexture ) {
|
||||
cTextureFactory::instance()->Bind( mTexture );
|
||||
else
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
} else {
|
||||
GLi->Disable( GL_TEXTURE_2D );
|
||||
}
|
||||
|
||||
cTextureFactory::instance()->SetPreBlendFunc( mBlend );
|
||||
|
||||
if ( mCurrentMode == DM_POINTS && NULL != mTexture ) {
|
||||
glEnable( GL_POINT_SPRITE_ARB );
|
||||
GLi->Enable( GL_POINT_SPRITE_ARB );
|
||||
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
|
||||
glPointSize( (GLfloat)mTexture->Width() );
|
||||
GLi->PointSize( (GLfloat)mTexture->Width() );
|
||||
}
|
||||
|
||||
if ( CreateMatrix ) {
|
||||
@@ -116,30 +120,32 @@ void cBatchRenderer::Flush() {
|
||||
GLi->Translatef( -mCenter.x, -mCenter.y, 0.0f);
|
||||
}
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) );
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) );
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) + sizeof(eeTexCoord) );
|
||||
Uint32 alloc = sizeof(GLfloat) * NumVertex * 4 * 2;
|
||||
|
||||
GLi->VertexPointer ( 2, GL_FLOAT , sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) , alloc );
|
||||
GLi->TexCoordPointer( 2, GL_FLOAT , sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) , alloc );
|
||||
GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) + sizeof(eeTexCoord) , alloc );
|
||||
|
||||
#ifdef EE_GLES
|
||||
if ( DM_QUADS == mCurrentMode ) {
|
||||
glDrawArrays( DM_TRIANGLES, 0, mNumVertex );
|
||||
GLi->DrawArrays( DM_TRIANGLES, 0, NumVertex );
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
glDrawArrays( mCurrentMode, 0, mNumVertex );
|
||||
GLi->DrawArrays( mCurrentMode, 0, NumVertex );
|
||||
}
|
||||
|
||||
if ( CreateMatrix )
|
||||
if ( CreateMatrix ) {
|
||||
GLi->PopMatrix();
|
||||
}
|
||||
|
||||
if ( mCurrentMode == DM_POINTS && mTexture > 0 ) {
|
||||
glDisable( GL_POINT_SPRITE_ARB );
|
||||
GLi->Disable( GL_POINT_SPRITE_ARB );
|
||||
}
|
||||
|
||||
if ( mTexture == 0 )
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
|
||||
mNumVertex = 0;
|
||||
if ( mTexture == 0 ) {
|
||||
GLi->Enable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
|
||||
void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle ) {
|
||||
@@ -838,7 +844,7 @@ eeFloat cBatchRenderer::GetLineWidth() {
|
||||
}
|
||||
|
||||
void cBatchRenderer::SetPointSize( const eeFloat& pointSize ) {
|
||||
glPointSize( pointSize );
|
||||
GLi->PointSize( pointSize );
|
||||
}
|
||||
|
||||
eeFloat cBatchRenderer::GetPointSize() {
|
||||
|
||||
@@ -297,14 +297,16 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con
|
||||
numvert = TextCache.CachedVerts();
|
||||
}
|
||||
|
||||
glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast<char*>( &Colors[0] ) );
|
||||
glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast<char*>( &RenderCoords[0] ) );
|
||||
glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast<char*>( &RenderCoords[0] ) + sizeof(eeFloat) * 2 );
|
||||
Uint32 alloc = numvert * sizeof(GLfloat) * 4;
|
||||
|
||||
GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , 0 , reinterpret_cast<char*>( &Colors[0] ) , alloc );
|
||||
GLi->TexCoordPointer( 2, GL_FLOAT , sizeof(eeVertexCoords), reinterpret_cast<char*>( &RenderCoords[0] ) , alloc );
|
||||
GLi->VertexPointer ( 2, GL_FLOAT , sizeof(eeVertexCoords), reinterpret_cast<char*>( &RenderCoords[0] ) + sizeof(eeFloat) * 2 , alloc );
|
||||
|
||||
#ifndef EE_GLES
|
||||
glDrawArrays( GL_QUADS, 0, numvert );
|
||||
GLi->DrawArrays( GL_QUADS, 0, numvert );
|
||||
#else
|
||||
glDrawArrays( GL_TRIANGLES, 0, numvert );
|
||||
GLi->DrawArrays( GL_TRIANGLES, 0, numvert );
|
||||
#endif
|
||||
|
||||
if ( Angle != 0.0f || Scale != 1.0f ) {
|
||||
@@ -466,14 +468,16 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat&
|
||||
}
|
||||
}
|
||||
|
||||
glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast<char*>( &mColors[0] ) );
|
||||
glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast<char*>( &mRenderCoords[0] ) );
|
||||
glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast<char*>( &mRenderCoords[0] ) + sizeof(eeFloat) * 2 );
|
||||
Uint32 alloc = numvert * sizeof(GLfloat) * 4;
|
||||
|
||||
GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , 0 , reinterpret_cast<char*>( &mColors[0] ) , alloc );
|
||||
GLi->TexCoordPointer ( 2, GL_FLOAT , sizeof(eeVertexCoords), reinterpret_cast<char*>( &mRenderCoords[0] ) , alloc );
|
||||
GLi->VertexPointer ( 2, GL_FLOAT , sizeof(eeVertexCoords), reinterpret_cast<char*>( &mRenderCoords[0] ) + sizeof(eeFloat) * 2 , alloc );
|
||||
|
||||
#ifndef EE_GLES
|
||||
glDrawArrays( GL_QUADS, 0, numvert );
|
||||
GLi->DrawArrays( GL_QUADS, 0, numvert );
|
||||
#else
|
||||
glDrawArrays( GL_TRIANGLES, 0, numvert );
|
||||
GLi->DrawArrays( GL_TRIANGLES, 0, numvert );
|
||||
#endif
|
||||
|
||||
if ( Angle != 0.0f || Scale != 1.0f )
|
||||
|
||||
@@ -49,8 +49,8 @@ eeColorAf cFrameBuffer::ClearColor() const {
|
||||
}
|
||||
|
||||
void cFrameBuffer::Clear() {
|
||||
glClearColor( mClearColor.R(), mClearColor.G(), mClearColor.B(), mClearColor.A() );
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
GLi->ClearColor( mClearColor.R(), mClearColor.G(), mClearColor.B(), mClearColor.A() );
|
||||
GLi->Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
cEngine::instance()->SetBackColor( cEngine::instance()->GetBackColor() );
|
||||
}
|
||||
|
||||
|
||||
@@ -262,17 +262,19 @@ void cParticleSystem::Draw() {
|
||||
TF->Bind( mTexId );
|
||||
TF->SetPreBlendFunc( ALPHA_BLENDONE );
|
||||
|
||||
if ( mPointsSup ) {
|
||||
glEnable( GL_POINT_SPRITE_ARB );
|
||||
if ( mPointsSup && GLi->Version() != GLv_3 ) {
|
||||
GLi->Enable( GL_POINT_SPRITE_ARB );
|
||||
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
|
||||
glPointSize( mSize );
|
||||
GLi->PointSize( mSize );
|
||||
|
||||
glColorPointer( 4, GL_FLOAT, sizeof(cParticle), reinterpret_cast<char*>( &mParticle[0] ) + sizeof(eeFloat) * 2 );
|
||||
glVertexPointer( 2, GL_FLOAT, sizeof(cParticle), reinterpret_cast<char*>( &mParticle[0] ) );
|
||||
Uint32 alloc = mPCount * sizeof(GLfloat) * 4 * 2;
|
||||
|
||||
glDrawArrays( GL_POINTS, 0, (GLsizei)mPCount );
|
||||
GLi->ColorPointer ( 4, GL_FLOAT, sizeof(cParticle), reinterpret_cast<char*>( &mParticle[0] ) + sizeof(eeFloat) * 2 , alloc );
|
||||
GLi->VertexPointer ( 2, GL_FLOAT, sizeof(cParticle), reinterpret_cast<char*>( &mParticle[0] ) , alloc );
|
||||
|
||||
glDisable( GL_POINT_SPRITE_ARB );
|
||||
GLi->DrawArrays( GL_POINTS, 0, (GLsizei)mPCount );
|
||||
|
||||
GLi->Disable( GL_POINT_SPRITE_ARB );
|
||||
} else {
|
||||
cTexture * Tex = TF->GetTexture( mTexId );
|
||||
|
||||
|
||||
@@ -298,7 +298,6 @@ void cPrimitives::DrawCircle(const eeVector2f& p, const eeFloat& radius, Uint32
|
||||
|
||||
void cPrimitives::SetColor( const eeColorA& Color ) {
|
||||
mColor = Color;
|
||||
glColor4ub( mColor.R(), mColor.G(), mColor.B(), mColor.A() );
|
||||
}
|
||||
|
||||
void cPrimitives::DrawTriangle(const eeTriangle2f& t, const EE_FILL_MODE& fillmode, const EE_PRE_BLEND_FUNC& blend, const eeFloat& lineWidth) {
|
||||
|
||||
@@ -28,7 +28,7 @@ cShader::cShader( const Uint32& Type, const std::string& Filename ) {
|
||||
Compile();
|
||||
}
|
||||
|
||||
cShader::cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize ) {
|
||||
cShader::cShader( const Uint32& Type, const char * Data, const Uint32& DataSize ) {
|
||||
Init( Type );
|
||||
|
||||
SetSource( Data, DataSize );
|
||||
@@ -44,12 +44,20 @@ cShader::cShader( const Uint32& Type, cPack * Pack, const std::string& Filename
|
||||
|
||||
Pack->ExtractFileToMemory( Filename, TempData );
|
||||
|
||||
SetSource( reinterpret_cast<Uint8*> ( &TempData[0] ), (Uint32)TempData.size() );
|
||||
SetSource( reinterpret_cast<char*> ( &TempData[0] ), (Uint32)TempData.size() );
|
||||
}
|
||||
|
||||
Compile();
|
||||
}
|
||||
|
||||
cShader::cShader( const Uint32& Type, const char ** Data, const Uint32& NumLines ) {
|
||||
Init( Type );
|
||||
|
||||
SetSource( Data, NumLines );
|
||||
|
||||
Compile();
|
||||
}
|
||||
|
||||
cShader::~cShader() {
|
||||
if ( 0 != mGLId )
|
||||
glDeleteShader( mGLId );
|
||||
@@ -83,7 +91,17 @@ void cShader::SetSource( const std::string& Source ) {
|
||||
glShaderSource( mGLId, 1, &src, NULL );
|
||||
}
|
||||
|
||||
void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) {
|
||||
void cShader::SetSource( const char** Data, const Uint32& NumLines ) {
|
||||
std::string tstr;
|
||||
|
||||
for ( Uint32 i = 0; i < NumLines; i++ ) {
|
||||
tstr += std::string( Data[i] );
|
||||
}
|
||||
|
||||
SetSource( tstr );
|
||||
}
|
||||
|
||||
void cShader::SetSource( const char * Data, const Uint32& DataSize ) {
|
||||
std::string _dst( DataSize, 0 );
|
||||
|
||||
memcpy( reinterpret_cast<void*>( &_dst[0] ), reinterpret_cast<const void*>( &Data[0] ), DataSize );
|
||||
@@ -123,6 +141,12 @@ bool cShader::Compile() {
|
||||
cLog::instance()->Write( "Couldn't compile shader. Log follows:" );
|
||||
cLog::instance()->Write( mCompileLog );
|
||||
cLog::instance()->Write( mSource );
|
||||
|
||||
#ifdef EE_DEBUG
|
||||
std::cout << "Couldn't compile shader. Log follows:" << std::endl;
|
||||
std::cout << mCompileLog << std::endl;
|
||||
std::cout << mSource << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
cLog::instance()->Write( "Shader Loaded Succesfully" );
|
||||
}
|
||||
@@ -140,7 +164,7 @@ cVertexShader::cVertexShader( const std::string& Filename ) :
|
||||
{
|
||||
}
|
||||
|
||||
cVertexShader::cVertexShader( const Uint8 * Data, const Uint32& DataSize ) :
|
||||
cVertexShader::cVertexShader( const char * Data, const Uint32& DataSize ) :
|
||||
cShader( GL_VERTEX_SHADER, Data, DataSize )
|
||||
{
|
||||
}
|
||||
@@ -150,6 +174,11 @@ cVertexShader::cVertexShader( cPack * Pack, const std::string& Filename ) :
|
||||
{
|
||||
}
|
||||
|
||||
cVertexShader::cVertexShader( const char ** Data, const Uint32& NumLines ) :
|
||||
cShader( GL_VERTEX_SHADER, Data, NumLines )
|
||||
{
|
||||
}
|
||||
|
||||
cFragmentShader::cFragmentShader() :
|
||||
cShader( GL_FRAGMENT_SHADER )
|
||||
{
|
||||
@@ -160,7 +189,7 @@ cFragmentShader::cFragmentShader( const std::string& Filename ) :
|
||||
{
|
||||
}
|
||||
|
||||
cFragmentShader::cFragmentShader( const Uint8 * Data, const Uint32& DataSize ) :
|
||||
cFragmentShader::cFragmentShader( const char * Data, const Uint32& DataSize ) :
|
||||
cShader( GL_FRAGMENT_SHADER, Data, DataSize )
|
||||
{
|
||||
}
|
||||
@@ -170,4 +199,9 @@ cFragmentShader::cFragmentShader( cPack * Pack, const std::string& Filename ) :
|
||||
{
|
||||
}
|
||||
|
||||
cFragmentShader::cFragmentShader( const char ** Data, const Uint32& NumLines ) :
|
||||
cShader( GL_FRAGMENT_SHADER, Data, NumLines )
|
||||
{
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -15,11 +15,14 @@ class EE_API cShader {
|
||||
cShader( const Uint32& Type, const std::string& Filename );
|
||||
|
||||
/** Create a type of shader from memory, and compile it. */
|
||||
cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize );
|
||||
cShader( const Uint32& Type, const char * Data, const Uint32& DataSize );
|
||||
|
||||
/** Create a type of shader loaded from a pack file */
|
||||
cShader( const Uint32& Type, cPack * Pack, const std::string& Filename );
|
||||
|
||||
/** Create a type of shader from memory, and compile it. */
|
||||
cShader( const Uint32& Type, const char ** Data, const Uint32& NumLines );
|
||||
|
||||
virtual ~cShader();
|
||||
|
||||
/** Set the shader source */
|
||||
@@ -29,7 +32,10 @@ class EE_API cShader {
|
||||
void SetSource( const std::vector<Uint8>& Source );
|
||||
|
||||
/** Set the shader source */
|
||||
void SetSource( const Uint8 * Data, const Uint32& DataSize );
|
||||
void SetSource( const char * Data, const Uint32& DataSize );
|
||||
|
||||
/** Set the shader source */
|
||||
void SetSource( const char** Data, const Uint32& NumLines );
|
||||
|
||||
/** Compile the shader */
|
||||
bool Compile();
|
||||
@@ -47,9 +53,9 @@ class EE_API cShader {
|
||||
Uint32 GetType() const { return mType; }
|
||||
|
||||
/** @return The Shader Id */
|
||||
Uint32 GetId() const { return mGLId; }
|
||||
|
||||
/** Reloads the Shader. */
|
||||
Uint32 GetId() const { return mGLId; }
|
||||
|
||||
/** Reloads the Shader. */
|
||||
void Reload();
|
||||
protected:
|
||||
GLuint mGLId;
|
||||
@@ -57,7 +63,7 @@ class EE_API cShader {
|
||||
bool mValid;
|
||||
bool mCompiled;
|
||||
std::string mCompileLog;
|
||||
std::string mSource;
|
||||
std::string mSource;
|
||||
|
||||
void Init( const Uint32& Type );
|
||||
};
|
||||
@@ -67,8 +73,9 @@ class EE_API cVertexShader : public cShader {
|
||||
public:
|
||||
cVertexShader();
|
||||
cVertexShader( const std::string& Filename );
|
||||
cVertexShader( const Uint8 * Data, const Uint32& DataSize );
|
||||
cVertexShader( const char * Data, const Uint32& DataSize );
|
||||
cVertexShader( cPack * Pack, const std::string& Filename );
|
||||
cVertexShader( const char ** Data, const Uint32& NumLines );
|
||||
};
|
||||
|
||||
/** @brief Prebuild Fragment Shader class */
|
||||
@@ -76,8 +83,9 @@ class EE_API cFragmentShader : public cShader {
|
||||
public:
|
||||
cFragmentShader();
|
||||
cFragmentShader( const std::string& Filename );
|
||||
cFragmentShader( const Uint8 * Data, const Uint32& DataSize );
|
||||
cFragmentShader( const char * Data, const Uint32& DataSize );
|
||||
cFragmentShader( cPack * Pack, const std::string& Filename );
|
||||
cFragmentShader( const char ** Data, const Uint32& NumLines );
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -71,7 +71,7 @@ cShaderProgram::cShaderProgram( cPack * Pack, const std::string& VertexShaderPat
|
||||
}
|
||||
}
|
||||
|
||||
cShaderProgram::cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name ) :
|
||||
cShaderProgram::cShaderProgram( const char * VertexShaderData, const Uint32& VertexShaderDataSize, const char * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name ) :
|
||||
mHandler(0),
|
||||
mId(0)
|
||||
{
|
||||
@@ -93,6 +93,28 @@ cShaderProgram::cShaderProgram( const Uint8 * VertexShaderData, const Uint32& Ve
|
||||
Link();
|
||||
}
|
||||
|
||||
cShaderProgram::cShaderProgram( const char ** VertexShaderData, const Uint32& NumLinesVS, const char ** FragmentShaderData, const Uint32& NumLinesFS, const std::string& name ) :
|
||||
mHandler(0),
|
||||
mId(0)
|
||||
{
|
||||
AddToManager( name );
|
||||
Init();
|
||||
|
||||
cVertexShader * vs = eeNew( cVertexShader, ( VertexShaderData, NumLinesVS ) );
|
||||
cFragmentShader * fs = eeNew( cFragmentShader, ( FragmentShaderData, NumLinesFS ) );
|
||||
|
||||
if ( !vs->IsValid() || !fs->IsValid() ) {
|
||||
eeSAFE_DELETE( vs );
|
||||
eeSAFE_DELETE( fs );
|
||||
return;
|
||||
}
|
||||
|
||||
AddShader( vs );
|
||||
AddShader( fs );
|
||||
|
||||
Link();
|
||||
}
|
||||
|
||||
cShaderProgram::~cShaderProgram() {
|
||||
if ( Handler() > 0 )
|
||||
glDeleteProgram( Handler() );
|
||||
@@ -183,12 +205,14 @@ bool cShaderProgram::Link() {
|
||||
|
||||
void cShaderProgram::Bind() const {
|
||||
cGlobalBatchRenderer::instance()->Draw();
|
||||
glUseProgram( Handler() );
|
||||
|
||||
GLi->SetShader( const_cast<cShaderProgram*>( this ) );
|
||||
}
|
||||
|
||||
void cShaderProgram::Unbind() const {
|
||||
cGlobalBatchRenderer::instance()->Draw();
|
||||
glUseProgram( 0 );
|
||||
|
||||
GLi->SetShader( NULL );
|
||||
}
|
||||
|
||||
Int32 cShaderProgram::UniformLocation( const std::string& Name ) {
|
||||
@@ -256,13 +280,13 @@ bool cShaderProgram::SetUniform( const std::string& Name, Int32 Value ) {
|
||||
return ( Location >= 0 );
|
||||
}
|
||||
|
||||
bool SetUniformMatrix( const Int32& Id, const eeFloat * Value ) {
|
||||
bool cShaderProgram::SetUniformMatrix( const Int32& Id, const float * Value ) {
|
||||
glUniformMatrix4fv( Id, 1, false, Value );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cShaderProgram::SetUniformMatrix( const std::string Name, const eeFloat * Value ) {
|
||||
bool cShaderProgram::SetUniformMatrix( const std::string Name, const float * Value ) {
|
||||
Int32 Location = UniformLocation( Name );
|
||||
|
||||
if ( Location >= 0 )
|
||||
|
||||
@@ -21,11 +21,13 @@ class EE_API cShaderProgram {
|
||||
cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& name = "" );
|
||||
|
||||
/** Constructor that creates a VertexShader from memory and a Fragment Shader from memory, and link them. */
|
||||
cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name = "" );
|
||||
cShaderProgram( const char * VertexShaderData, const Uint32& VertexShaderDataSize, const char * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name = "" );
|
||||
|
||||
/** Constructor that creates the vertex shader and fragment shader from two files inside a pack */
|
||||
cShaderProgram( cPack * Pack, const std::string& VertexShaderPath, const std::string& FragmentShaderPath, const std::string& name = "" );
|
||||
|
||||
cShaderProgram( const char ** VertexShaderData, const Uint32& NumLinesVS, const char ** FragmentShaderData, const Uint32& NumLinesFS, const std::string& name = "" );
|
||||
|
||||
virtual ~cShaderProgram();
|
||||
|
||||
/** Add a new shader */
|
||||
@@ -72,9 +74,9 @@ class EE_API cShaderProgram {
|
||||
/** @overload */
|
||||
bool SetUniform( const std::string& Name, Int32 Value );
|
||||
|
||||
bool SetUniformMatrix( const std::string Name, const eeFloat * Value );
|
||||
bool SetUniformMatrix( const std::string Name, const float * Value );
|
||||
|
||||
bool SetUniformMatrix( const Int32& Id, const eeFloat * Value );
|
||||
bool SetUniformMatrix( const Int32& Id, const float * Value );
|
||||
|
||||
/** @return The id of the program (the handle) */
|
||||
const Uint32& Handler() const { return mHandler; }
|
||||
|
||||
@@ -102,7 +102,7 @@ void cTextureFactory::Bind( const cTexture* Tex, const Uint32& TextureUnit ) {
|
||||
if ( GLi->IsExtension( EEGL_ARB_multitexture ) )
|
||||
SetActiveTextureUnit( TextureUnit );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, Tex->Handle() );
|
||||
GLi->BindTexture( GL_TEXTURE_2D, Tex->Handle() );
|
||||
|
||||
mCurrentTexture[ TextureUnit ] = Tex->Handle();
|
||||
|
||||
@@ -201,9 +201,9 @@ void cTextureFactory::UngrabTextures() {
|
||||
}
|
||||
|
||||
void cTextureFactory::SetBlendFunc( const EE_BLEND_FUNC& SrcFactor, const EE_BLEND_FUNC& DestFactor ) {
|
||||
glEnable( GL_BLEND );
|
||||
GLi->Enable( GL_BLEND );
|
||||
|
||||
glBlendFunc( (GLenum)SrcFactor, (GLenum)DestFactor );
|
||||
GLi->BlendFunc( (GLenum)SrcFactor, (GLenum)DestFactor );
|
||||
|
||||
mLastBlend = ALPHA_CUSTOM;
|
||||
}
|
||||
@@ -211,33 +211,33 @@ void cTextureFactory::SetBlendFunc( const EE_BLEND_FUNC& SrcFactor, const EE_BLE
|
||||
void cTextureFactory::SetPreBlendFunc( const EE_PRE_BLEND_FUNC& blend, bool force ) {
|
||||
if ( mLastBlend != blend || force ) {
|
||||
if (blend == ALPHA_NONE) {
|
||||
glDisable( GL_BLEND );
|
||||
GLi->Disable( GL_BLEND );
|
||||
} else {
|
||||
glEnable( GL_BLEND );
|
||||
GLi->Enable( GL_BLEND );
|
||||
|
||||
switch (blend) {
|
||||
case ALPHA_NORMAL:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case ALPHA_BLENDONE:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_ONE);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_ONE);
|
||||
break;
|
||||
case ALPHA_BLENDTWO:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA);
|
||||
glBlendFunc(GL_DST_ALPHA , GL_ONE);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA);
|
||||
GLi->BlendFunc(GL_DST_ALPHA , GL_ONE);
|
||||
break;
|
||||
case ALPHA_BLENDTHREE:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_ONE);
|
||||
glBlendFunc(GL_DST_ALPHA , GL_SRC_ALPHA);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_ONE);
|
||||
GLi->BlendFunc(GL_DST_ALPHA , GL_SRC_ALPHA);
|
||||
break;
|
||||
case ALPHA_ALPHACHANNELS:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA);
|
||||
break;
|
||||
case ALPHA_DESTALPHA:
|
||||
glBlendFunc(GL_SRC_ALPHA , GL_DST_ALPHA);
|
||||
GLi->BlendFunc(GL_SRC_ALPHA , GL_DST_ALPHA);
|
||||
break;
|
||||
case ALPHA_MULTIPLY:
|
||||
glBlendFunc(GL_DST_COLOR,GL_ZERO);
|
||||
GLi->BlendFunc(GL_DST_COLOR,GL_ZERO);
|
||||
break;
|
||||
case ALPHA_NONE:
|
||||
// AVOID COMPILER WARNING
|
||||
@@ -253,7 +253,7 @@ void cTextureFactory::SetPreBlendFunc( const EE_PRE_BLEND_FUNC& blend, bool forc
|
||||
}
|
||||
|
||||
void cTextureFactory::SetActiveTextureUnit( const Uint32& Unit ) {
|
||||
glActiveTextureARB( GL_TEXTURE0_ARB + Unit );
|
||||
GLi->ActiveTexture( GL_TEXTURE0_ARB + Unit );
|
||||
}
|
||||
|
||||
void cTextureFactory::SetTextureConstantColor( const eeColorA& Color ) {
|
||||
|
||||
@@ -152,7 +152,7 @@ void cVertexBuffer::Unbind() {
|
||||
|
||||
if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 ) ) {
|
||||
//glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
GLi->Enable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,27 +26,30 @@ void cVertexBufferOGL::Draw() {
|
||||
if( mElemDraw < 0 )
|
||||
lSize = GetIndexCount();
|
||||
|
||||
glDrawElements( mDrawType, lSize, GL_UNSIGNED_INT, &mIndexArray[0] );
|
||||
GLi->DrawElements( mDrawType, lSize, GL_UNSIGNED_INT, &mIndexArray[0] );
|
||||
} else {
|
||||
glDrawArrays( mDrawType, 0, GetVertexCount() );
|
||||
GLi->DrawArrays( mDrawType, 0, GetVertexCount() );
|
||||
}
|
||||
}
|
||||
|
||||
void cVertexBufferOGL::SetVertexStates() {
|
||||
Uint32 alloc = GetVertexCount() * sizeof(GLfloat) * 2;
|
||||
Uint32 allocC = GetVertexCount() * sizeof(GLfloat) * 4;
|
||||
|
||||
/// POSITION
|
||||
if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) {
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glVertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_POSITION ], &mVertexArray[ VERTEX_FLAG_POSITION ][0] );
|
||||
GLi->EnableClientState( GL_VERTEX_ARRAY );
|
||||
GLi->VertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_POSITION ], &mVertexArray[ VERTEX_FLAG_POSITION ][0], alloc );
|
||||
} else {
|
||||
//glDisableClientState( GL_VERTEX_ARRAY );
|
||||
//GLi->DisableClientState( GL_VERTEX_ARRAY );
|
||||
}
|
||||
|
||||
/// COLOR
|
||||
if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) {
|
||||
glEnableClientState( GL_COLOR_ARRAY );
|
||||
glColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, sizeof(Uint8) * eeVertexElements[ VERTEX_FLAG_COLOR ], &mColorArray[0] );
|
||||
GLi->EnableClientState( GL_COLOR_ARRAY );
|
||||
GLi->ColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, sizeof(Uint8) * eeVertexElements[ VERTEX_FLAG_COLOR ], &mColorArray[0], allocC );
|
||||
} else {
|
||||
//glDisableClientState( GL_COLOR_ARRAY );
|
||||
//GLi->DisableClientState( GL_COLOR_ARRAY );
|
||||
}
|
||||
|
||||
/// TEXTURES
|
||||
@@ -54,25 +57,25 @@ void cVertexBufferOGL::SetVertexStates() {
|
||||
for ( Int32 i = 0; i < 5; i++ ) {
|
||||
if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) {
|
||||
glClientActiveTextureARB( GL_TEXTURE0_ARB + i );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
|
||||
glTexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], &mVertexArray[ VERTEX_FLAG_TEXTURE0 + i ][0] );
|
||||
GLi->TexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], &mVertexArray[ VERTEX_FLAG_TEXTURE0 + i ][0], alloc );
|
||||
} else {
|
||||
//glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
//GLi->DisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 ) ) {
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glTexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], &mVertexArray[ VERTEX_FLAG_TEXTURE0 ][0] );
|
||||
GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->TexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], &mVertexArray[ VERTEX_FLAG_TEXTURE0 ][0], alloc );
|
||||
} else {
|
||||
//glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
//GLi->DisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->Disable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
|
||||
glActiveTextureARB( GL_TEXTURE0_ARB );
|
||||
GLi->ActiveTexture( GL_TEXTURE0_ARB );
|
||||
glClientActiveTextureARB( GL_TEXTURE0_ARB );
|
||||
}
|
||||
|
||||
|
||||
@@ -89,11 +89,11 @@ void cVertexBufferVBO::Draw() {
|
||||
|
||||
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mElementHandle );
|
||||
|
||||
glDrawElements( mDrawType, lSize, GL_UNSIGNED_INT, (char*)NULL );
|
||||
GLi->DrawElements( mDrawType, lSize, GL_UNSIGNED_INT, (char*)NULL );
|
||||
|
||||
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
|
||||
} else {
|
||||
glDrawArrays( mDrawType, 0, GetVertexCount() );
|
||||
GLi->DrawArrays( mDrawType, 0, GetVertexCount() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ void cVertexBufferVBO::SetVertexStates() {
|
||||
glTexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], GL_FLOAT, 0, (char*)NULL );
|
||||
} else {
|
||||
//glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
GLi->Disable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
#include "../base.hpp"
|
||||
#include "../renders.hpp"
|
||||
|
||||
//#define EE_GL3_ENABLED
|
||||
#define EE_GL3_ENABLED 1
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,9 +12,9 @@ cGL * cGL::CreateSingleton() {
|
||||
if ( ms_singleton == 0 ) {
|
||||
#ifdef EE_GL3_ENABLED
|
||||
/** Implement an OpenGL3 compilant renderer */
|
||||
if ( '3' == glGetString(GL_VERSION)[0] )
|
||||
/*if ( '3' == glGetString(GL_VERSION)[0] )
|
||||
ms_singleton = eeNew( cRendererGL3, () );
|
||||
else
|
||||
else*/
|
||||
#endif
|
||||
ms_singleton = eeNew( cRendererGL, () );
|
||||
}
|
||||
@@ -188,4 +188,56 @@ void cGL::Enable( GLenum cap ) {
|
||||
glEnable( cap );
|
||||
}
|
||||
|
||||
char * cGL::GetString( GLenum name ) {
|
||||
return (char*)glGetString( name );
|
||||
}
|
||||
|
||||
void cGL::Clear ( GLbitfield mask ) {
|
||||
glClear( mask );
|
||||
}
|
||||
|
||||
void cGL::ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) {
|
||||
glClearColor( red, green, blue, alpha );
|
||||
}
|
||||
|
||||
void cGL::Scissor ( GLint x, GLint y, GLsizei width, GLsizei height ) {
|
||||
glScissor( x, y, width, height );
|
||||
}
|
||||
|
||||
void cGL::PolygonMode( GLenum face, GLenum mode ) {
|
||||
glPolygonMode( face, mode );
|
||||
}
|
||||
|
||||
void cGL::PointSize( GLfloat size ) {
|
||||
glPointSize( size );
|
||||
}
|
||||
|
||||
void cGL::DrawArrays (GLenum mode, GLint first, GLsizei count) {
|
||||
glDrawArrays( mode, first, count );
|
||||
}
|
||||
|
||||
void cGL::DrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices ) {
|
||||
glDrawElements( mode, count, type, indices );
|
||||
}
|
||||
|
||||
void cGL::BindTexture ( GLenum target, GLuint texture ) {
|
||||
glBindTexture( target, texture );
|
||||
}
|
||||
|
||||
void cGL::ActiveTexture( GLenum texture ) {
|
||||
glActiveTexture( texture );
|
||||
}
|
||||
|
||||
void cGL::BlendFunc ( GLenum sfactor, GLenum dfactor ) {
|
||||
glBlendFunc( sfactor, dfactor );
|
||||
}
|
||||
|
||||
void cGL::SetShader( cShaderProgram * Shader ) {
|
||||
if ( NULL != Shader ) {
|
||||
glUseProgram( Shader->Handler() );
|
||||
} else {
|
||||
glUseProgram( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define EE_GRAPHICS_CGL_HPP
|
||||
|
||||
#include "base.hpp"
|
||||
#include "../cshaderprogram.hpp"
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
@@ -19,6 +20,17 @@ enum EEGL_extensions {
|
||||
EEGL_ARB_vertex_buffer_object
|
||||
};
|
||||
|
||||
/** Just for reference */
|
||||
enum EEGL_ARRAY_STATES {
|
||||
EEGL_VERTEX_ARRAY = 0,
|
||||
EEGL_NORMAL_ARRAY = 1,
|
||||
EEGL_COLOR_ARRAY = 2,
|
||||
EEGL_INDEX_ARRAY = 3,
|
||||
EEGL_TEXTURE_COORD_ARRAY = 4,
|
||||
EEGL_EDGE_FLAG_ARRAY = 5,
|
||||
EEGL_ARRAY_STATES_SIZE
|
||||
};
|
||||
|
||||
enum EEGL_version {
|
||||
GLv_2,
|
||||
GLv_3,
|
||||
@@ -58,13 +70,35 @@ class cGL {
|
||||
|
||||
Uint32 GetTextureOpEnum( const EE_TEXTURE_OP& Type );
|
||||
|
||||
void Clear ( GLbitfield mask );
|
||||
|
||||
void ClearColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
|
||||
|
||||
void Scissor ( GLint x, GLint y, GLsizei width, GLsizei height );
|
||||
|
||||
void PolygonMode( GLenum face, GLenum mode );
|
||||
|
||||
char * GetExtensions();
|
||||
|
||||
char * GetString( GLenum name );
|
||||
|
||||
void PointSize( GLfloat size );
|
||||
|
||||
void DrawArrays (GLenum mode, GLint first, GLsizei count);
|
||||
|
||||
void DrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices );
|
||||
|
||||
void BindTexture ( GLenum target, GLuint texture );
|
||||
|
||||
void ActiveTexture( GLenum texture );
|
||||
|
||||
void BlendFunc ( GLenum sfactor, GLenum dfactor );
|
||||
|
||||
void Viewport ( GLint x, GLint y, GLsizei width, GLsizei height );
|
||||
|
||||
void Disable ( GLenum cap );
|
||||
virtual void Disable ( GLenum cap );
|
||||
|
||||
void Enable( GLenum cap );
|
||||
virtual void Enable( GLenum cap );
|
||||
|
||||
virtual EEGL_version Version() = 0;
|
||||
|
||||
@@ -80,10 +114,25 @@ class cGL {
|
||||
|
||||
virtual void Scalef( GLfloat x, GLfloat y, GLfloat z ) = 0;
|
||||
|
||||
virtual void MatrixMode (GLenum mode) = 0;
|
||||
virtual void MatrixMode ( GLenum mode ) = 0;
|
||||
|
||||
virtual void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) = 0;
|
||||
virtual void Ortho ( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ) = 0;
|
||||
|
||||
virtual void LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ ) = 0;
|
||||
|
||||
virtual void Perspective ( GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar ) = 0;
|
||||
|
||||
virtual void EnableClientState( GLenum array ) = 0;
|
||||
|
||||
virtual void DisableClientState( GLenum array ) = 0;
|
||||
|
||||
virtual void VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) = 0;
|
||||
|
||||
virtual void ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) = 0;
|
||||
|
||||
virtual void TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) = 0;
|
||||
|
||||
virtual void SetShader( cShaderProgram * Shader );
|
||||
protected:
|
||||
Uint32 mExtensions;
|
||||
private:
|
||||
|
||||
@@ -40,8 +40,36 @@ void cRendererGL::MatrixMode(GLenum mode) {
|
||||
glMatrixMode( mode );
|
||||
}
|
||||
|
||||
void cRendererGL::Ortho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) {
|
||||
void cRendererGL::Ortho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ) {
|
||||
glOrtho( left, right, bottom, top, zNear, zFar );
|
||||
}
|
||||
|
||||
}}
|
||||
void cRendererGL::LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ ) {
|
||||
gluLookAt( eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ );
|
||||
}
|
||||
|
||||
void cRendererGL::Perspective ( GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar ) {
|
||||
gluPerspective( fovy, aspect, zNear, zFar );
|
||||
}
|
||||
|
||||
void cRendererGL::EnableClientState( GLenum array ) {
|
||||
glEnableClientState( array );
|
||||
}
|
||||
|
||||
void cRendererGL::DisableClientState( GLenum array ) {
|
||||
glDisableClientState( array );
|
||||
}
|
||||
|
||||
void cRendererGL::VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) {
|
||||
glVertexPointer( size, type, stride, pointer );
|
||||
}
|
||||
|
||||
void cRendererGL::ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) {
|
||||
glColorPointer( size, type, stride, pointer );
|
||||
}
|
||||
|
||||
void cRendererGL::TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) {
|
||||
glTexCoordPointer( size, type, stride, pointer );
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -27,8 +27,21 @@ class cRendererGL : public cGL {
|
||||
|
||||
void MatrixMode (GLenum mode);
|
||||
|
||||
void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar );
|
||||
void Ortho ( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar );
|
||||
|
||||
void LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ );
|
||||
|
||||
void Perspective ( GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar );
|
||||
|
||||
void EnableClientState( GLenum array );
|
||||
|
||||
void DisableClientState( GLenum array );
|
||||
|
||||
void VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
|
||||
void ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
|
||||
void TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
@@ -4,74 +4,130 @@
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
const GLchar *g_vertexShader[] = {"#version 130\n",
|
||||
"uniform mat4 glm_ProjectionMatrix;\n", // replaces deprecated gl_ProjectionMatrix see http://www.lighthouse3d.com/opengl/glsl/index.php?minimal
|
||||
"uniform mat4 glm_ModelViewMatrix;\n", // replaces deprecated gl_ModelViewMatrix
|
||||
"in vec4 dgl_Vertex;\n", // replaces deprecated gl_Vertex
|
||||
"in vec4 dgl_Color;\n", // replaces deprecated gl_Color
|
||||
"invariant out vec4 Color;\n", // to fragment shader
|
||||
const GLchar *g_vertexShader[] = {"#version 330\n",
|
||||
"uniform mat4 glm_ProjectionMatrix;\n", // replaces deprecated gl_ProjectionMatrix
|
||||
"uniform mat4 glm_ModelViewMatrix;\n", // replaces deprecated gl_ModelViewMatrix
|
||||
"layout(location = 0) in vec2 dgl_Vertex;\n", // replaces deprecated gl_Vertex
|
||||
"layout(location = 2) in vec4 dgl_Color;\n", // replaces deprecated gl_Color
|
||||
"layout(location = 4) in vec2 dgl_TexCoord;\n", // replaces deprecated gl_TexCoord
|
||||
"invariant out vec4 Color;\n", // to fragment shader
|
||||
"invariant out vec2 TexCoord;\n", // to fragment shader
|
||||
"void main(void)\n",
|
||||
"{\n",
|
||||
" Color = dgl_Color;\n",
|
||||
" gl_Position = glm_ProjectionMatrix*glm_ModelViewMatrix*dgl_Vertex;\n", // replaces deprecated ftransform() see http://www.songho.ca/opengl/gl_transform.html
|
||||
" gl_TexCoord[0] = gl_MultiTexCoord0;\n",
|
||||
" Color = dgl_Color;\n",
|
||||
" TexCoord = dgl_TexCoord;\n",
|
||||
" vec4 v4 = vec4( dgl_Vertex.x, dgl_Vertex.y, 0.0, 1.0 );\n",
|
||||
" gl_Position = glm_ProjectionMatrix * glm_ModelViewMatrix * v4;\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
const GLchar *g_fragmentShader[] = {"#version 130\n",
|
||||
"invariant in vec4 Color;\n", // from vertex shader
|
||||
"out vec4 dgl_FragColor;\n", // replaces deprecated gl_FragColor
|
||||
const GLchar *g_fragmentShader[] = {"#version 330\n",
|
||||
"uniform int glm_TexActive = 1;\n",
|
||||
"invariant in vec4 Color;\n",
|
||||
"invariant in vec2 TexCoord;\n",
|
||||
"out vec4 dgl_FragColor;\n",
|
||||
"uniform sampler2D textureUnit0;\n",
|
||||
"void main(void)\n",
|
||||
"{\n",
|
||||
" dgl_FragColor = Color;\n", // gl_FragColor is deprecated
|
||||
" if ( 1 == glm_TexActive )\n",
|
||||
" dgl_FragColor = Color * texture2D( textureUnit0, TexCoord );\n",
|
||||
" else\n",
|
||||
" dgl_FragColor = Color;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
cRendererGL3::cRendererGL3() :
|
||||
shader_id(0),
|
||||
glm_ProjectionMatrix_id(0),
|
||||
glm_ModelViewMatrix_id(0),
|
||||
mCurrentMode(0)
|
||||
mCurrentMode(0),
|
||||
mCurShader(NULL)
|
||||
{
|
||||
glm_ProjectionMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
|
||||
glm_ModelViewMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix
|
||||
}
|
||||
|
||||
cRendererGL3::~cRendererGL3() {
|
||||
for ( Uint32 i = 0; i < eeARRAY_SIZE( mVBO ); i++ ) {
|
||||
if ( 0 != mVBO[i] ) {
|
||||
glDeleteBuffers( 1, &mVBO[i] );
|
||||
}
|
||||
}
|
||||
|
||||
glDeleteVertexArrays( 1, &mVAO );
|
||||
}
|
||||
|
||||
EEGL_version cRendererGL3::Version() {
|
||||
return GLv_3;
|
||||
}
|
||||
|
||||
GLuint cRendererGL3::BaseShaderId() {
|
||||
return mCurShader->Handler();
|
||||
}
|
||||
|
||||
void cRendererGL3::SetShader( cShaderProgram * Shader ) {
|
||||
if ( NULL == Shader ) {
|
||||
Shader = mShaders[ EEGL_SHADER_BASE_TEX ];
|
||||
}
|
||||
|
||||
if ( mCurShader == Shader ) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCurShader = Shader;
|
||||
glm_ProjectionMatrix_id = mCurShader->UniformLocation( "glm_ProjectionMatrix" );
|
||||
glm_ModelViewMatrix_id = mCurShader->UniformLocation( "glm_ModelViewMatrix" );
|
||||
|
||||
GLenum CM = mCurrentMode;
|
||||
|
||||
MatrixMode( GL_PROJECTION );
|
||||
MatrixMode( GL_MODELVIEW );
|
||||
MatrixMode( CM );
|
||||
|
||||
glUseProgram( mCurShader->Handler() );
|
||||
}
|
||||
|
||||
void cRendererGL3::Disable ( GLenum cap ) {
|
||||
cGL::Disable( cap );
|
||||
|
||||
if ( GL_TEXTURE_2D == cap ) {
|
||||
mCurShader->SetUniform( "glm_TexActive", 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void cRendererGL3::Enable( GLenum cap ) {
|
||||
cGL::Enable( cap );
|
||||
|
||||
if ( GL_TEXTURE_2D == cap ) {
|
||||
mCurShader->SetUniform( "glm_TexActive", 1 );
|
||||
}
|
||||
}
|
||||
|
||||
void cRendererGL3::Init() {
|
||||
cGL::Init();
|
||||
|
||||
// compile Vertex shader
|
||||
GLuint m_vxShaderId = glCreateShader(GL_VERTEX_SHADER);
|
||||
GLsizei nlines_vx = sizeof(g_vertexShader)/sizeof(const GLchar*);
|
||||
glShaderSource( m_vxShaderId, nlines_vx, (const GLchar**)g_vertexShader, NULL );
|
||||
glCompileShader( m_vxShaderId );
|
||||
//mShaders[ EEGL_SHADER_BASE ] = eeNew( cShaderProgram, ( (const char**)g_vertexShader_base, sizeof(g_vertexShader_base)/sizeof(const GLchar*), (const char**)g_fragmentShader_base, sizeof(g_fragmentShader_base)/sizeof(const GLchar*), "EEGL_SHADER_BASE" ) );
|
||||
mShaders[ EEGL_SHADER_BASE_TEX ] = eeNew( cShaderProgram, ( (const char**)g_vertexShader, sizeof(g_vertexShader)/sizeof(const GLchar*), (const char**)g_fragmentShader, sizeof(g_fragmentShader)/sizeof(const GLchar*), "EEGL_SHADER_BASE_TEX" ) );
|
||||
SetShader( mShaders[ EEGL_SHADER_BASE_TEX ] );
|
||||
|
||||
// compile Fragment shader
|
||||
GLuint m_fgShaderId = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
GLsizei nlines_fg = sizeof(g_fragmentShader)/sizeof(const GLchar*);
|
||||
glShaderSource( m_fgShaderId, nlines_fg, (const GLchar**)g_fragmentShader, NULL );
|
||||
glCompileShader( m_fgShaderId );
|
||||
glGenVertexArrays( 1, &mVAO );
|
||||
glBindVertexArray( mVAO );
|
||||
|
||||
// link shaders
|
||||
shader_id = glCreateProgram();
|
||||
glAttachShader( shader_id, m_vxShaderId );
|
||||
glAttachShader( shader_id, m_fgShaderId );
|
||||
glLinkProgram( shader_id );
|
||||
memset( mVBO, 0, eeARRAY_SIZE( mVBO ) );
|
||||
|
||||
//hooks from CPU to GPU
|
||||
//define Uniform hooks
|
||||
glm_ProjectionMatrix_id = glGetUniformLocation(shader_id, "glm_ProjectionMatrix");
|
||||
glm_ModelViewMatrix_id = glGetUniformLocation(shader_id, "glm_ModelViewMatrix");
|
||||
glGenBuffers( EEGL_ARRAY_STATES_SIZE, &mVBO[0] );
|
||||
|
||||
//"in vec2 dgl_Vertex;",
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mVBO[ EEGL_VERTEX_ARRAY ] );
|
||||
glBufferData(GL_ARRAY_BUFFER, 131072, NULL, GL_DYNAMIC_DRAW );
|
||||
|
||||
//"in vec4 dgl_Color;",
|
||||
glBindBuffer( GL_ARRAY_BUFFER, mVBO[ EEGL_COLOR_ARRAY ] );
|
||||
glBufferData( GL_ARRAY_BUFFER, 131072, NULL, GL_DYNAMIC_DRAW );
|
||||
|
||||
//"in vec2 dgl_TexCoord;",
|
||||
glBindBuffer( GL_ARRAY_BUFFER, mVBO[ EEGL_TEXTURE_COORD_ARRAY ] );
|
||||
glBufferData( GL_ARRAY_BUFFER, 131072, NULL, GL_DYNAMIC_DRAW );
|
||||
|
||||
// finally, use the shader for rendering
|
||||
glUseProgram(shader_id); // select the shaders program
|
||||
}
|
||||
|
||||
void cRendererGL3::PushMatrix() {
|
||||
@@ -88,12 +144,14 @@ void cRendererGL3::UpdateMatrix() {
|
||||
switch ( mCurrentMode ) {
|
||||
case GL_PROJECTION:
|
||||
{
|
||||
glUniformMatrix4fv( glm_ProjectionMatrix_id, 1, false, &glm_ProjectionMatrix.top()[0][0] );
|
||||
if ( -1 != glm_ProjectionMatrix_id )
|
||||
mCurShader->SetUniformMatrix( glm_ProjectionMatrix_id, &glm_ProjectionMatrix.top()[0][0] );
|
||||
break;
|
||||
}
|
||||
case GL_MODELVIEW:
|
||||
{
|
||||
glUniformMatrix4fv( glm_ModelViewMatrix_id, 1, false, &glm_ModelViewMatrix.top()[0][0] );
|
||||
if ( -1 != glm_ModelViewMatrix_id )
|
||||
mCurShader->SetUniformMatrix( glm_ModelViewMatrix_id, &glm_ModelViewMatrix.top()[0][0] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -136,8 +194,70 @@ void cRendererGL3::MatrixMode(GLenum mode) {
|
||||
}
|
||||
}
|
||||
|
||||
void cRendererGL3::Ortho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) {
|
||||
mCurMatrix->top() = glm::ortho( left, right, bottom, top , zNear, zFar );
|
||||
void cRendererGL3::Ortho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ) {
|
||||
mCurMatrix->top() *= glm::ortho( left, right, bottom, top , zNear, zFar );
|
||||
UpdateMatrix();
|
||||
}
|
||||
|
||||
void cRendererGL3::LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ ) {
|
||||
mCurMatrix->top() *= glm::lookAt( glm::vec3(eyeX, eyeY, eyeZ), glm::vec3(centerX, centerY, centerZ), glm::vec3(upX, upY, upZ) );
|
||||
UpdateMatrix();
|
||||
}
|
||||
|
||||
void cRendererGL3::Perspective ( GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar ) {
|
||||
mCurMatrix->top() *= glm::perspective( fovy, aspect, zNear, zFar );
|
||||
UpdateMatrix();
|
||||
}
|
||||
|
||||
void cRendererGL3::EnableClientState( GLenum array ) {
|
||||
glEnableVertexAttribArray( array - GL_VERTEX_ARRAY );
|
||||
}
|
||||
|
||||
void cRendererGL3::DisableClientState( GLenum array ) {
|
||||
glDisableVertexAttribArray( array - GL_VERTEX_ARRAY );
|
||||
}
|
||||
|
||||
void cRendererGL3::VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLuint allocate ) {
|
||||
const GLint index = mCurShader->AttributeLocation( "dgl_Vertex" );
|
||||
|
||||
//eeASSERT( -1 != index );
|
||||
|
||||
if ( -1 != index ) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, mVBO[ EEGL_VERTEX_ARRAY ] );
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0, allocate, pointer );
|
||||
|
||||
glVertexAttribPointer( index, size, type, GL_FALSE, stride, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void cRendererGL3::ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) {
|
||||
const GLint index = mCurShader->AttributeLocation( "dgl_Color" );
|
||||
|
||||
//eeASSERT( -1 != index );
|
||||
|
||||
if ( -1 != index ) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, mVBO[ EEGL_COLOR_ARRAY ] );
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0, allocate, pointer );
|
||||
|
||||
if ( type == GL_UNSIGNED_BYTE ) {
|
||||
glVertexAttribPointer( index, size, type, GL_TRUE, stride, 0 );
|
||||
} else {
|
||||
glVertexAttribPointer( index, size, type, GL_FALSE, stride, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cRendererGL3::TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) {
|
||||
const GLint index = mCurShader->AttributeLocation( "dgl_TexCoord" );
|
||||
|
||||
//eeASSERT( -1 != index );
|
||||
|
||||
if ( -1 != index ) {
|
||||
glBindBuffer( GL_ARRAY_BUFFER, mVBO[ EEGL_TEXTURE_COORD_ARRAY ] );
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0, allocate, pointer );
|
||||
|
||||
glVertexAttribPointer( index, size, type, GL_FALSE, stride, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
#ifndef EE_GRAPHICS_CRENDERERGL3_HPP
|
||||
#define EE_GRAPHICS_CRENDERERGL3_HPP
|
||||
|
||||
#ifdef EE_GL3_ENABLED
|
||||
|
||||
#include "cgl.hpp"
|
||||
|
||||
#include <glm/glm.hpp> //OpenGL Mathematics (GLM). A C++ mathematics library for 3D graphics.
|
||||
#include <glm/ext.hpp>
|
||||
#ifdef EE_GL3_ENABLED
|
||||
|
||||
// Xlib Madness
|
||||
#ifdef True
|
||||
#undef True
|
||||
#endif
|
||||
|
||||
#ifdef False
|
||||
#undef False
|
||||
#endif
|
||||
|
||||
#include <glm/gtx/matrix_projection.hpp>
|
||||
#include <glm/gtx/transform.hpp>
|
||||
#include <glm/gtx/transform2.hpp>
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
enum EEGL_SHADERS_NUM {
|
||||
EEGL_SHADER_BASE_TEX,
|
||||
EEGL_SHADERS_COUNT
|
||||
};
|
||||
|
||||
class cRendererGL3 : public cGL {
|
||||
public:
|
||||
cRendererGL3();
|
||||
@@ -26,6 +41,10 @@ class cRendererGL3 : public cGL {
|
||||
|
||||
void LoadIdentity();
|
||||
|
||||
void Disable ( GLenum cap );
|
||||
|
||||
void Enable( GLenum cap );
|
||||
|
||||
void Translatef( GLfloat x, GLfloat y, GLfloat z );
|
||||
|
||||
void Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z );
|
||||
@@ -34,15 +53,36 @@ class cRendererGL3 : public cGL {
|
||||
|
||||
void MatrixMode (GLenum mode);
|
||||
|
||||
void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar );
|
||||
void Ortho ( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar );
|
||||
|
||||
void LookAt( GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ );
|
||||
|
||||
void Perspective ( GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar );
|
||||
|
||||
void EnableClientState( GLenum array );
|
||||
|
||||
void DisableClientState( GLenum array );
|
||||
|
||||
void VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
|
||||
void ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
|
||||
void TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate );
|
||||
|
||||
GLuint BaseShaderId();
|
||||
|
||||
void SetShader( cShaderProgram * Shader );
|
||||
protected:
|
||||
GLuint shader_id;
|
||||
std::stack<glm::mat4> glm_ProjectionMatrix; // cpu-side
|
||||
GLint glm_ProjectionMatrix_id; // cpu-side hook to shader uniform
|
||||
std::stack<glm::mat4> glm_ModelViewMatrix; // cpu-side
|
||||
GLint glm_ModelViewMatrix_id; // cpu-side hook to shader uniform
|
||||
GLenum mCurrentMode;
|
||||
std::stack<glm::mat4>* mCurMatrix;
|
||||
cShaderProgram * mShaders[ EEGL_SHADERS_COUNT ];
|
||||
cShaderProgram * mCurShader;
|
||||
GLuint mVAO;
|
||||
GLuint mVBO[ EEGL_ARRAY_STATES_SIZE ];
|
||||
|
||||
void UpdateMatrix();
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ void cDampedSpring::Draw() {
|
||||
cVect a = tovect( cpvadd(body_a->p, cpvrotate(spring->anchr1, body_a->rot)) );
|
||||
cVect b = tovect( cpvadd(body_b->p, cpvrotate(spring->anchr2, body_b->rot)) );
|
||||
|
||||
glPointSize(5.0f);
|
||||
GLi->PointSize(5.0f);
|
||||
glBegin(GL_POINTS); {
|
||||
glVertex2f(a.x, a.y);
|
||||
glVertex2f(b.x, b.y);
|
||||
@@ -64,7 +64,7 @@ void cDampedSpring::Draw() {
|
||||
|
||||
cVect delta = b - a;
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, springVAR);
|
||||
GLi->VertexPointer( 2, GL_FLOAT, 0, springVAR, springVAR_count * sizeof(GLfloat) * 2 );
|
||||
GLi->PushMatrix();
|
||||
|
||||
GLfloat x = a.x;
|
||||
@@ -82,7 +82,7 @@ void cDampedSpring::Draw() {
|
||||
|
||||
glMultMatrixf(matrix);
|
||||
|
||||
glDrawArrays(GL_LINE_STRIP, 0, springVAR_count);
|
||||
GLi->DrawArrays(GL_LINE_STRIP, 0, springVAR_count);
|
||||
|
||||
GLi->PopMatrix();
|
||||
#endif
|
||||
|
||||
@@ -55,11 +55,11 @@ void cShapeSegment::Draw( cSpace * space ) {
|
||||
cVect b = tovect( seg->CP_PRIVATE(tb) );
|
||||
|
||||
if ( seg->CP_PRIVATE(r) ) {
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glDisableClientState( GL_COLOR_ARRAY );
|
||||
GLi->Disable( GL_TEXTURE_2D );
|
||||
GLi->DisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->DisableClientState( GL_COLOR_ARRAY );
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, pillVAR);
|
||||
GLi->VertexPointer( 3, GL_FLOAT, 0, pillVAR, pillVAR_count * sizeof(GLfloat) * 3 );
|
||||
GLi->PushMatrix();
|
||||
|
||||
cVect d = b - a;
|
||||
@@ -78,17 +78,17 @@ void cShapeSegment::Draw( cSpace * space ) {
|
||||
|
||||
glColor3ub( C.R(), C.B(), C.B() );
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, pillVAR_count);
|
||||
GLi->DrawArrays(GL_TRIANGLE_FAN, 0, pillVAR_count);
|
||||
}
|
||||
|
||||
glColor3f( 0.4f, 0.4f, 0.4f );
|
||||
glDrawArrays( GL_LINE_LOOP, 0, pillVAR_count );
|
||||
GLi->DrawArrays( GL_LINE_LOOP, 0, pillVAR_count );
|
||||
|
||||
GLi->PopMatrix();
|
||||
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState( GL_COLOR_ARRAY );
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->EnableClientState( GL_COLOR_ARRAY );
|
||||
GLi->Enable( GL_TEXTURE_2D );
|
||||
} else {
|
||||
cPrimitives p;
|
||||
p.DrawLine( eeVector2f( a.x, a.y ), eeVector2f( b.x, b.y ) );
|
||||
|
||||
108
src/test/ee.cpp
108
src/test/ee.cpp
@@ -1698,7 +1698,9 @@ void cEETest::Demo1Create() {
|
||||
Physics::cShape::ResetShapeIdCounter();
|
||||
|
||||
mSpace = Physics::cSpace::New();
|
||||
mSpace->ResizeActiveHash( 30.f, 1000 );
|
||||
mSpace->Iterations( 30 );
|
||||
mSpace->ResizeStaticHash( 40.f, 1000 );
|
||||
mSpace->ResizeActiveHash( 40.f, 1000 );
|
||||
mSpace->Gravity( cVectNew( 0, 100 ) );
|
||||
mSpace->SleepTimeThreshold( 0.5f );
|
||||
|
||||
@@ -1939,6 +1941,36 @@ void cEETest::PhysicsDestroy() {
|
||||
cPhysicsManager::DestroySingleton();
|
||||
}
|
||||
|
||||
void defineVertexArrayObject(GLuint vaoId, size_t NbytesV, size_t NbytesC, GLint size, GLenum type, GLfloat *vertices, GLfloat *colors, GLfloat * texCoords, GLuint shader_id ) {
|
||||
//enable vertex array object to be defined
|
||||
glBindVertexArray(vaoId);
|
||||
|
||||
//generate VBO foreach 'in'; dgl_Vertex dgl_Color dgl_TexCoord
|
||||
GLuint m_vboId[3];
|
||||
glGenBuffers(3, &m_vboId[0]);
|
||||
|
||||
//"in vec2 dgl_Vertex;",
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboId[0] ); // enable the 1st VBO
|
||||
glBufferData(GL_ARRAY_BUFFER, NbytesV, vertices, GL_STATIC_DRAW); // fill the VBO with vertices data
|
||||
const GLuint index_mPosition = glGetAttribLocation( shader_id, "dgl_Vertex" ); // get ID for "dgl_Vertex"
|
||||
glVertexAttribPointer( index_mPosition, 2, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_Vertex" attribute
|
||||
glEnableVertexAttribArray( index_mPosition ); // enable VBO vertex attribute ("dgl_Vertex")
|
||||
|
||||
//"in vec4 dgl_Color;",
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_vboId[1] ); // enable the 2nd VBO
|
||||
glBufferData( GL_ARRAY_BUFFER, NbytesC, colors, GL_STATIC_DRAW ); // fill the 2nd VBO with colors data
|
||||
const GLuint index_mcolor = glGetAttribLocation( shader_id,"dgl_Color" ); // get ID for "dgl_Color"
|
||||
glVertexAttribPointer( index_mcolor, 4, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_Color" attribute
|
||||
glEnableVertexAttribArray( index_mcolor ); // enable VBO vertex attribute ("dgl_Color")
|
||||
|
||||
//"in vec2 dgl_TexCoord;",
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_vboId[2] ); // enable the 3rd VBO
|
||||
glBufferData( GL_ARRAY_BUFFER, NbytesV, texCoords, GL_STATIC_DRAW ); // fill the 3nd VBO with tex coords data
|
||||
const GLuint index_mcoords = glGetAttribLocation( shader_id,"dgl_TexCoord" ); // get ID for "dgl_TexCoords"
|
||||
glVertexAttribPointer( index_mcoords, 2, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_TexCoords" attribute
|
||||
glEnableVertexAttribArray( index_mcoords ); // enable VBO vertex attribute ("dgl_TexCoords")
|
||||
}
|
||||
|
||||
int main (int argc, char * argv []) {
|
||||
cEETest * Test = eeNew( cEETest, () );
|
||||
|
||||
@@ -1946,6 +1978,80 @@ int main (int argc, char * argv []) {
|
||||
|
||||
eeDelete( Test );
|
||||
|
||||
/*
|
||||
cEngine * EE = cEngine::instance();
|
||||
EE->Init( 800, 600, 32, true, true, true, true );
|
||||
EE->SetBackColor( eeColor( 255, 255, 255 ) );
|
||||
|
||||
cInput * KM = cInput::instance();
|
||||
cTextureFactory * TF = cTextureFactory::instance();
|
||||
cTexture * Tex = TF->GetTexture( TF->Load( AppPath() + "data/bnb/bnb.png" ) );
|
||||
|
||||
cRendererGL3 * Ren = reinterpret_cast<cRendererGL3 *>( GLi );
|
||||
|
||||
GLfloat vertices0[] = { // dgl_Vertex
|
||||
0.0 , 0.0, // xy
|
||||
0.0 , 600,
|
||||
800.0 , 600.0,
|
||||
800.0 , 0.0
|
||||
};
|
||||
|
||||
size_t Nbytes_vertices0=sizeof(vertices0);
|
||||
|
||||
GLfloat colors0[] = { // dgl_Color
|
||||
1.0, 1.0, 1.0, 0.5, //rgba
|
||||
1.0, 1.0, 1.0, 0.5,
|
||||
1.0, 1.0, 1.0, 0.5,
|
||||
1.0, 1.0, 1.0, 0.5
|
||||
};
|
||||
size_t Nbytes_colors0=sizeof(colors0);
|
||||
|
||||
GLfloat texCoords0[] = { // dgl_TexCoord
|
||||
0.0 , 0.0, // xy
|
||||
0.0 , 1.0,
|
||||
1.0 , 1.0,
|
||||
1.0 , 0.0
|
||||
};
|
||||
|
||||
GLuint vao_id;
|
||||
|
||||
glGenVertexArrays( 1, &vao_id );
|
||||
|
||||
glBindVertexArray( vao_id );
|
||||
|
||||
GLuint vao_elementcount = Nbytes_vertices0 / 2 / sizeof(GLfloat);
|
||||
|
||||
defineVertexArrayObject( vao_id, Nbytes_vertices0, Nbytes_colors0, 4, GL_FLOAT, vertices0, colors0, texCoords0, Ren->BaseShaderId() );
|
||||
|
||||
eeFloat ang = 0;
|
||||
|
||||
while( EE->Running() ) {
|
||||
KM->Update();
|
||||
|
||||
ang += EE->Elapsed() * 0.1;
|
||||
|
||||
TF->Bind( Tex );
|
||||
glBindVertexArray( vao_id );
|
||||
|
||||
GLi->DrawArrays( GL_QUADS, 0, vao_elementcount );
|
||||
|
||||
GLi->PushMatrix();
|
||||
|
||||
GLi->Translatef( 400, 300, 0 );
|
||||
GLi->Rotatef( ang, 0, 0, 1 );
|
||||
GLi->Translatef( -400, -300, 0 );
|
||||
|
||||
GLi->DrawArrays( GL_QUADS, 0, vao_elementcount );
|
||||
|
||||
GLi->PopMatrix();
|
||||
|
||||
EE->Display();
|
||||
|
||||
if ( KM->IsKeyDown( KEY_ESCAPE ) ) EE->Running( false );
|
||||
};
|
||||
|
||||
cEngine::DestroySingleton();
|
||||
*/
|
||||
EE::MemoryManager::LogResults();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -86,7 +86,7 @@ cEngine::cEngine() :
|
||||
mFrames.FPS.Error = 0;
|
||||
mFrames.ElapsedTime = 0;
|
||||
|
||||
cShapeGroupManager::instance();
|
||||
cShapeGroupManager::CreateSingleton();
|
||||
}
|
||||
|
||||
cEngine::~cEngine() {
|
||||
@@ -105,8 +105,6 @@ cEngine::~cEngine() {
|
||||
|
||||
cFontManager::DestroySingleton();
|
||||
|
||||
cShaderProgramManager::DestroySingleton();
|
||||
|
||||
UI::cUIManager::DestroySingleton();
|
||||
|
||||
cJoystickManager::DestroySingleton();
|
||||
@@ -117,6 +115,8 @@ cEngine::~cEngine() {
|
||||
|
||||
Graphics::cGL::DestroySingleton();
|
||||
|
||||
cShaderProgramManager::DestroySingleton();
|
||||
|
||||
cLog::DestroySingleton();
|
||||
|
||||
HaikuTTF::hkFontManager::DestroySingleton();
|
||||
@@ -266,25 +266,23 @@ const cView& cEngine::GetView() const {
|
||||
void cEngine::Setup2D( const bool& KeepView ) {
|
||||
SetBackColor( mBackColor );
|
||||
|
||||
glShadeModel( GL_SMOOTH );
|
||||
SetLineSmooth( mVideoInfo.LineSmooth );
|
||||
|
||||
glEnable( GL_TEXTURE_2D ); // Enable Textures
|
||||
GLi->Enable( GL_TEXTURE_2D ); // Enable Textures
|
||||
GLi->Disable( GL_DEPTH_TEST );
|
||||
GLi->Disable( GL_LIGHTING );
|
||||
|
||||
if ( !KeepView )
|
||||
SetView( mDefaultView );
|
||||
|
||||
glDisable( GL_DEPTH_TEST );
|
||||
glDisable( GL_LIGHTING );
|
||||
|
||||
cTextureFactory::instance()->SetPreBlendFunc( ALPHA_BLENDONE ); // This is to fix a little bug on windows when the resolution change. I don't know why it happens, but this line fix it.
|
||||
cTextureFactory::instance()->SetPreBlendFunc( ALPHA_NORMAL );
|
||||
|
||||
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState( GL_COLOR_ARRAY );
|
||||
glShadeModel( GL_SMOOTH );
|
||||
GLi->EnableClientState( GL_VERTEX_ARRAY );
|
||||
GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
GLi->EnableClientState( GL_COLOR_ARRAY );
|
||||
}
|
||||
|
||||
void cEngine::CalculateFps() {
|
||||
@@ -325,7 +323,7 @@ void cEngine::Display() {
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
||||
GLi->Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
||||
|
||||
GetElapsedTime();
|
||||
|
||||
@@ -399,7 +397,7 @@ Uint32 cEngine::FPS() const {
|
||||
|
||||
void cEngine::SetBackColor(const eeColor& Color) {
|
||||
mBackColor = Color;
|
||||
glClearColor( static_cast<eeFloat>( mBackColor.R() ) / 255.0f, static_cast<eeFloat>( mBackColor.G() ) / 255.0f, static_cast<eeFloat>( mBackColor.B() ) / 255.0f, 255.0f );
|
||||
GLi->ClearColor( static_cast<eeFloat>( mBackColor.R() ) / 255.0f, static_cast<eeFloat>( mBackColor.G() ) / 255.0f, static_cast<eeFloat>( mBackColor.B() ) / 255.0f, 255.0f );
|
||||
}
|
||||
|
||||
const eeColor& cEngine::GetBackColor() const {
|
||||
@@ -526,39 +524,39 @@ void cEngine::SetGamma( const eeFloat& Red, const eeFloat& Green, const eeFloat&
|
||||
void cEngine::SetLineSmooth( const bool& Enable ) {
|
||||
mVideoInfo.LineSmooth = Enable;
|
||||
if ( Enable )
|
||||
glEnable( GL_LINE_SMOOTH );
|
||||
GLi->Enable( GL_LINE_SMOOTH );
|
||||
else
|
||||
glDisable( GL_LINE_SMOOTH );
|
||||
GLi->Disable( GL_LINE_SMOOTH );
|
||||
}
|
||||
|
||||
void cEngine::SetPolygonMode( const EE_FILL_MODE& Mode ) {
|
||||
if ( Mode == EE_DRAW_FILL )
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
GLi->PolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
else
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
GLi->PolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
}
|
||||
|
||||
void cEngine::ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
|
||||
cGlobalBatchRenderer::instance()->Draw();
|
||||
glScissor( x, GetHeight() - Height - y, Width, Height );
|
||||
glEnable( GL_SCISSOR_TEST );
|
||||
GLi->Scissor( x, GetHeight() - Height - y, Width, Height );
|
||||
GLi->Enable( GL_SCISSOR_TEST );
|
||||
}
|
||||
|
||||
void cEngine::ClipDisable() {
|
||||
cGlobalBatchRenderer::instance()->Draw();
|
||||
glDisable( GL_SCISSOR_TEST );
|
||||
GLi->Disable( GL_SCISSOR_TEST );
|
||||
}
|
||||
|
||||
std::string cEngine::GetVendor() {
|
||||
return std::string( reinterpret_cast<const char*> ( glGetString( GL_VENDOR ) ) );
|
||||
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_VENDOR ) ) );
|
||||
}
|
||||
|
||||
std::string cEngine::GetRenderer() {
|
||||
return std::string( reinterpret_cast<const char*> ( glGetString( GL_RENDERER ) ) );
|
||||
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_RENDERER ) ) );
|
||||
}
|
||||
|
||||
std::string cEngine::GetVersion() {
|
||||
return std::string( reinterpret_cast<const char*> ( glGetString( GL_VERSION ) ) );
|
||||
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_VERSION ) ) );
|
||||
}
|
||||
|
||||
bool cEngine::GetExtension( const std::string& Ext ) {
|
||||
@@ -1073,10 +1071,10 @@ void cEngine::ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Widt
|
||||
GLdouble clip_top[] = { 0.0 , 1.0 , 0.0, -tY };
|
||||
GLdouble clip_bottom[] = { 0.0 , -1.0 , 0.0, tY + tH };
|
||||
|
||||
glEnable(GL_CLIP_PLANE0);
|
||||
glEnable(GL_CLIP_PLANE1);
|
||||
glEnable(GL_CLIP_PLANE2);
|
||||
glEnable(GL_CLIP_PLANE3);
|
||||
GLi->Enable(GL_CLIP_PLANE0);
|
||||
GLi->Enable(GL_CLIP_PLANE1);
|
||||
GLi->Enable(GL_CLIP_PLANE2);
|
||||
GLi->Enable(GL_CLIP_PLANE3);
|
||||
|
||||
glClipPlane(GL_CLIP_PLANE0, clip_left);
|
||||
glClipPlane(GL_CLIP_PLANE1, clip_right);
|
||||
@@ -1087,10 +1085,10 @@ void cEngine::ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Widt
|
||||
void cEngine::ClipPlaneDisable() {
|
||||
cGlobalBatchRenderer::instance()->Draw();
|
||||
|
||||
glDisable(GL_CLIP_PLANE0);
|
||||
glDisable(GL_CLIP_PLANE1);
|
||||
glDisable(GL_CLIP_PLANE2);
|
||||
glDisable(GL_CLIP_PLANE3);
|
||||
GLi->Disable(GL_CLIP_PLANE0);
|
||||
GLi->Disable(GL_CLIP_PLANE1);
|
||||
GLi->Disable(GL_CLIP_PLANE2);
|
||||
GLi->Disable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user