first new api of openGl working and create a resourceManager => this one will be used
This commit is contained in:
parent
fc30b0bb21
commit
6ac6bc50d0
@ -16,12 +16,12 @@ LOCAL_LIBRARIES := etk freetype tinyxml libzip libpng parsersvg lua
|
||||
LOCAL_C_INCLUDES :=
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
|
||||
LOCAL_EXPORT_LDLIBS := -lGLESv1_CM -ldl -llog
|
||||
|
||||
LOCAL_EXPORT_LDLIBS := -lGLESv2 -ldl -llog
|
||||
|
||||
LOCAL_CFLAGS := -Wno-write-strings \
|
||||
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-$(BUILD_DIRECTORY_MODE)\"" \
|
||||
-DDATA_IN_APK \
|
||||
-DLUA_COMPAT_ALL
|
||||
-DDATA_IN_APK
|
||||
|
||||
# load the common sources file of the platform
|
||||
include $(LOCAL_PATH)/file.mk
|
||||
@ -29,7 +29,7 @@ include $(LOCAL_PATH)/file.mk
|
||||
LOCAL_SRC_FILES := ewol/os/gui.Android.cpp $(FILE_LIST)
|
||||
|
||||
# Ewol Test Software :
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lz
|
||||
LOCAL_LDLIBS := -lGLESv2 -ldl -llog -lz
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
51
Sources/libewol/ewol/Resource.h
Normal file
51
Sources/libewol/ewol/Resource.h
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/Resources.h
|
||||
* @brief ewol resources template (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __RESOURCES_H__
|
||||
#define __RESOURCES_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
// class resources is pure virtual
|
||||
class Resource {
|
||||
etk::UString m_name;
|
||||
uint32_t m_counter;
|
||||
public:
|
||||
Resource(etk::UString& filename) : m_name(filename), m_counter(1) { };
|
||||
virtual ~Resource(void) { };
|
||||
bool HasName(etk::UString& fileName) { return fileName==m_name; };
|
||||
etk::UString GetName(void) { return m_name; };
|
||||
void Increment(void) { m_counter++; };
|
||||
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
|
||||
virtual const char* GetType(void)=0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
177
Sources/libewol/ewol/ResourceManager.cpp
Normal file
177
Sources/libewol/ewol/ResourceManager.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/ResourcesManager.h
|
||||
* @brief ewol resources manager template (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/ResourceManager.h>
|
||||
|
||||
static etk::Vector<ewol::Resource*> l_resourceList;
|
||||
|
||||
|
||||
void ewol::resource::Init(void)
|
||||
{
|
||||
// nothing to do in theory then, we clean the buffers :
|
||||
// NOTE : If we do domething here, then the system does not work corectly
|
||||
if (l_resourceList.Size() != 0) {
|
||||
EWOL_CRITICAL("Start with a resource manager Not empty, number of resources loaded : " << l_resourceList.Size());
|
||||
}
|
||||
l_resourceList.Clear();
|
||||
}
|
||||
|
||||
void ewol::resource::UnInit(void)
|
||||
{
|
||||
// remove textured font ...
|
||||
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
|
||||
if (l_resourceList[iii] != NULL) {
|
||||
delete(l_resourceList[iii]);
|
||||
l_resourceList[iii] = NULL;
|
||||
}
|
||||
}
|
||||
l_resourceList.Clear();
|
||||
}
|
||||
|
||||
// internal generic keeper ...
|
||||
static ewol::Resource* Keep(etk::UString name)
|
||||
{
|
||||
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
||||
if (l_resourceList[iii] != NULL) {
|
||||
if(l_resourceList[iii]->HasName(name)) {
|
||||
l_resourceList[iii]->Increment();
|
||||
return l_resourceList[iii];
|
||||
}
|
||||
}
|
||||
}
|
||||
// we did not find it ...
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// return the type of the resource ...
|
||||
bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object, int32_t size)
|
||||
{
|
||||
object = NULL;
|
||||
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
||||
if (l_resourceList[iii] != NULL) {
|
||||
if(l_resourceList[iii]->HasName(name)) {
|
||||
ewol::TexturedFont* tmpObject = static_cast<ewol::TexturedFont*>(l_resourceList[iii]);
|
||||
if (NULL!=tmpObject) {
|
||||
if (tmpObject->getFontSize() == size) {
|
||||
l_resourceList[iii]->Increment();
|
||||
object = static_cast<ewol::TexturedFont*>l_resourceList[iii]
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// good name but not good Size
|
||||
}
|
||||
}
|
||||
}
|
||||
// need to crate a new one ...
|
||||
object = new ewol::TexturedFont(filename, size);
|
||||
if (NULL == object) {
|
||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||
return false;
|
||||
}
|
||||
l_resourceList.PushBack(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object)
|
||||
{
|
||||
object = static_cast<ewol::Font*>(Keep(filename));
|
||||
if (NULL != object) {
|
||||
return true;
|
||||
}
|
||||
// need to crate a new one ...
|
||||
object = new ewol::Font(filename, size);
|
||||
if (NULL == object) {
|
||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||
return false;
|
||||
}
|
||||
l_resourceList.PushBack(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object)
|
||||
{
|
||||
object = static_cast<ewol::Program*>(Keep(filename));
|
||||
if (NULL != object) {
|
||||
return true;
|
||||
}
|
||||
// need to crate a new one ...
|
||||
object = new ewol::Program(filename, size);
|
||||
if (NULL == object) {
|
||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||
return false;
|
||||
}
|
||||
l_resourceList.PushBack(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
|
||||
{
|
||||
object = static_cast<ewol::Shader*>(Keep(filename));
|
||||
if (NULL != object) {
|
||||
return true;
|
||||
}
|
||||
// need to crate a new one ...
|
||||
object = new ewol::Shader(filename, size);
|
||||
if (NULL == object) {
|
||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||
return false;
|
||||
}
|
||||
l_resourceList.PushBack(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::Release(ewol::Resource*& object)
|
||||
{
|
||||
if (NUUL == object) {
|
||||
EWOL_ERROR("Try to remove a resource that have null pointer ...");
|
||||
return;
|
||||
}
|
||||
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
||||
if (l_resourceList[iii] != NULL) {
|
||||
if(l_resourceList[iii] == object) {
|
||||
if (true == l_resourceList[iii]->Decrement()) {
|
||||
// delete element
|
||||
delete(l_resourceList[iii]);
|
||||
// remove element from the list :
|
||||
l_resourceList.Erase(iii);
|
||||
}
|
||||
// insidiously remove the pointer for the caller ...
|
||||
object = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
EWOL_ERROR("Can not find the resources in the list : " << (int64_t)object);
|
||||
// insidiously remove the pointer for the caller ...
|
||||
object = NULL;
|
||||
}
|
||||
|
54
Sources/libewol/ewol/ResourceManager.h
Normal file
54
Sources/libewol/ewol/ResourceManager.h
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/ResourcesManager.h
|
||||
* @brief ewol resources manager template (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __RESOURCES_MANAGER_H__
|
||||
#define __RESOURCES_MANAGER_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/Resource.h>
|
||||
#include <ewol/openGL/Shader.h>
|
||||
#include <ewol/openGL/Program.h>
|
||||
#include <ewol/font/Font.h>
|
||||
#include <ewol/font/TexturedFont.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
namespace resource {
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
// return the type of the resource ...
|
||||
bool Keep(etk::UString& filename, ewol::TexturedFont*& object, int32_t size);
|
||||
bool Keep(etk::UString& filename, ewol::Font*& object);
|
||||
bool Keep(etk::UString& filename, ewol::Program*& object);
|
||||
bool Keep(etk::UString& filename, ewol::Shader*& object);
|
||||
|
||||
void Release(ewol::resource*& object);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <etk/File.h>
|
||||
#include <draw/Image.h>
|
||||
#include <ewol/texture/Texture.h>
|
||||
#include <ewol/Resource.h>
|
||||
|
||||
|
||||
namespace ewol
|
||||
@ -76,21 +77,10 @@ namespace ewol
|
||||
Vector2D<int32_t> m_advance; // space use in the display for this specific char
|
||||
} GlyphProperty;
|
||||
|
||||
class Font {
|
||||
private:
|
||||
etk::UString m_name;
|
||||
uint32_t m_counter;
|
||||
class Font : public ewol::Resource
|
||||
public:
|
||||
Font(etk::UString fontFolder, etk::UString fontName) :
|
||||
m_counter(1)
|
||||
{
|
||||
m_name = fontName;
|
||||
};
|
||||
Font(etk::UString fontFolder, etk::UString fontName) : ewol::Resource(fontName) {};
|
||||
virtual ~Font(void) {};
|
||||
bool HasName(etk::UString& fileName) { return fileName==m_name; };
|
||||
etk::UString GetName(void) { return m_name; };
|
||||
void Increment(void) { m_counter++; };
|
||||
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
|
||||
virtual int32_t Draw(draw::Image& imageOut,
|
||||
int32_t fontSize,
|
||||
Vector2D<float> textPos,
|
||||
|
@ -52,6 +52,7 @@ namespace ewol
|
||||
public:
|
||||
TexturedFont(etk::UString fontName, int32_t size);
|
||||
~TexturedFont(void);
|
||||
int32_t getFontSize(void) { return m_size; };
|
||||
bool HasName(etk::UString& fileName, int32_t size) { return (m_size!=size)?false:((m_font==NULL)?false:m_font->HasName(fileName)); };
|
||||
void Increment(void) { m_counter++; };
|
||||
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
|
||||
|
41
Sources/libewol/ewol/openGL/Program.cpp
Normal file
41
Sources/libewol/ewol/openGL/Program.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGL/Program.cpp
|
||||
* @brief ewol openGl Program shader system (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGL/Program.h>
|
||||
|
||||
ewol::Program::Program(etk::UString& filename) : ewol::Resource(filename)
|
||||
m_program(0),
|
||||
m_needToReleaseShader(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ewol::Program::~Program(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
48
Sources/libewol/ewol/openGL/Program.h
Normal file
48
Sources/libewol/ewol/openGL/Program.h
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGL/Program.h
|
||||
* @brief ewol openGl Program shader system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL__PROGRAM_H__
|
||||
#define __OPEN_GL__PROGRAM_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/Resource.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
Class Program : public ewol::Resource
|
||||
{
|
||||
private :
|
||||
GLuint m_program;
|
||||
bool m_needToReleaseShader;
|
||||
public:
|
||||
Program(etk::UString& filename);
|
||||
virtual ~Program(void);
|
||||
GLuint GetGL_ID(void) { return m_program; };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
44
Sources/libewol/ewol/openGL/Shader.cpp
Normal file
44
Sources/libewol/ewol/openGL/Shader.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGL/Shader.cpp
|
||||
* @brief ewol openGl Shader system (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGL/Shader.h>
|
||||
|
||||
|
||||
|
||||
ewol::Shader::Shader(etk::UString& filename):
|
||||
ewol::Resource(filename),
|
||||
m_shader(0),
|
||||
m_type(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ewol::Shader::~Shader(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
49
Sources/libewol/ewol/openGL/Shader.h
Normal file
49
Sources/libewol/ewol/openGL/Shader.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGL/Shader.h
|
||||
* @brief ewol openGl Shader system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 24/08/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL__SHADER_H__
|
||||
#define __OPEN_GL__SHADER_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/Resource.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
Class Shader : public ewol::Resource
|
||||
{
|
||||
private :
|
||||
GLuint m_shader;
|
||||
GLenum m_type;
|
||||
public:
|
||||
Shader(etk::UString& filename);
|
||||
virtual ~Shader(void);
|
||||
GLuint GetGL_ID(void) { return m_shader; };
|
||||
GLenum GetShaderType(void) { return m_type; };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
203
Sources/libewol/ewol/openGL/openGL.cpp
Normal file
203
Sources/libewol/ewol/openGL/openGL.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGL/openGL.cpp
|
||||
* @brief ewol openGl abstarction (sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 19/09/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGl.h>
|
||||
|
||||
|
||||
void glOrthoEwol(GLfloat left,
|
||||
GLfloat right,
|
||||
GLfloat bottom,
|
||||
GLfloat top,
|
||||
GLfloat nearVal,
|
||||
GLfloat farVal)
|
||||
{
|
||||
GLfloat myMatrix[4*4];
|
||||
int iii;
|
||||
for(iii=0; iii<4*4 ; iii++) {
|
||||
myMatrix[iii] = 0;
|
||||
}
|
||||
myMatrix[0] = 2.0 / (right - left);
|
||||
myMatrix[5] = 2.0 / (top - bottom);
|
||||
myMatrix[10] = -2.0 / (farVal - nearVal);
|
||||
#if 1
|
||||
myMatrix[3] = -1*(right + left) / (right - left);
|
||||
myMatrix[7] = -1*(top + bottom) / (top - bottom);
|
||||
myMatrix[11] = -1*(farVal + nearVal) / (farVal - nearVal);
|
||||
#else
|
||||
// test if matrix is not corectly instanciate ...
|
||||
myMatrix[12] = -1*(right + left) / (right - left);
|
||||
myMatrix[13] = -1*(top + bottom) / (top - bottom);
|
||||
myMatrix[14] = -1*(farVal + nearVal) / (farVal - nearVal);
|
||||
#endif
|
||||
myMatrix[15] = 1;
|
||||
|
||||
glLoadMatrixf(myMatrix);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void printGLString(const char *name, GLenum s)
|
||||
{
|
||||
const char *v = (const char *) glGetString(s);
|
||||
EWOL_INFO("GL " << name << " = " << v);
|
||||
}
|
||||
|
||||
static void checkGlError(const char* op)
|
||||
{
|
||||
for (GLint error = glGetError(); error; error = glGetError()) {
|
||||
EWOL_INFO("after " << op << "() glError (" << error << ")");
|
||||
}
|
||||
}
|
||||
|
||||
static const char gVertexShader[] =
|
||||
"attribute vec4 vPosition;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = vPosition;\n"
|
||||
"}\n";
|
||||
|
||||
static const char gFragmentShader[] =
|
||||
/*"precision mediump float;\n"*/
|
||||
"void main() {\n"
|
||||
" gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
|
||||
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
|
||||
|
||||
GLuint loadShader(GLenum shaderType, const char* pSource)
|
||||
{
|
||||
GLuint shader = glCreateShader(shaderType);
|
||||
if (!shader) {
|
||||
EWOL_ERROR("glCreateShader return error ...");
|
||||
checkGlError("glCreateShader");
|
||||
} else {
|
||||
glShaderSource(shader, 1, &pSource, NULL);
|
||||
glCompileShader(shader);
|
||||
GLint compiled = 0;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled) {
|
||||
GLint infoLen = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
glGetShaderInfoLog(shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
|
||||
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
|
||||
if (shaderType == GL_VERTEX_SHADER){
|
||||
tmpShaderType = "GL_VERTEX_SHADER";
|
||||
}
|
||||
EWOL_ERROR("Could not compile \"" << tmpShaderType << "\": " << l_bufferDisplayError);
|
||||
}
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint createProgram(const char* pVertexSource, const char* pFragmentSource)
|
||||
{
|
||||
EWOL_INFO("Create the VERTEX shader ...");
|
||||
GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
|
||||
if (!vertexShader) {
|
||||
EWOL_ERROR("VERTEX shader return error ...");
|
||||
return 0;
|
||||
}
|
||||
EWOL_INFO("Create the FRAGMENT shader ...");
|
||||
GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
|
||||
if (!pixelShader) {
|
||||
EWOL_ERROR("FRAGMENT shader return error ...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
EWOL_INFO("Create the Program ...");
|
||||
GLuint program = glCreateProgram();
|
||||
if (!program) {
|
||||
EWOL_ERROR("program creation return error ...");
|
||||
|
||||
} else {
|
||||
glAttachShader(program, vertexShader);
|
||||
checkGlError("glAttachShader");
|
||||
glAttachShader(program, pixelShader);
|
||||
checkGlError("glAttachShader");
|
||||
glLinkProgram(program);
|
||||
GLint linkStatus = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
||||
if (linkStatus != GL_TRUE) {
|
||||
GLint bufLength = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
glGetProgramInfoLog(program, LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
|
||||
EWOL_ERROR("Could not compile \"PROGRAM\": " << l_bufferDisplayError);
|
||||
glDeleteProgram(program);
|
||||
program = 0;
|
||||
}
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
GLuint gProgram;
|
||||
GLuint gvPositionHandle;
|
||||
|
||||
bool TESTsetupGraphics(int w, int h)
|
||||
{
|
||||
printGLString("Version", GL_VERSION);
|
||||
printGLString("Vendor", GL_VENDOR);
|
||||
printGLString("Renderer", GL_RENDERER);
|
||||
printGLString("Extensions", GL_EXTENSIONS);
|
||||
|
||||
EWOL_INFO("setupGraphics("<< w << "," << h);
|
||||
gProgram = createProgram(gVertexShader, gFragmentShader);
|
||||
if (!gProgram) {
|
||||
EWOL_ERROR("Could not create program.");
|
||||
return false;
|
||||
}
|
||||
gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
|
||||
checkGlError("glGetAttribLocation");
|
||||
EWOL_INFO("glGetAttribLocation(\"vPosition\") = " << gvPositionHandle);
|
||||
|
||||
glViewport(0, 0, w, h);
|
||||
checkGlError("glViewport");
|
||||
|
||||
return true;
|
||||
}
|
||||
const GLfloat gTriangleVertices[] = { 0.0f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f };
|
||||
//const GLfloat gTriangleVertices[] = { 0.0f, 0.0f, 200.0f, 0.0f, 0.0f, 200.0f };
|
||||
|
||||
void TEST_renderFrame(void) {
|
||||
static float grey = 0.5;
|
||||
|
||||
grey += 0.01f;
|
||||
if (grey > 1.0f) {
|
||||
grey = 0.0f;
|
||||
}
|
||||
glClearColor(grey, grey, grey, 1.0f);
|
||||
checkGlError("glClearColor");
|
||||
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
checkGlError("glClear");
|
||||
|
||||
glUseProgram(gProgram);
|
||||
checkGlError("glUseProgram");
|
||||
|
||||
glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
|
||||
checkGlError("glVertexAttribPointer");
|
||||
glEnableVertexAttribArray(gvPositionHandle);
|
||||
checkGlError("glEnableVertexAttribArray");
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
checkGlError("glDrawArrays");
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGl.h
|
||||
* @file ewol/openGL/openGL.h
|
||||
* @brief ewol openGl abstarction (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 19/09/2012
|
||||
@ -38,7 +38,8 @@ extern "C" {
|
||||
#include <GL/glext.h>
|
||||
*/
|
||||
#elif defined(__TARGET_OS__Android)
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#elif defined(__TARGET_OS__Windows)
|
||||
#include <GL/gl.h>
|
||||
#elif defined(__TARGET_OS__MacOs)
|
||||
@ -51,6 +52,9 @@ extern "C" {
|
||||
|
||||
void glOrthoEwol(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal);
|
||||
|
||||
bool TESTsetupGraphics(int w, int h);
|
||||
void TEST_renderFrame(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/openGl.cpp
|
||||
* @brief ewol openGl abstarction (sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 19/09/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ewol/openGl.h>
|
||||
|
||||
|
||||
void glOrthoEwol(GLfloat left,
|
||||
GLfloat right,
|
||||
GLfloat bottom,
|
||||
GLfloat top,
|
||||
GLfloat nearVal,
|
||||
GLfloat farVal)
|
||||
{
|
||||
GLfloat myMatrix[4*4];
|
||||
int iii;
|
||||
for(iii=0; iii<4*4 ; iii++) {
|
||||
myMatrix[iii] = 0;
|
||||
}
|
||||
myMatrix[0] = 2.0 / (right - left);
|
||||
myMatrix[5] = 2.0 / (top - bottom);
|
||||
myMatrix[10] = -2.0 / (farVal - nearVal);
|
||||
#if 1
|
||||
myMatrix[3] = -1*(right + left) / (right - left);
|
||||
myMatrix[7] = -1*(top + bottom) / (top - bottom);
|
||||
myMatrix[11] = -1*(farVal + nearVal) / (farVal - nearVal);
|
||||
#else
|
||||
// test if matrix is not corectly instanciate ...
|
||||
myMatrix[12] = -1*(right + left) / (right - left);
|
||||
myMatrix[13] = -1*(top + bottom) / (top - bottom);
|
||||
myMatrix[14] = -1*(farVal + nearVal) / (farVal - nearVal);
|
||||
#endif
|
||||
myMatrix[15] = 1;
|
||||
|
||||
glLoadMatrixf(myMatrix);
|
||||
|
||||
|
||||
}
|
@ -526,6 +526,7 @@ bool eSystem::Draw(bool displayEveryTime)
|
||||
// FPS display system
|
||||
l_FpsSystem.Tic();
|
||||
if (true == isGlobalSystemInit) {
|
||||
/*
|
||||
// process the events
|
||||
ewolProcessEvents();
|
||||
// call all the widget that neded to do something periodicly
|
||||
@ -548,6 +549,8 @@ bool eSystem::Draw(bool displayEveryTime)
|
||||
tmpWindows->SysDraw();
|
||||
}
|
||||
}
|
||||
*/
|
||||
TEST_renderFrame();
|
||||
glFlush();
|
||||
}
|
||||
// FPS display system
|
||||
|
@ -394,6 +394,8 @@ bool CreateOGlContext(void)
|
||||
} else {
|
||||
EWOL_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
// start openGL shader mode ...
|
||||
TESTsetupGraphics(400, 300);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user