[DEV] start gale integration
This commit is contained in:
parent
210d090e23
commit
b569e69297
@ -6,5 +6,5 @@ precision mediump int;
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = f_color;
|
||||
gl_FragColor = f_color;
|
||||
}
|
||||
|
@ -5,14 +5,13 @@ precision mediump int;
|
||||
|
||||
// Input :
|
||||
attribute vec3 EW_coord3d;
|
||||
attribute vec4 EW_color;
|
||||
uniform vec4 EW_color;
|
||||
uniform mat4 EW_MatrixTransformation;
|
||||
uniform mat4 EW_MatrixPosition;
|
||||
|
||||
// output :
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0);
|
||||
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
|
||||
f_color = EW_color;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ ewol::compositing::Area::Area(const ivec2& _size) :
|
||||
m_GLtexture(-1),
|
||||
m_GLtexID(-1),
|
||||
m_resource(nullptr) {
|
||||
m_resource = ewol::resource::Texture::create();
|
||||
m_resource = gale::resource::Texture::create();
|
||||
m_resource->setImageSize(_size);
|
||||
m_resource->flush();
|
||||
loadProgram();
|
||||
@ -35,7 +35,7 @@ ewol::compositing::Area::~Area() {
|
||||
void ewol::compositing::Area::loadProgram() {
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
m_GLprogram = ewol::resource::Program::create(std::string("DATA:textured3D.prog"));
|
||||
m_GLprogram = gale::resource::Program::create(std::string("DATA:textured3D.prog"));
|
||||
if (nullptr != m_GLprogram) {
|
||||
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->getAttribute("EW_color");
|
||||
@ -59,7 +59,7 @@ void ewol::compositing::Area::draw(bool _disableDepthTest) {
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply;
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix()*m_matrixApply;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// TextureID
|
||||
@ -71,7 +71,7 @@ void ewol::compositing::Area::draw(bool _disableDepthTest) {
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <etk/Color.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/compositing/Compositing.h>
|
||||
#include <ewol/resource/Program.h>
|
||||
#include <ewol/resource/Texture.h>
|
||||
#include <gale/resource/Program.h>
|
||||
#include <gale/resource/Texture.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace compositing {
|
||||
@ -22,14 +22,14 @@ namespace ewol {
|
||||
vec3 m_position; //!< The current position to draw
|
||||
etk::Color<> m_color; //!< The text foreground color
|
||||
private:
|
||||
std::shared_ptr<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
|
||||
std::shared_ptr<gale::resource::Program> m_GLprogram; //!< pointer on the opengl display program
|
||||
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
|
||||
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
|
||||
int32_t m_GLColor; //!< openGL id on the element (color buffer)
|
||||
int32_t m_GLtexture; //!< openGL id on the element (Texture position)
|
||||
int32_t m_GLtexID; //!< openGL id on the element (texture ID)
|
||||
private:
|
||||
std::shared_ptr<ewol::resource::Texture> m_resource; //!< texture resources
|
||||
std::shared_ptr<gale::resource::Texture> m_resource; //!< texture resources
|
||||
std::vector<vec3 > m_coord; //!< internal coord of the object
|
||||
std::vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
|
||||
std::vector<etk::Color<float> > m_coordColor; //!< internal color of the different point
|
||||
|
@ -306,7 +306,7 @@ void ewol::compositing::Drawing::draw(bool _disableDepthTest) {
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply;
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix()*m_matrixApply;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
mat4 tmpMatrix2;
|
||||
@ -316,7 +316,7 @@ void ewol::compositing::Drawing::draw(bool _disableDepthTest) {
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -71,12 +71,12 @@ void ewol::compositing::Image::draw(bool _disableDepthTest) {
|
||||
return;
|
||||
}
|
||||
if (_disableDepthTest == true) {
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
} else {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply;
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix()*m_matrixApply;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// TextureID
|
||||
@ -98,7 +98,7 @@ void ewol::compositing::Image::draw(bool _disableDepthTest) {
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ void ewol::compositing::Shaper::draw(bool _disableDepthTest) {
|
||||
//glScalef(m_scaling.x, m_scaling.y, 1.0);
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix();
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 2/*x,y*/, m_coord);
|
||||
@ -202,8 +202,8 @@ void ewol::compositing::Shaper::draw(bool _disableDepthTest) {
|
||||
m_GLprogram->setTexture0(m_GLtexID, m_resourceTexture->getId());
|
||||
}
|
||||
// Request the draw of the elements :
|
||||
//ewol::openGL::drawArrays(GL_TRIANGLES, 0, SHAPER_NB_MAX_VERTEX);
|
||||
ewol::openGL::drawArrays(GL_TRIANGLE_STRIP, 0, m_nbVertexToDisplay);
|
||||
//gale::openGL::drawArrays(GL_TRIANGLES, 0, SHAPER_NB_MAX_VERTEX);
|
||||
gale::openGL::drawArrays(GL_TRIANGLE_STRIP, 0, m_nbVertexToDisplay);
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,11 @@ void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _en
|
||||
return;
|
||||
}
|
||||
if (_enableDepthTest == true) {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::getMatrix();
|
||||
mat4 camMatrix = ewol::openGL::getCameraMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
@ -63,10 +63,10 @@ void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _en
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
if (_enableDepthTest == true) {
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ void ewol::compositing::Text::drawD(bool _disableDepthTest) {
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply;
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix()*m_matrixApply;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// Texture :
|
||||
@ -102,7 +102,7 @@ void ewol::compositing::Text::drawD(bool _disableDepthTest) {
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,11 @@ void ewol::compositing::TextDF::drawMT(const mat4& _transformationMatrix, bool _
|
||||
return;
|
||||
}
|
||||
if (_enableDepthTest == true) {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::getMatrix();
|
||||
mat4 camMatrix = ewol::openGL::getCameraMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
@ -72,10 +72,10 @@ void ewol::compositing::TextDF::drawMT(const mat4& _transformationMatrix, bool _
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
m_GLprogram->sendAttribute(m_GLglyphLevel, m_glyphLevel);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
if (_enableDepthTest == true) {
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ void ewol::compositing::TextDF::drawD(bool _disableDepthTest) {
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply;
|
||||
mat4 tmpMatrix = gale::openGL::getMatrix()*m_matrixApply;
|
||||
m_GLprogram->use();
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// Texture :
|
||||
@ -110,7 +110,7 @@ void ewol::compositing::TextDF::drawD(bool _disableDepthTest) {
|
||||
m_GLprogram->sendAttribute(m_GLColor, m_coordColor);
|
||||
m_GLprogram->sendAttribute(m_GLglyphLevel, m_glyphLevel);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, m_coord.size());
|
||||
m_GLprogram->unUse();
|
||||
}
|
||||
|
||||
|
@ -614,7 +614,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
|
||||
//! drawing section :
|
||||
{
|
||||
// Lock openGl context:
|
||||
ewol::openGL::lock();
|
||||
gale::openGL::lock();
|
||||
if (m_displayFps == true) {
|
||||
m_FpsSystemContext.tic();
|
||||
}
|
||||
@ -647,13 +647,13 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
|
||||
if (m_displayFps == true) {
|
||||
m_FpsFlush.incrementCounter();
|
||||
}
|
||||
ewol::openGL::flush();
|
||||
gale::openGL::flush();
|
||||
}
|
||||
if (m_displayFps == true) {
|
||||
m_FpsFlush.toc();
|
||||
}
|
||||
// release open GL Context
|
||||
ewol::openGL::unLock();
|
||||
gale::openGL::unLock();
|
||||
}
|
||||
if (m_displayFps == true) {
|
||||
m_FpsSystemEvent.draw();
|
||||
@ -665,11 +665,11 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
|
||||
// set the curent interface :
|
||||
lockContext();
|
||||
// release open GL Context
|
||||
ewol::openGL::lock();
|
||||
gale::openGL::lock();
|
||||
// while The Gui is drawing in OpenGl, we do some not realTime things
|
||||
m_resourceManager.updateContext();
|
||||
// release open GL Context
|
||||
ewol::openGL::unLock();
|
||||
gale::openGL::unLock();
|
||||
m_objectManager.cleanInternalRemoved();
|
||||
m_resourceManager.cleanInternalRemoved();
|
||||
// release the curent interface :
|
||||
|
@ -1,496 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <etk/stdTools.h>
|
||||
#include <mutex>
|
||||
//#define DIRECT_MODE
|
||||
|
||||
#define CHECK_ERROR_OPENGL
|
||||
|
||||
static void checkGlError(const char* _op, int32_t _localLine) {
|
||||
#ifdef CHECK_ERROR_OPENGL
|
||||
bool hasError = false;
|
||||
for (GLint error = glGetError(); error; error = glGetError()) {
|
||||
EWOL_ERROR("after " << _op << "():" << _localLine << " glError(" << error << ")");
|
||||
hasError = true;
|
||||
}
|
||||
if (hasError == true) {
|
||||
EWOL_CRITICAL("plop");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define OPENGL_ERROR(data) do { } while (false)
|
||||
//#define OPENGL_ERROR(data) EWOL_ERROR(data)
|
||||
#define OPENGL_WARNING(data) do { } while (false)
|
||||
//#define OPENGL_WARNING(data) EWOL_WARNING(data)
|
||||
#define OPENGL_INFO(data) do { } while (false)
|
||||
//#define OPENGL_INFO(data) EWOL_INFO(data)
|
||||
|
||||
|
||||
/**
|
||||
* @brief get the draw mutex (ewol render).
|
||||
* @note due ti the fact that the system can be called for multiple instance, for naw we just limit the acces to one process at a time.
|
||||
* @return the main inteface Mutex
|
||||
*/
|
||||
static std::mutex& mutexOpenGl() {
|
||||
static std::mutex s_drawMutex;
|
||||
return s_drawMutex;
|
||||
}
|
||||
|
||||
std::vector<mat4> l_matrixList;
|
||||
mat4 l_matrixCamera;
|
||||
static uint32_t l_flagsCurrent = 0;
|
||||
static uint32_t l_flagsMustBeSet = 0;
|
||||
static uint32_t l_textureflags = 0;
|
||||
static int32_t l_programId = 0;
|
||||
|
||||
|
||||
void ewol::openGL::lock() {
|
||||
mutexOpenGl().lock();
|
||||
l_matrixList.clear();
|
||||
mat4 tmpMat;
|
||||
l_matrixList.push_back(tmpMat);
|
||||
l_matrixCamera.identity();
|
||||
l_flagsCurrent = 0;
|
||||
l_flagsMustBeSet = 0;
|
||||
l_textureflags = 0;
|
||||
l_programId = -1;
|
||||
}
|
||||
|
||||
void ewol::openGL::unLock() {
|
||||
mutexOpenGl().unlock();
|
||||
}
|
||||
|
||||
void ewol::openGL::setBasicMatrix(const mat4& _newOne) {
|
||||
if (l_matrixList.size()!=1) {
|
||||
EWOL_ERROR("matrix is not corect size in the stack : " << l_matrixList.size());
|
||||
}
|
||||
l_matrixList.clear();
|
||||
l_matrixList.push_back(_newOne);
|
||||
}
|
||||
|
||||
void ewol::openGL::setMatrix(const mat4& _newOne) {
|
||||
if (l_matrixList.size() == 0) {
|
||||
EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
l_matrixList.push_back(_newOne);
|
||||
return;
|
||||
}
|
||||
l_matrixList[l_matrixList.size()-1] = _newOne;
|
||||
}
|
||||
|
||||
void ewol::openGL::push() {
|
||||
if (l_matrixList.size() == 0) {
|
||||
EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
return;
|
||||
}
|
||||
mat4 tmp = l_matrixList[l_matrixList.size()-1];
|
||||
l_matrixList.push_back(tmp);
|
||||
}
|
||||
|
||||
void ewol::openGL::pop() {
|
||||
if (l_matrixList.size() <= 1) {
|
||||
EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
l_matrixList.clear();
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
l_matrixCamera.identity();
|
||||
return;
|
||||
}
|
||||
l_matrixList.pop_back();
|
||||
l_matrixCamera.identity();
|
||||
}
|
||||
|
||||
const mat4& ewol::openGL::getMatrix() {
|
||||
if (l_matrixList.size() == 0) {
|
||||
EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
}
|
||||
return l_matrixList[l_matrixList.size()-1];
|
||||
}
|
||||
|
||||
const mat4& ewol::openGL::getCameraMatrix() {
|
||||
return l_matrixCamera;
|
||||
}
|
||||
|
||||
void ewol::openGL::setCameraMatrix(const mat4& _newOne) {
|
||||
l_matrixCamera = _newOne;
|
||||
}
|
||||
|
||||
void ewol::openGL::finish() {
|
||||
l_programId = -1;
|
||||
l_textureflags = 0;
|
||||
}
|
||||
|
||||
void ewol::openGL::flush() {
|
||||
l_programId = -1;
|
||||
l_textureflags = 0;
|
||||
glFlush();
|
||||
OPENGL_INFO("========================" );
|
||||
OPENGL_INFO("== FLUSH OPEN GL ==" );
|
||||
OPENGL_INFO("========================");
|
||||
}
|
||||
|
||||
void ewol::openGL::swap() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::ostream& ewol::operator <<(std::ostream& _os, const enum openGL::openGlFlags& _obj) {
|
||||
static std::vector<std::pair<enum openGL::openGlFlags, const char*>> list = {
|
||||
std::make_pair(openGL::FLAG_BLEND, "FLAG_BLEND"),
|
||||
std::make_pair(openGL::FLAG_CLIP_DISTANCE_I, "FLAG_CLIP_DISTANCE_I"),
|
||||
std::make_pair(openGL::FLAG_COLOR_LOGIC_OP, "FLAG_COLOR_LOGIC_OP"),
|
||||
std::make_pair(openGL::FLAG_CULL_FACE, "FLAG_CULL_FACE"),
|
||||
std::make_pair(openGL::FLAG_DEBUG_OUTPUT, "FLAG_DEBUG_OUTPUT"),
|
||||
std::make_pair(openGL::FLAG_DEBUG_OUTPUT_SYNCHRONOUS, "FLAG_DEBUG_OUTPUT_SYNCHRONOUS"),
|
||||
std::make_pair(openGL::FLAG_DEPTH_CLAMP, "FLAG_DEPTH_CLAMP"),
|
||||
std::make_pair(openGL::FLAG_DEPTH_TEST, "FLAG_DEPTH_TEST"),
|
||||
std::make_pair(openGL::FLAG_DITHER, "FLAG_DITHER"),
|
||||
std::make_pair(openGL::FLAG_FRAMEBUFFER_SRGB, "FLAG_FRAMEBUFFER_SRGB"),
|
||||
std::make_pair(openGL::FLAG_LINE_SMOOTH, "FLAG_LINE_SMOOTH"),
|
||||
std::make_pair(openGL::FLAG_MULTISAMPLE, "FLAG_MULTISAMPLE"),
|
||||
std::make_pair(openGL::FLAG_POLYGON_OFFSET_FILL, "FLAG_POLYGON_OFFSET_FILL"),
|
||||
std::make_pair(openGL::FLAG_POLYGON_OFFSET_LINE, "FLAG_POLYGON_OFFSET_LINE"),
|
||||
std::make_pair(openGL::FLAG_POLYGON_OFFSET_POINT, "FLAG_POLYGON_OFFSET_POINT"),
|
||||
std::make_pair(openGL::FLAG_POLYGON_SMOOTH, "FLAG_POLYGON_SMOOTH"),
|
||||
std::make_pair(openGL::FLAG_PRIMITIVE_RESTART, "FLAG_PRIMITIVE_RESTART"),
|
||||
std::make_pair(openGL::FLAG_PRIMITIVE_RESTART_FIXED_INDEX, "FLAG_PRIMITIVE_RESTART_FIXED_INDEX"),
|
||||
std::make_pair(openGL::FLAG_SAMPLE_ALPHA_TO_COVERAGE, "FLAG_SAMPLE_ALPHA_TO_COVERAGE"),
|
||||
std::make_pair(openGL::FLAG_SAMPLE_ALPHA_TO_ONE, "FLAG_SAMPLE_ALPHA_TO_ONE"),
|
||||
std::make_pair(openGL::FLAG_SAMPLE_COVERAGE, "FLAG_SAMPLE_COVERAGE"),
|
||||
std::make_pair(openGL::FLAG_SAMPLE_SHADING, "FLAG_SAMPLE_SHADING"),
|
||||
std::make_pair(openGL::FLAG_SAMPLE_MASK, "FLAG_SAMPLE_MASK"),
|
||||
std::make_pair(openGL::FLAG_SCISSOR_TEST, "FLAG_SCISSOR_TEST"),
|
||||
std::make_pair(openGL::FLAG_STENCIL_TEST, "FLAG_STENCIL_TEST"),
|
||||
std::make_pair(openGL::FLAG_PROGRAM_POINT_SIZE, "FLAG_PROGRAM_POINT_SIZE"),
|
||||
std::make_pair(openGL::FLAG_TEXTURE_2D, "FLAG_TEXTURE_2D"),
|
||||
std::make_pair(openGL::FLAG_ALPHA_TEST, "FLAG_ALPHA_TEST"),
|
||||
std::make_pair(openGL::FLAG_FOG, "FLAG_FOG")
|
||||
};
|
||||
_os << "{";
|
||||
bool hasOne = false;
|
||||
for (auto &it : list) {
|
||||
if ((_obj & it.first) != 0) {
|
||||
if (hasOne==true) {
|
||||
_os << ",";
|
||||
}
|
||||
_os << it.second;
|
||||
hasOne = true;
|
||||
}
|
||||
}
|
||||
_os << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::pair<enum ewol::openGL::renderMode, std::string>>& getListRenderMode() {
|
||||
static std::vector<std::pair<enum ewol::openGL::renderMode, std::string>> list = {
|
||||
std::make_pair(ewol::openGL::renderPoint, "POINTS"),
|
||||
std::make_pair(ewol::openGL::renderLine, "LINES"),
|
||||
std::make_pair(ewol::openGL::renderLineStrip, "LINES_STRIP"),
|
||||
std::make_pair(ewol::openGL::renderLineLoop, "LINE_LOOP"),
|
||||
std::make_pair(ewol::openGL::renderTriangle, "TRIANGLE"),
|
||||
std::make_pair(ewol::openGL::renderTriangleStrip, "TRIANGLE_STRIP"),
|
||||
std::make_pair(ewol::openGL::renderTriangleFan, "TRIANGLE_FAN"),
|
||||
std::make_pair(ewol::openGL::renderQuad, "QUAD"),
|
||||
std::make_pair(ewol::openGL::renderQuadStrip, "QUAD_STRIP"),
|
||||
std::make_pair(ewol::openGL::renderPolygon, "POLYGON"),
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<ewol::openGL::renderMode>(const ewol::openGL::renderMode& _obj) {
|
||||
for (auto &it : getListRenderMode()) {
|
||||
if (it.first == _obj) {
|
||||
return it.second;
|
||||
}
|
||||
}
|
||||
EWOL_ERROR("Can not convert : " << static_cast<int32_t>(_obj) << " return UNKNOW");
|
||||
return "UNKNOW";
|
||||
}
|
||||
template<> std::u32string to_u32string<ewol::openGL::renderMode>(const ewol::openGL::renderMode& _obj) {
|
||||
return etk::to_u32string(etk::to_string(_obj));
|
||||
}
|
||||
template<> bool from_string<ewol::openGL::renderMode>(ewol::openGL::renderMode& _variableRet, const std::string& _value) {
|
||||
for (auto &it : getListRenderMode()) {
|
||||
if (it.second == _value) {
|
||||
_variableRet = it.first;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
EWOL_WARNING("Can not parse : '" << _value << "' set Triangle default value");
|
||||
_variableRet = ewol::openGL::renderTriangle;
|
||||
return false;
|
||||
}
|
||||
template<> bool from_string<ewol::openGL::renderMode>(ewol::openGL::renderMode& _variableRet, const std::u32string& _value) {
|
||||
return from_string(_variableRet, etk::to_string(_value));
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& ewol::operator <<(std::ostream& _os, const enum openGL::renderMode& _obj) {
|
||||
_os << etk::to_string(_obj);
|
||||
return _os;
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t curentFlag;
|
||||
GLenum OGlFlag;
|
||||
} correspondenceTable_ts;
|
||||
|
||||
static correspondenceTable_ts basicFlag[] = {
|
||||
{(uint32_t)ewol::openGL::FLAG_BLEND, GL_BLEND},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_CLIP_DISTANCE_I, GL_CLIP_DISTANCE0},
|
||||
{(uint32_t)ewol::openGL::FLAG_COLOR_LOGIC_OP, GL_COLOR_LOGIC_OP},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_CULL_FACE, GL_CULL_FACE},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_DEBUG_OUTPUT, GL_DEBUG_OUTPUT},
|
||||
{(uint32_t)ewol::openGL::FLAG_DEBUG_OUTPUT_SYNCHRONOUS, GL_DEBUG_OUTPUT_SYNCHRONOUS},
|
||||
{(uint32_t)ewol::openGL::FLAG_DEPTH_CLAMP, GL_DEPTH_CLAMP},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_DEPTH_TEST, GL_DEPTH_TEST},
|
||||
{(uint32_t)ewol::openGL::FLAG_DITHER, GL_DITHER},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_FRAMEBUFFER_SRGB, GL_FRAMEBUFFER_SRGB},
|
||||
{(uint32_t)ewol::openGL::FLAG_LINE_SMOOTH, GL_LINE_SMOOTH},
|
||||
{(uint32_t)ewol::openGL::FLAG_MULTISAMPLE, GL_MULTISAMPLE},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_FILL},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_LINE, GL_POLYGON_OFFSET_LINE},
|
||||
{(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_POINT, GL_POLYGON_OFFSET_POINT},
|
||||
{(uint32_t)ewol::openGL::FLAG_POLYGON_SMOOTH, GL_POLYGON_SMOOTH},
|
||||
{(uint32_t)ewol::openGL::FLAG_PRIMITIVE_RESTART, GL_PRIMITIVE_RESTART},
|
||||
{(uint32_t)ewol::openGL::FLAG_PRIMITIVE_RESTART_FIXED_INDEX, GL_PRIMITIVE_RESTART_FIXED_INDEX},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_SAMPLE_ALPHA_TO_COVERAGE, GL_SAMPLE_ALPHA_TO_COVERAGE},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_SAMPLE_ALPHA_TO_ONE, GL_SAMPLE_ALPHA_TO_ONE},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_SAMPLE_COVERAGE, GL_SAMPLE_COVERAGE},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_SAMPLE_SHADING, GL_SAMPLE_SHADING},
|
||||
{(uint32_t)ewol::openGL::FLAG_SAMPLE_MASK, GL_SAMPLE_MASK},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_SCISSOR_TEST, GL_SCISSOR_TEST},
|
||||
{(uint32_t)ewol::openGL::FLAG_STENCIL_TEST, GL_STENCIL_TEST},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_PROGRAM_POINT_SIZE, GL_PROGRAM_POINT_SIZE},
|
||||
#endif
|
||||
{(uint32_t)ewol::openGL::FLAG_TEXTURE_2D, GL_TEXTURE_2D},
|
||||
#if 0
|
||||
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
|
||||
{(uint32_t)ewol::openGL::FLAG_ALPHA_TEST, GL_ALPHA_TEST},
|
||||
{(uint32_t)ewol::openGL::FLAG_FOG, GL_FOG}
|
||||
#endif
|
||||
//{(uint32_t)ewol::openGL::FLAG_, GL_}
|
||||
};
|
||||
static int32_t basicFlagCount = sizeof(basicFlag) / sizeof(correspondenceTable_ts);
|
||||
|
||||
void ewol::openGL::reset() {
|
||||
#ifdef DIRECT_MODE
|
||||
EWOL_TODO("...");
|
||||
#else
|
||||
l_flagsMustBeSet = 0;
|
||||
l_programId = -1;
|
||||
l_textureflags = 0;
|
||||
updateAllFlags();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ewol::openGL::enable(enum ewol::openGL::openGlFlags _flagID) {
|
||||
//EWOL_INFO("Enable : " <EWOL_ERROR< _flagID);
|
||||
#ifdef DIRECT_MODE
|
||||
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
|
||||
if ( basicFlag[iii].curentFlag == (uint32_t)_flagID ) {
|
||||
glEnable(basicFlag[iii].OGlFlag);
|
||||
}
|
||||
}
|
||||
# else
|
||||
//EWOL_DEBUG("Enable FLAGS = " << l_flagsMustBeSet);
|
||||
l_flagsMustBeSet |= (uint32_t)_flagID;
|
||||
//EWOL_DEBUG(" == >" << l_flagsMustBeSet);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ewol::openGL::disable(enum ewol::openGL::openGlFlags _flagID) {
|
||||
//EWOL_INFO("Disable : " << _flagID);
|
||||
#ifdef DIRECT_MODE
|
||||
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
|
||||
if ( basicFlag[iii].curentFlag == (uint32_t)_flagID ) {
|
||||
glDisable(basicFlag[iii].OGlFlag);
|
||||
}
|
||||
}
|
||||
# else
|
||||
//EWOL_DEBUG("Disable FLAGS = " << l_flagsMustBeSet);
|
||||
l_flagsMustBeSet &= ~((uint32_t)_flagID);
|
||||
//EWOL_DEBUG(" == >" << l_flagsMustBeSet);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ewol::openGL::updateAllFlags() {
|
||||
#ifdef DIRECT_MODE
|
||||
return;
|
||||
#endif
|
||||
// check if fhags has change :
|
||||
if (l_flagsMustBeSet == l_flagsCurrent ) {
|
||||
OPENGL_INFO("OGL: current flag : " << (enum openGL::openGlFlags)l_flagsMustBeSet);
|
||||
return;
|
||||
}
|
||||
OPENGL_INFO("OGL: set new flag : " << (enum openGL::openGlFlags)l_flagsMustBeSet);
|
||||
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
|
||||
uint32_t CurrentFlag = basicFlag[iii].curentFlag;
|
||||
if ( (l_flagsMustBeSet&CurrentFlag)!=(l_flagsCurrent&CurrentFlag) ) {
|
||||
if ( (l_flagsMustBeSet&CurrentFlag) != 0) {
|
||||
glEnable(basicFlag[iii].OGlFlag);
|
||||
OPENGL_INFO(" enable : " << (enum openGL::openGlFlags)basicFlag[iii].curentFlag);
|
||||
} else {
|
||||
glDisable(basicFlag[iii].OGlFlag);
|
||||
OPENGL_INFO(" disable : " << (enum openGL::openGlFlags)basicFlag[iii].curentFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
l_flagsCurrent = l_flagsMustBeSet;
|
||||
}
|
||||
|
||||
|
||||
void ewol::openGL::activeTexture(uint32_t _flagID) {
|
||||
if (l_programId >= 0) {
|
||||
glActiveTexture(_flagID);
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::desActiveTexture(uint32_t _flagID) {
|
||||
if (l_programId >= 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::drawArrays(uint32_t _mode, int32_t _first, int32_t _count) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
glDrawArrays(_mode, _first, _count);
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::drawElements(uint32_t _mode, const std::vector<uint32_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
//EWOL_DEBUG("Request draw of " << indices.size() << "elements");
|
||||
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_INT, &_indices[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::drawElements16(uint32_t _mode, const std::vector<uint16_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::drawElements8(uint32_t _mode, const std::vector<uint8_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_BYTE, &_indices[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::openGL::useProgram(int32_t _id) {
|
||||
//EWOL_DEBUG("USE prog : " << id);
|
||||
#if 1
|
||||
// note : In normal openGL case, the system might call with the program ID and at the end with 0,
|
||||
// here, we wrap this use to prevent over call of glUseProgram == > then we set -1 when the
|
||||
// user no more use this program, and just stop grnerating. (chen 0 == > this is an errored program ...
|
||||
if (-1 == _id) {
|
||||
// not used == > because it is unneded
|
||||
return;
|
||||
}
|
||||
if (l_programId != _id) {
|
||||
l_programId = _id;
|
||||
glUseProgram(l_programId);
|
||||
}
|
||||
#else
|
||||
if (-1 == _id) {
|
||||
glUseProgram(0);
|
||||
} else {
|
||||
l_programId = _id;
|
||||
glUseProgram(_id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ewol::openGL::genBuffers(std::vector<GLuint>& _buffers) {
|
||||
if (_buffers.size() == 0) {
|
||||
EWOL_WARNING("try to generate vector buffer with size 0");
|
||||
return true;
|
||||
}
|
||||
OPENGL_INFO("Create N=" << _buffers.size() << " Buffer");
|
||||
glGenBuffers(_buffers.size(), &_buffers[0]);
|
||||
checkGlError("glGenBuffers", __LINE__);
|
||||
bool hasError = false;
|
||||
for (size_t iii=0; iii<_buffers.size(); iii++) {
|
||||
if (_buffers[iii] == 0) {
|
||||
EWOL_ERROR("[" << iii << "] error to create a buffer id=" << _buffers[iii]);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
return hasError;
|
||||
}
|
||||
|
||||
bool ewol::openGL::deleteBuffers(std::vector<GLuint>& _buffers) {
|
||||
if (_buffers.size() == 0) {
|
||||
EWOL_WARNING("try to delete vector buffer with size 0");
|
||||
return true;
|
||||
}
|
||||
glDeleteBuffers(_buffers.size(), &_buffers[0]);
|
||||
checkGlError("glDeleteBuffers", __LINE__);
|
||||
for (auto &it : _buffers) {
|
||||
it = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ewol::openGL::bindBuffer(GLuint _bufferId) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _bufferId);
|
||||
checkGlError("glBindBuffer", __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ewol::openGL::bufferData(size_t _size, const void* _data, GLenum _usage) {
|
||||
glBufferData(GL_ARRAY_BUFFER, _size, _data, _usage);
|
||||
checkGlError("glBufferData", __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ewol::openGL::unbindBuffer() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
checkGlError("glBindBuffer(0)", __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,213 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL_H__
|
||||
#define __OPEN_GL_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <vector>
|
||||
#include <etk/math/Matrix4.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__TARGET_OS__Linux)
|
||||
// TO ENABLE THE SHADER api ...
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
// TODO : Check it it work
|
||||
// This is to prevent the use of these element that is not allowed in the openGL ES
|
||||
#undef glVertexPointer
|
||||
#undef glTexCoordPointer
|
||||
#undef glColorPointer
|
||||
#undef glPopMatrix
|
||||
#undef glPushMatrix
|
||||
#undef glMatrixMode
|
||||
#undef glLoadIdentity
|
||||
#undef glTranslatef
|
||||
#elif defined(__TARGET_OS__Android)
|
||||
// Include openGL ES 2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#elif defined(__TARGET_OS__Windows)
|
||||
// TO ENABLE THE SHADER api ...
|
||||
//#define GL_GLEXT_PROTOTYPES
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
#elif defined(__TARGET_OS__MacOs)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#elif defined(__TARGET_OS__IOs)
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#else
|
||||
#error you need to specify a __TAGET_OS__ ...
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace ewol {
|
||||
namespace openGL {
|
||||
/**
|
||||
* @brief Lock the openGL context for one user only == > better to keep flags and other things ...
|
||||
*/
|
||||
void lock();
|
||||
/**
|
||||
* @brief Un-lock the openGL context for an other user...
|
||||
*/
|
||||
void unLock();
|
||||
/**
|
||||
* @brief When you will done an opengl rendering, you might call this reset matrix first. It remove all the stach of the matrix pushed.
|
||||
* @param[in] _newOne the default matrix that might be set for the graphic card for renderer. if too more pop will be done, this is the last that mmight survived
|
||||
*/
|
||||
void setBasicMatrix(const mat4& _newOne);
|
||||
/**
|
||||
* @brief this funtion configure the current use matrix for the renderer (call @ref Push before, and @ref Pop when no more needed).
|
||||
* @param[in] _newOne The new current matrix use for the render.
|
||||
* @note We did not use opengl standard system, due to the fact that is not supported in opengl ES-2
|
||||
*/
|
||||
void setMatrix(const mat4& _newOne);
|
||||
/**
|
||||
* @brief store current matrix in the matrix stack.
|
||||
*/
|
||||
void push();
|
||||
/**
|
||||
* @brief remove the current matrix and get the last one from the matrix stack.
|
||||
*/
|
||||
void pop();
|
||||
/**
|
||||
* @brief get a reference on the current matrix destinate to opengl renderer.
|
||||
* @return The requested matrix.
|
||||
*/
|
||||
const mat4& getMatrix();
|
||||
/**
|
||||
* @brief get a reference on the current matrix camera destinate to opengl renderer.
|
||||
* @return The requested matrix.
|
||||
*/
|
||||
const mat4& getCameraMatrix();
|
||||
/**
|
||||
* @brief set a reference on the current camera to opengl renderer.
|
||||
* @param[in] _newOne The requested matrix.
|
||||
*/
|
||||
void setCameraMatrix(const mat4& _newOne);
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void finish();
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void flush();
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void swap();
|
||||
|
||||
enum openGlFlags {
|
||||
FLAG_BLEND = 1<<0, //!< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
|
||||
FLAG_CLIP_DISTANCE_I = 1<<1, //!< If enabled, clip geometry against user-defined half space i.
|
||||
FLAG_COLOR_LOGIC_OP = 1<<2, //!< If enabled, apply the currently selected logical operation to the computed fragment color and color buffer values. See glLogicOp.
|
||||
FLAG_CULL_FACE = 1<<3, //!< If enabled, cull polygons based on their winding in window coordinates. See glCullFace.
|
||||
FLAG_DEBUG_OUTPUT = 1<<4, //!< If enabled, debug messages are produced by a debug context. When disabled, the debug message log is silenced. Note that in a non-debug context, very few, if any messages might be produced, even when GL_DEBUG_OUTPUT is enabled.
|
||||
FLAG_DEBUG_OUTPUT_SYNCHRONOUS = 1<<5, //!< If enabled, debug messages are produced synchronously by a debug context. If disabled, debug messages may be produced asynchronously. In particular, they may be delayed relative to the execution of GL commands, and the debug callback function may be called from a thread other than that in which the commands are executed. See glDebugMessageCallback.
|
||||
FLAG_DEPTH_CLAMP = 1<<6, //!< If enabled, the -wc≤zc≤wc plane equation is ignored by view volume clipping (effectively, there is no near or far plane clipping). See glDepthRange.
|
||||
FLAG_DEPTH_TEST = 1<<7, //!< If enabled, do depth comparisons and update the depth buffer. Note that even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRange.
|
||||
FLAG_DITHER = 1<<8, //!< If enabled, dither color components or indices before they are written to the color buffer.
|
||||
FLAG_FRAMEBUFFER_SRGB = 1<<9, //!< If enabled and the value of GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment corresponding to the destination buffer is GL_SRGB, the R, G, and B destination color values (after conversion from fixed-point to floating-point) are considered to be encoded for the sRGB color space and hence are linearized prior to their use in blending.
|
||||
FLAG_LINE_SMOOTH = 1<<10, //!< If enabled, draw lines with correct filtering. Otherwise, draw aliased lines. See glLineWidth.
|
||||
FLAG_MULTISAMPLE = 1<<11, //!< If enabled, use multiple fragment samples in computing the final color of a pixel. See glSampleCoverage.
|
||||
FLAG_POLYGON_OFFSET_FILL = 1<<12, //!< If enabled, and if the polygon is rendered in GL_FILL mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
|
||||
FLAG_POLYGON_OFFSET_LINE = 1<<13, //!< If enabled, and if the polygon is rendered in GL_LINE mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
|
||||
FLAG_POLYGON_OFFSET_POINT = 1<<14, //!< If enabled, an offset is added to depth values of a polygon's fragments before the depth comparison is performed, if the polygon is rendered in GL_POINT mode. See glPolygonOffset.
|
||||
FLAG_POLYGON_SMOOTH = 1<<15, //!< If enabled, draw polygons with proper filtering. Otherwise, draw aliased polygons. For correct antialiased polygons, an alpha buffer is needed and the polygons must be sorted front to back.
|
||||
FLAG_PRIMITIVE_RESTART = 1<<16, //!< enables primitive restarting. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the primitive restart index. See glPrimitiveRestartIndex.
|
||||
FLAG_PRIMITIVE_RESTART_FIXED_INDEX = 1<<17, //!< enables primitive restarting with a fixed index. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the fixed primitive index for the specified index type. The fixed index is equal to 2n−1 where n is equal to 8 for GL_UNSIGNED_BYTE, 16 for GL_UNSIGNED_SHORT and 32 for GL_UNSIGNED_INT.
|
||||
FLAG_SAMPLE_ALPHA_TO_COVERAGE = 1<<18, //!< If enabled, compute a temporary coverage value where each bit is determined by the alpha value at the corresponding sample location. The temporary coverage value is then ANDed with the fragment coverage value.
|
||||
FLAG_SAMPLE_ALPHA_TO_ONE = 1<<19, //!< If enabled, each sample alpha value is replaced by the maximum representable alpha value.
|
||||
FLAG_SAMPLE_COVERAGE = 1<<20, //!< If enabled, the fragment's coverage is ANDed with the temporary coverage value. If GL_SAMPLE_COVERAGE_INVERT is set to GL_TRUE, invert the coverage value. See glSampleCoverage.
|
||||
FLAG_SAMPLE_SHADING = 1<<21, //!< If enabled, the active fragment shader is run once for each covered sample, or at fraction of this rate as determined by the current value of GL_MIN_SAMPLE_SHADING_VALUE. See glMinSampleShading.
|
||||
FLAG_SAMPLE_MASK = 1<<22, //!< If enabled, the sample coverage mask generated for a fragment during rasterization will be ANDed with the value of GL_SAMPLE_MASK_VALUE before shading occurs. See glSampleMaski.
|
||||
FLAG_SCISSOR_TEST = 1<<23, //!< If enabled, discard fragments that are outside the scissor rectangle. See glScissor.
|
||||
FLAG_STENCIL_TEST = 1<<24, //!< If enabled, do stencil testing and update the stencil buffer. See glStencilFunc and glStencilOp. GL_TEXTURE_CUBE_MAP_SEAMLESS = 1<<0, //!< If enabled, cubemap textures are sampled such that when linearly sampling from the border between two adjacent faces, texels from both faces are used to generate the final sample value. When disabled, texels from only a single face are used to construct the final sample value.
|
||||
FLAG_PROGRAM_POINT_SIZE = 1<<25, //!< If enabled and a vertex or geometry shader is active, then the derived point size is taken from the (potentially clipped) shader builtin gl_PointSize and clamped to the implementation-dependent point size range.
|
||||
FLAG_TEXTURE_2D = 1<<26, //!<
|
||||
FLAG_ALPHA_TEST = 1<<27, //!<
|
||||
FLAG_FOG = 1<<28, //!<
|
||||
};
|
||||
enum renderMode {
|
||||
renderPoint = GL_POINTS,
|
||||
renderLine = GL_LINES,
|
||||
renderLineStrip = GL_LINE_STRIP, //!< Not supported in EWOL (TODO : Later)
|
||||
renderLineLoop = GL_LINE_LOOP,
|
||||
renderTriangle = GL_TRIANGLES,
|
||||
renderTriangleStrip = GL_TRIANGLE_STRIP, //!< Not supported in EWOL (TODO : Later)
|
||||
renderTriangleFan = GL_TRIANGLE_FAN, //!< Not supported in EWOL (TODO : Later)
|
||||
#if (!defined(__TARGET_OS__IOs) && !defined(__TARGET_OS__Android))
|
||||
renderQuad = GL_QUADS, //!< Not supported in OpenGL-ES2
|
||||
renderQuadStrip = GL_QUAD_STRIP, //!< Not supported in OpenGL-ES2
|
||||
renderPolygon = GL_POLYGON //!< Not supported in OpenGL-ES2
|
||||
#else
|
||||
renderQuad, //!< Not supported in OpenGL-ES2
|
||||
renderQuadStrip, //!< Not supported in OpenGL-ES2
|
||||
renderPolygon //!< Not supported in OpenGL-ES2
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief enable a flag on the system
|
||||
* @param[in] flagID The flag requested
|
||||
*/
|
||||
void enable(enum openGlFlags _flagID);
|
||||
/**
|
||||
* @brief disable a flag on the system
|
||||
* @param[in] flagID The flag requested
|
||||
*/
|
||||
void disable(enum openGlFlags _flagID);
|
||||
/**
|
||||
* @brieg update all the internal flag needed to be set from tre previous element set ...
|
||||
*/
|
||||
void updateAllFlags();
|
||||
/**
|
||||
* @brief enable Texture on the system
|
||||
* @param[in] flagID The flag requested
|
||||
*/
|
||||
void activeTexture(uint32_t _flagID);
|
||||
/**
|
||||
* @brief disable Texture on the system
|
||||
* @param[in] flagID The flag requested
|
||||
*/
|
||||
void desActiveTexture(uint32_t _flagID);
|
||||
/**
|
||||
* @brief draw a specific array == > this enable mode difference ...
|
||||
*/
|
||||
void drawArrays(uint32_t _mode, int32_t _first, int32_t _count);
|
||||
void drawElements (uint32_t _mode, const std::vector<uint32_t>& _indices);
|
||||
void drawElements16(uint32_t _mode, const std::vector<uint16_t>& _indices);
|
||||
void drawElements8 (uint32_t _mode, const std::vector<uint8_t>& _indices);
|
||||
/**
|
||||
* @brief Use openGL program
|
||||
* @param[in] id Id of the program that might be used
|
||||
*/
|
||||
void useProgram(int32_t _id);
|
||||
void reset();
|
||||
|
||||
|
||||
bool genBuffers(std::vector<GLuint>& _buffers);
|
||||
bool deleteBuffers(std::vector<GLuint>& _buffers);
|
||||
bool bindBuffer(GLuint _bufferId);
|
||||
bool bufferData(size_t _size, const void* _data, GLenum _usage);
|
||||
bool unbindBuffer();
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, const enum openGL::openGlFlags& _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, const enum openGL::renderMode& _obj);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -23,8 +23,8 @@ void ewol::resource::Colored3DObject::init() {
|
||||
ewol::Resource::init();
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
m_GLprogram = ewol::resource::Program::create("DATA:simple3D.prog");
|
||||
if (nullptr != m_GLprogram ) {
|
||||
m_GLprogram = gale::resource::Program::create("DATA:simple3D.prog");
|
||||
if (m_GLprogram != nullptr) {
|
||||
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->getUniform("EW_color");
|
||||
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
|
||||
@ -48,7 +48,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
return;
|
||||
}
|
||||
if (true == _depthtest) {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
@ -56,8 +56,8 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::getMatrix();
|
||||
mat4 camMatrix = ewol::openGL::getCameraMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
@ -65,7 +65,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, _vertices.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
// Request the draw od the elements :
|
||||
//glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
@ -74,7 +74,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
return;
|
||||
}
|
||||
if (true == _depthtest) {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
@ -99,8 +99,8 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::getMatrix();
|
||||
mat4 camMatrix = ewol::openGL::getCameraMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
@ -108,13 +108,13 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_TRIANGLES, 0, _vertices.size());
|
||||
gale::openGL::drawArrays(GL_TRIANGLES, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
if (true == _depthtest) {
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
return;
|
||||
}
|
||||
if (true == _depthtest) {
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::enable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
@ -139,8 +139,8 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::getMatrix();
|
||||
mat4 camMatrix = ewol::openGL::getCameraMatrix();
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
@ -148,13 +148,13 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
ewol::openGL::drawArrays(GL_LINES, 0, _vertices.size());
|
||||
gale::openGL::drawArrays(GL_LINES, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
if (true == _depthtest) {
|
||||
if (false == _updateDepthBuffer) {
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,13 @@
|
||||
#include <etk/types.h>
|
||||
#include <ewol/resource/Resource.h>
|
||||
#include <ewol/resource/Image.h>
|
||||
#include <ewol/resource/Shader.h>
|
||||
#include <ewol/resource/Program.h>
|
||||
#include <gale/resource/Program.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace resource {
|
||||
class Colored3DObject : public ewol::Resource {
|
||||
protected:
|
||||
std::shared_ptr<ewol::resource::Program> m_GLprogram;
|
||||
std::shared_ptr<gale::resource::Program> m_GLprogram;
|
||||
int32_t m_GLPosition;
|
||||
int32_t m_GLMatrix;
|
||||
int32_t m_GLColor;
|
||||
|
@ -1,842 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/resource/Program.h>
|
||||
#include <ewol/resource/Manager.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/ewol.h>
|
||||
|
||||
//#define LOCAL_DEBUG EWOL_VERBOSE
|
||||
#define LOCAL_DEBUG EWOL_DEBUG
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "resource::Program"
|
||||
|
||||
ewol::resource::Program::Program() :
|
||||
ewol::Resource(),
|
||||
m_exist(false),
|
||||
m_program(0),
|
||||
m_hasTexture(false),
|
||||
m_hasTexture1(false) {
|
||||
addObjectType("ewol::resource::Program");
|
||||
m_resourceLevel = 1;
|
||||
}
|
||||
|
||||
void ewol::resource::Program::init(const std::string& _filename) {
|
||||
ewol::Resource::init(_filename);
|
||||
EWOL_DEBUG("OGL : load PROGRAM '" << m_name << "'");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.exist()) {
|
||||
EWOL_INFO("File does not Exist : \"" << file << "\" == > automatic load of framment and shader with same names... ");
|
||||
std::string tmpFilename = m_name;
|
||||
// remove extention ...
|
||||
tmpFilename.erase(tmpFilename.size()-4, 4);
|
||||
std::shared_ptr<ewol::resource::Shader> tmpShader = ewol::resource::Shader::create(tmpFilename+"vert");
|
||||
if (nullptr == tmpShader) {
|
||||
EWOL_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
return;
|
||||
} else {
|
||||
EWOL_DEBUG("Add shader on program : "<< tmpFilename << "vert");
|
||||
m_shaderList.push_back(tmpShader);
|
||||
}
|
||||
tmpShader = ewol::resource::Shader::create(tmpFilename+"frag");
|
||||
if (nullptr == tmpShader) {
|
||||
EWOL_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
return;
|
||||
} else {
|
||||
EWOL_DEBUG("Add shader on program : "<< tmpFilename << "frag");
|
||||
m_shaderList.push_back(tmpShader);
|
||||
}
|
||||
} else {
|
||||
std::string fileExtention = file.fileGetExtention();
|
||||
if (fileExtention != "prog") {
|
||||
EWOL_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
|
||||
return;
|
||||
}
|
||||
if (false == file.fileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : \"" << file << "\"");
|
||||
return;
|
||||
}
|
||||
#define MAX_LINE_SIZE (2048)
|
||||
char tmpData[MAX_LINE_SIZE];
|
||||
while (file.fileGets(tmpData, MAX_LINE_SIZE) != nullptr) {
|
||||
int32_t len = strlen(tmpData);
|
||||
if( tmpData[len-1] == '\n'
|
||||
|| tmpData[len-1] == '\r') {
|
||||
tmpData[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
EWOL_DEBUG(" Read data : \"" << tmpData << "\"");
|
||||
if (len == 0) {
|
||||
continue;
|
||||
}
|
||||
if (tmpData[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
// get it with relative position :
|
||||
std::string tmpFilename = file.getRelativeFolder() + tmpData;
|
||||
std::shared_ptr<ewol::resource::Shader> tmpShader = ewol::resource::Shader::create(tmpFilename);
|
||||
if (nullptr == tmpShader) {
|
||||
EWOL_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
} else {
|
||||
EWOL_DEBUG("Add shader on program : "<< tmpFilename);
|
||||
m_shaderList.push_back(tmpShader);
|
||||
}
|
||||
|
||||
}
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
}
|
||||
updateContext();
|
||||
}
|
||||
|
||||
ewol::resource::Program::~Program() {
|
||||
m_shaderList.clear();
|
||||
removeContext();
|
||||
m_elementList.clear();
|
||||
m_hasTexture = false;
|
||||
m_hasTexture1 = false;
|
||||
}
|
||||
|
||||
std::ostream& ewol::resource::operator <<(std::ostream& _os, const ewol::resource::progAttributeElement& _obj) {
|
||||
_os << "{";
|
||||
_os << "[" << _obj.m_name << "] ";
|
||||
_os << _obj.m_elementId << " ";
|
||||
_os << _obj.m_isLinked;
|
||||
_os << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
std::ostream& ewol::resource::operator <<(std::ostream& _os, const std::vector<ewol::resource::progAttributeElement>& _obj){
|
||||
_os << "{";
|
||||
for (auto &it : _obj) {
|
||||
_os << it;
|
||||
}
|
||||
_os << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
void ewol::resource::Program::checkGlError(const char* _op, int32_t _localLine, int32_t _idElem) {
|
||||
#ifdef DEBUG
|
||||
bool isPresent = false;
|
||||
for (GLint error = glGetError(); error; error = glGetError()) {
|
||||
EWOL_ERROR("after " << _op << "() line=" << _localLine << " glError(" << error << ")");
|
||||
isPresent = true;
|
||||
}
|
||||
if (isPresent == true) {
|
||||
EWOL_ERROR(" in program name : " << m_name);
|
||||
EWOL_ERROR(" program OpenGL ID =" << m_program);
|
||||
EWOL_ERROR(" List IO :");
|
||||
int32_t id = 0;
|
||||
for (auto &it : m_elementList) {
|
||||
if (id == _idElem) {
|
||||
EWOL_ERROR(" * name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " attribute=" << it.m_isAttribute << " is linked=" << it.m_isLinked);
|
||||
} else {
|
||||
EWOL_ERROR(" name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " attribute=" << it.m_isAttribute << " is linked=" << it.m_isLinked);
|
||||
}
|
||||
id++;
|
||||
}
|
||||
EWOL_CRITICAL("Stop on openGL ERROR");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
|
||||
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
|
||||
|
||||
bool ewol::resource::Program::checkIdValidity(int32_t _idElem) {
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
return false;
|
||||
}
|
||||
return m_elementList[_idElem].m_isLinked;
|
||||
}
|
||||
|
||||
int32_t ewol::resource::Program::getAttribute(std::string _elementName) {
|
||||
// check if it exist previously :
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
if (m_elementList[iii].m_name == _elementName) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
progAttributeElement tmp;
|
||||
tmp.m_name = _elementName;
|
||||
tmp.m_isAttribute = true;
|
||||
tmp.m_elementId = glGetAttribLocation(m_program, tmp.m_name.c_str());
|
||||
tmp.m_isLinked = true;
|
||||
if (tmp.m_elementId<0) {
|
||||
EWOL_WARNING(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
|
||||
tmp.m_isLinked = false;
|
||||
checkGlError("glGetAttribLocation", __LINE__, tmp.m_elementId);
|
||||
} else {
|
||||
EWOL_INFO(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
|
||||
}
|
||||
m_elementList.push_back(tmp);
|
||||
return m_elementList.size()-1;
|
||||
}
|
||||
|
||||
int32_t ewol::resource::Program::getUniform(std::string _elementName) {
|
||||
// check if it exist previously :
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
if (m_elementList[iii].m_name == _elementName) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
progAttributeElement tmp;
|
||||
tmp.m_name = _elementName;
|
||||
tmp.m_isAttribute = false;
|
||||
tmp.m_elementId = glGetUniformLocation(m_program, tmp.m_name.c_str());
|
||||
tmp.m_isLinked = true;
|
||||
if (tmp.m_elementId<0) {
|
||||
EWOL_WARNING(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
|
||||
tmp.m_isLinked = false;
|
||||
checkGlError("glGetUniformLocation", __LINE__, tmp.m_elementId);
|
||||
} else {
|
||||
EWOL_INFO(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
|
||||
}
|
||||
m_elementList.push_back(tmp);
|
||||
return m_elementList.size()-1;
|
||||
}
|
||||
|
||||
void ewol::resource::Program::updateContext() {
|
||||
if (true == m_exist) {
|
||||
// Do nothing == > too dangerous ...
|
||||
} else {
|
||||
// create the Shader
|
||||
EWOL_INFO("Create the Program ... \"" << m_name << "\"");
|
||||
m_program = glCreateProgram();
|
||||
if (0 == m_program) {
|
||||
EWOL_ERROR("program creation return error ...");
|
||||
checkGlError("glCreateProgram", __LINE__);
|
||||
return;
|
||||
}
|
||||
EWOL_DEBUG("Create program with oglID=" << m_program);
|
||||
// first attach vertex shader, and after fragment shader
|
||||
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
|
||||
if (nullptr != m_shaderList[iii]) {
|
||||
if (m_shaderList[iii]->getShaderType() == GL_VERTEX_SHADER) {
|
||||
glAttachShader(m_program, m_shaderList[iii]->getGL_ID());
|
||||
checkGlError("glAttachShader", __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
|
||||
if (nullptr != m_shaderList[iii]) {
|
||||
if (m_shaderList[iii]->getShaderType() == GL_FRAGMENT_SHADER) {
|
||||
glAttachShader(m_program, m_shaderList[iii]->getGL_ID());
|
||||
checkGlError("glAttachShader", __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
glLinkProgram(m_program);
|
||||
checkGlError("glLinkProgram", __LINE__);
|
||||
GLint linkStatus = GL_FALSE;
|
||||
glGetProgramiv(m_program, GL_LINK_STATUS, &linkStatus);
|
||||
checkGlError("glGetProgramiv", __LINE__);
|
||||
if (linkStatus != GL_TRUE) {
|
||||
GLint bufLength = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
glGetProgramInfoLog(m_program, LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
|
||||
char tmpLog[256];
|
||||
int32_t idOut=0;
|
||||
EWOL_ERROR("Could not compile \"PROGRAM\": \"" << m_name << "\"");
|
||||
for (size_t iii=0; iii<LOG_OGL_INTERNAL_BUFFER_LEN ; iii++) {
|
||||
tmpLog[idOut] = l_bufferDisplayError[iii];
|
||||
if (tmpLog[idOut] == '\n' || tmpLog[idOut] == '\0' || idOut >= 256) {
|
||||
tmpLog[idOut] = '\0';
|
||||
EWOL_ERROR(" == > " << tmpLog);
|
||||
idOut=0;
|
||||
} else {
|
||||
idOut++;
|
||||
}
|
||||
if (l_bufferDisplayError[iii] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idOut != 0) {
|
||||
tmpLog[idOut] = '\0';
|
||||
EWOL_ERROR(" == > " << tmpLog);
|
||||
}
|
||||
glDeleteProgram(m_program);
|
||||
checkGlError("glDeleteProgram", __LINE__);
|
||||
m_program = 0;
|
||||
return;
|
||||
}
|
||||
m_exist = true;
|
||||
// now get the old attribute requested priviously ...
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
if (true == m_elementList[iii].m_isAttribute) {
|
||||
m_elementList[iii].m_elementId = glGetAttribLocation(m_program, m_elementList[iii].m_name.c_str());
|
||||
m_elementList[iii].m_isLinked = true;
|
||||
if (m_elementList[iii].m_elementId<0) {
|
||||
m_elementList[iii].m_isLinked = false;
|
||||
checkGlError("glGetAttribLocation", __LINE__);
|
||||
EWOL_WARNING("glGetAttribLocation(\"" << m_elementList[iii].m_name << "\") = " << m_elementList[iii].m_elementId);
|
||||
}
|
||||
} else {
|
||||
m_elementList[iii].m_elementId = glGetUniformLocation(m_program, m_elementList[iii].m_name.c_str());
|
||||
m_elementList[iii].m_isLinked = true;
|
||||
if (m_elementList[iii].m_elementId<0) {
|
||||
m_elementList[iii].m_isLinked = false;
|
||||
checkGlError("glGetUniformLocation", __LINE__);
|
||||
EWOL_WARNING("glGetUniformLocation(\"" << m_elementList[iii].m_name << "\") = " << m_elementList[iii].m_elementId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::Program::removeContext() {
|
||||
if (true == m_exist) {
|
||||
glDeleteProgram(m_program);
|
||||
m_program = 0;
|
||||
m_exist = false;
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
m_elementList[iii].m_elementId=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::Program::removeContextToLate() {
|
||||
m_exist = false;
|
||||
m_program = 0;
|
||||
}
|
||||
|
||||
void ewol::resource::Program::reload() {
|
||||
/* TODO : ...
|
||||
etk::file file(m_name, etk::FILE_TYPE_DATA);
|
||||
if (false == file.Exist()) {
|
||||
EWOL_ERROR("File does not Exist : \"" << file << "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t fileSize = file.size();
|
||||
if (0 == fileSize) {
|
||||
EWOL_ERROR("This file is empty : " << file);
|
||||
return;
|
||||
}
|
||||
if (false == file.fOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
// remove previous data ...
|
||||
if (nullptr != m_fileData) {
|
||||
delete[] m_fileData;
|
||||
m_fileData = 0;
|
||||
}
|
||||
// allocate data
|
||||
m_fileData = new char[fileSize+5];
|
||||
if (nullptr == m_fileData) {
|
||||
EWOL_ERROR("Error Memory allocation size=" << fileSize);
|
||||
return;
|
||||
}
|
||||
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
file.fRead(m_fileData, 1, fileSize);
|
||||
// close the file:
|
||||
file.fClose();
|
||||
*/
|
||||
// now change the OGL context ...
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (m_elementList[_idElem].m_isLinked == false) {
|
||||
return;
|
||||
}
|
||||
//EWOL_ERROR("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " element");
|
||||
glVertexAttribPointer(m_elementList[_idElem].m_elementId, // attribute ID of openGL
|
||||
_nbElement, // number of elements per vertex, here (r,g,b,a)
|
||||
GL_FLOAT, // the type of each element
|
||||
GL_FALSE, // take our values as-is
|
||||
_jumpBetweenSample, // no extra data between each position
|
||||
_pointer); // Pointer on the buffer
|
||||
checkGlError("glVertexAttribPointer", __LINE__, _idElem);
|
||||
glEnableVertexAttribArray(m_elementList[_idElem].m_elementId);
|
||||
checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
void ewol::resource::Program::sendAttributePointer(int32_t _idElem,
|
||||
const std::shared_ptr<ewol::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample,
|
||||
int32_t _offset) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
// check error of the VBO goog enought ...
|
||||
if (_vbo->getElementSize(_index) <= 0) {
|
||||
EWOL_ERROR("Can not bind a VBO Buffer with an element size of : " << _vbo->getElementSize(_index) << " named=" << _vbo->getName());
|
||||
return;
|
||||
}
|
||||
|
||||
EWOL_VERBOSE("[" << m_elementList[_idElem].m_name << "] send " << _vbo->getElementSize(_index) << " element on oglID=" << _vbo->getGL_ID(_index) << " VBOindex=" << _index);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo->getGL_ID(_index));
|
||||
checkGlError("glBindBuffer", __LINE__, _idElem);
|
||||
EWOL_VERBOSE(" id=" << m_elementList[_idElem].m_elementId);
|
||||
EWOL_VERBOSE(" eleme size=" << _vbo->getElementSize(_index));
|
||||
EWOL_VERBOSE(" jump sample=" << _jumpBetweenSample);
|
||||
EWOL_VERBOSE(" offset=" << _offset);
|
||||
glVertexAttribPointer(m_elementList[_idElem].m_elementId, // attribute ID of openGL
|
||||
_vbo->getElementSize(_index), // number of elements per vertex, here (r,g,b,a)
|
||||
GL_FLOAT, // the type of each element
|
||||
GL_FALSE, // take our values as-is
|
||||
_jumpBetweenSample, // no extra data between each position
|
||||
(GLvoid *)_offset); // Pointer on the buffer
|
||||
checkGlError("glVertexAttribPointer", __LINE__, _idElem);
|
||||
glEnableVertexAttribArray(m_elementList[_idElem].m_elementId);
|
||||
checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
//EWOL_ERROR("[" << m_elementList[_idElem].m_name << "] send 1 matrix");
|
||||
// note : Android des not supported the transposition of the matrix, then we will done it oursef:
|
||||
if (true == _transpose) {
|
||||
mat4 tmp = _matrix;
|
||||
tmp.transpose();
|
||||
glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, tmp.m_mat);
|
||||
} else {
|
||||
glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, _matrix.m_mat);
|
||||
}
|
||||
checkGlError("glUniformMatrix4fv", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::uniform1f(int32_t _idElem, float _value1) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform1f(m_elementList[_idElem].m_elementId, _value1);
|
||||
checkGlError("glUniform1f", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform2f(int32_t _idElem, float _value1, float _value2) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform2f(m_elementList[_idElem].m_elementId, _value1, _value2);
|
||||
checkGlError("glUniform2f", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform3f(int32_t _idElem, float _value1, float _value2, float _value3) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform3f(m_elementList[_idElem].m_elementId, _value1, _value2, _value3);
|
||||
checkGlError("glUniform3f", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform4f(int32_t _idElem, float _value1, float _value2, float _value3, float _value4) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform4f(m_elementList[_idElem].m_elementId, _value1, _value2, _value3, _value4);
|
||||
checkGlError("glUniform4f", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::uniform1i(int32_t _idElem, int32_t _value1) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform1i(m_elementList[_idElem].m_elementId, _value1);
|
||||
checkGlError("glUniform1i", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform2i(int32_t _idElem, int32_t _value1, int32_t _value2) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform2i(m_elementList[_idElem].m_elementId, _value1, _value2);
|
||||
checkGlError("glUniform2i", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform3i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform3i(m_elementList[_idElem].m_elementId, _value1, _value2, _value3);
|
||||
checkGlError("glUniform3i", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform4i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3, int32_t _value4) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
glUniform4i(m_elementList[_idElem].m_elementId, _value1, _value2, _value3, _value4);
|
||||
checkGlError("glUniform4i", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform1fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform1fv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform2fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform2fv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
EWOL_VERBOSE("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " vec3");
|
||||
glUniform3fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform3fv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
EWOL_VERBOSE("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " vec4");
|
||||
glUniform4fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform4fv", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ewol::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform1iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform1iv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform2iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform2iv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform3iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform3iv", __LINE__, _idElem);
|
||||
}
|
||||
void ewol::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
EWOL_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
if (0 == _nbElement) {
|
||||
EWOL_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (nullptr == _value) {
|
||||
EWOL_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform4iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform4iv", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//#define PROGRAM_DISPLAY_SPEED
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef PROGRAM_DISPLAY_SPEED
|
||||
int64_t g_startTime = 0;
|
||||
#endif
|
||||
|
||||
|
||||
void ewol::resource::Program::use() {
|
||||
#ifdef PROGRAM_DISPLAY_SPEED
|
||||
g_startTime = ewol::getTime();
|
||||
#endif
|
||||
// event if it was 0 == > set it to prevent other use of the previous shader display ...
|
||||
ewol::openGL::useProgram(m_program);
|
||||
checkGlError("glUseProgram", __LINE__);
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::Program::setTexture0(int32_t _idElem, GLint _textureOpenGlID) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
ewol::openGL::enable(GL_TEXTURE_2D);
|
||||
checkGlError("glEnable", __LINE__);
|
||||
#endif
|
||||
ewol::openGL::activeTexture(GL_TEXTURE0);
|
||||
checkGlError("glActiveTexture", __LINE__, _idElem);
|
||||
// set the textureID
|
||||
glBindTexture(GL_TEXTURE_2D, _textureOpenGlID);
|
||||
checkGlError("glBindTexture", __LINE__, _idElem);
|
||||
// set the texture on the uniform attribute
|
||||
glUniform1i(m_elementList[_idElem].m_elementId, /*GL_TEXTURE*/0);
|
||||
checkGlError("glUniform1i", __LINE__, _idElem);
|
||||
m_hasTexture = true;
|
||||
}
|
||||
|
||||
void ewol::resource::Program::setTexture1(int32_t _idElem, GLint _textureOpenGlID) {
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
ewol::openGL::enable(GL_TEXTURE_2D);
|
||||
checkGlError("glEnable", __LINE__);
|
||||
#endif
|
||||
ewol::openGL::activeTexture(GL_TEXTURE1);
|
||||
checkGlError("glActiveTexture", __LINE__, _idElem);
|
||||
// set the textureID
|
||||
glBindTexture(GL_TEXTURE_2D, _textureOpenGlID);
|
||||
checkGlError("glBindTexture", __LINE__, _idElem);
|
||||
// set the texture on the uniform attribute
|
||||
glUniform1i(m_elementList[_idElem].m_elementId, /*GL_TEXTURE*/1);
|
||||
checkGlError("glUniform1i", __LINE__, _idElem);
|
||||
m_hasTexture1 = true;
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::Program::unUse() {
|
||||
//EWOL_WARNING("Will use program : " << m_program);
|
||||
if (0 == m_program) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
if (true == m_hasTexture) {
|
||||
ewol::openGL::disable(GL_TEXTURE_2D);
|
||||
//checkGlError("glDisable", __LINE__);
|
||||
m_hasTexture = false;
|
||||
}
|
||||
#endif
|
||||
// no need to disable program == > this only generate perturbation on speed ...
|
||||
ewol::openGL::useProgram(-1);
|
||||
#ifdef PROGRAM_DISPLAY_SPEED
|
||||
float localTime = (float)(ewol::getTime() - g_startTime) / 1000.0f;
|
||||
if (localTime>1) {
|
||||
EWOL_ERROR(" prog : " << localTime << "ms resource=\"" << m_name << "\"");
|
||||
} else {
|
||||
EWOL_DEBUG(" prog : " << localTime << "ms resource=\"" << m_name << "\"");
|
||||
}
|
||||
#endif
|
||||
checkGlError("glUseProgram", __LINE__);
|
||||
}
|
||||
|
@ -1,313 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL__PROGRAM_H__
|
||||
#define __OPEN_GL__PROGRAM_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector4D.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <ewol/resource/Resource.h>
|
||||
#include <ewol/resource/Shader.h>
|
||||
#include <ewol/resource/VirtualBufferObject.h>
|
||||
#include <etk/Color.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace resource {
|
||||
/**
|
||||
* @brief In a openGL program we need some data to communicate with them, we register all the name requested by the user in this structure:
|
||||
* @note Register all requested element permit to abstract the fact that some element does not exist and remove control of existance from upper code.
|
||||
* This is important to note when the Program is reloaded the elements availlable can change.
|
||||
* @not-in-doc
|
||||
*/
|
||||
class progAttributeElement {
|
||||
public :
|
||||
std::string m_name; //!< Name of the element
|
||||
GLint m_elementId; //!< openGl Id if this element == > can not exist ==> @ref m_isLinked
|
||||
bool m_isAttribute; //!< true if it was an attribute element, otherwite it was an uniform
|
||||
bool m_isLinked; //!< if this element does not exist this is false
|
||||
};
|
||||
//! @not-in-doc
|
||||
std::ostream& operator <<(std::ostream& _os, const ewol::resource::progAttributeElement& _obj);
|
||||
//! @not-in-doc
|
||||
std::ostream& operator <<(std::ostream& _os, const std::vector<ewol::resource::progAttributeElement>& _obj);
|
||||
/**
|
||||
* @brief Program is a compilation of some fragment Shader and vertex Shader. This construct automaticly this assiciation
|
||||
* The input file must have the form : "myFile.prog"
|
||||
* The data is simple :
|
||||
* <pre>
|
||||
* # Comment line ... paid attention at the space at the end of lines, they are considered like a part of the file ...
|
||||
* # The folder is automaticly get from the program file basic folder
|
||||
* filename1.vert
|
||||
* filename2.frag
|
||||
* filename3.vert
|
||||
* filename4.frag
|
||||
* </pre>
|
||||
*/
|
||||
class Program : public ewol::Resource {
|
||||
private :
|
||||
bool m_exist; //!< the file existed
|
||||
GLuint m_program; //!< openGL id of the current program
|
||||
std::vector<std::shared_ptr<ewol::resource::Shader>> m_shaderList; //!< List of all the shader loaded
|
||||
std::vector<ewol::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
|
||||
bool m_hasTexture; //!< A texture has been set to the current shader
|
||||
bool m_hasTexture1; //!< A texture has been set to the current shader
|
||||
protected:
|
||||
/**
|
||||
* @brief Contructor of an opengl Program.
|
||||
* @param[in] filename Standard file name format. see @ref etk::FSNode
|
||||
*/
|
||||
Program();
|
||||
void init(const std::string& _filename);
|
||||
public:
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Program);
|
||||
/**
|
||||
* @brief Destructor, remove the current Program.
|
||||
*/
|
||||
virtual ~Program();
|
||||
public:
|
||||
/**
|
||||
* @brief Check If an Id is valid in the shader or not (sometime the shader have not some attribute, then we need to display some error)
|
||||
* @return _idElem Id of the Attribute that might be sended.
|
||||
* @return true The id is valid, false otherwise
|
||||
*/
|
||||
bool checkIdValidity(int32_t _idElem);
|
||||
/**
|
||||
* @brief User request an attribute on this program.
|
||||
* @note The attribute is send to the fragment shaders
|
||||
* @param[in] _elementName Name of the requested attribute.
|
||||
* @return An abstract ID of the current attribute (this value is all time availlable, even if the program will be reloaded)
|
||||
*/
|
||||
int32_t getAttribute(std::string _elementName);
|
||||
/**
|
||||
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program).
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Specifies the number of elements that are to be modified.
|
||||
* @param[in] _pointer Pointer on the data that might be sended.
|
||||
* @param[in] _jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
|
||||
*/
|
||||
void sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample=0);
|
||||
void sendAttributePointer(int32_t _idElem,
|
||||
const std::shared_ptr<ewol::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample=0,
|
||||
int32_t _offset=0);
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec2>& _data) {
|
||||
sendAttribute(_idElem, 2/*u,v / x,y*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec3>& _data) {
|
||||
sendAttribute(_idElem, 3/*x,y,z,unused*/, &_data[0], 4*sizeof(btScalar));
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<etk::Color<float>>& _data) {
|
||||
sendAttribute(_idElem, 4/*r,g,b,a*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<float>& _data) {
|
||||
sendAttribute(_idElem, 1, &_data[0]);
|
||||
}
|
||||
/**
|
||||
* @brief User request an Uniform on this program.
|
||||
* @note uniform value is availlable for all the fragment shader in the program (only one value for all)
|
||||
* @param[in] _elementName Name of the requested uniform.
|
||||
* @return An abstract ID of the current uniform (this value is all time availlable, even if the program will be reloaded)
|
||||
*/
|
||||
int32_t getUniform(std::string _elementName);
|
||||
/**
|
||||
* @brief Send a uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _matrix Matrix that might be sended.
|
||||
* @param[in] _transpose Transpose the matrix (needed all the taime in the normal openGl access (only not done in the openGL-ES2 due to the fact we must done it ourself)
|
||||
*/
|
||||
void uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose=true);
|
||||
|
||||
inline void uniform(int32_t _idElem, const etk::Color<float>& _value) {
|
||||
uniform4f(_idElem, _value.r(), _value.g(), _value.b(), _value.a());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send 1 float uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
*/
|
||||
void uniform1f(int32_t _idElem, float _value1);
|
||||
/**
|
||||
* @brief Send 2 float uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
*/
|
||||
void uniform2f(int32_t _idElem, float _value1, float _value2);
|
||||
/**
|
||||
* @brief Send 3 float uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
* @param[in] _value3 Value to send at the Uniform
|
||||
*/
|
||||
void uniform3f(int32_t _idElem, float _value1, float _value2, float _value3);
|
||||
/**
|
||||
* @brief Send 4 float uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
* @param[in] _value3 Value to send at the Uniform
|
||||
* @param[in] _value4 Value to send at the Uniform
|
||||
*/
|
||||
void uniform4f(int32_t _idElem, float _value1, float _value2, float _value3, float _value4);
|
||||
|
||||
/**
|
||||
* @brief Send 1 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
*/
|
||||
void uniform1i(int32_t _idElem, int32_t _value1);
|
||||
/**
|
||||
* @brief Send 2 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
*/
|
||||
void uniform2i(int32_t _idElem, int32_t _value1, int32_t _value2);
|
||||
/**
|
||||
* @brief Send 3 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
* @param[in] _value3 Value to send at the Uniform
|
||||
*/
|
||||
void uniform3i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3);
|
||||
/**
|
||||
* @brief Send 4 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _value1 Value to send at the Uniform
|
||||
* @param[in] _value2 Value to send at the Uniform
|
||||
* @param[in] _value3 Value to send at the Uniform
|
||||
* @param[in] _value4 Value to send at the Uniform
|
||||
*/
|
||||
void uniform4i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3, int32_t _value4);
|
||||
|
||||
/**
|
||||
* @brief Send "vec1" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform1fv(int32_t _idElem, int32_t _nbElement, const float *_value);
|
||||
/**
|
||||
* @brief Send "vec2" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform2fv(int32_t _idElem, int32_t _nbElement, const float *_value);
|
||||
/**
|
||||
* @brief Send "vec3" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform3fv(int32_t _idElem, int32_t _nbElement, const float *_value);
|
||||
/**
|
||||
* @brief Send "vec4" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform4fv(int32_t _idElem, int32_t _nbElement, const float *_value);
|
||||
|
||||
/**
|
||||
* @brief Send "ivec1" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform1iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value);
|
||||
/**
|
||||
* @brief Send "ivec2" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform2iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value);
|
||||
/**
|
||||
* @brief Send "ivec3" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform3iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value);
|
||||
/**
|
||||
* @brief Send "ivec4" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _nbElement Number of element sended
|
||||
* @param[in] _value Pointer on the data
|
||||
*/
|
||||
void uniform4iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value);
|
||||
|
||||
inline void uniform2(int32_t _idElem, const vec2& _value) {
|
||||
uniform2fv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
inline void uniform3(int32_t _idElem, const vec3& _value) {
|
||||
uniform3fv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
inline void uniform4(int32_t _idElem, const vec4& _value) {
|
||||
uniform4fv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
inline void uniform2(int32_t _idElem, const ivec2& _value) {
|
||||
uniform2iv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
inline void uniform3(int32_t _idElem, const ivec3& _value) {
|
||||
uniform3iv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
inline void uniform4(int32_t _idElem, const ivec4& _value) {
|
||||
uniform4iv(_idElem, 1, &_value.m_floats[0]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Request the processing of this program
|
||||
*/
|
||||
void use();
|
||||
/**
|
||||
* @brief set the testure Id on the specify uniform element.
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
* @param[in] _textureOpenGlID Real openGL texture ID
|
||||
*/
|
||||
void setTexture0(int32_t _idElem, GLint _textureOpenGlID);
|
||||
void setTexture1(int32_t _idElem, GLint _textureOpenGlID);
|
||||
/**
|
||||
* @brief Stop the processing of this program
|
||||
*/
|
||||
void unUse();
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
void updateContext();
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
void removeContext();
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
void removeContextToLate();
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
void reload();
|
||||
private:
|
||||
void checkGlError(const char* _op, int32_t _localLine, int32_t _idElem=-2);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,158 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/resource/Shader.h>
|
||||
#include <ewol/resource/Manager.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "resource::Shader"
|
||||
|
||||
ewol::resource::Shader::Shader() :
|
||||
ewol::Resource(),
|
||||
m_exist(false),
|
||||
m_fileData(nullptr),
|
||||
m_shader(0),
|
||||
m_type(0) {
|
||||
addObjectType("ewol::Shader");
|
||||
m_resourceLevel = 0;
|
||||
}
|
||||
|
||||
void ewol::resource::Shader::init(const std::string& _filename) {
|
||||
ewol::Resource::init(_filename);
|
||||
EWOL_DEBUG("OGL : load SHADER \"" << _filename << "\"");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
if (etk::end_with(m_name, ".frag") == true) {
|
||||
m_type = GL_FRAGMENT_SHADER;
|
||||
} else if (etk::end_with(m_name, ".vert") == true) {
|
||||
m_type = GL_VERTEX_SHADER;
|
||||
} else {
|
||||
EWOL_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\"");
|
||||
return;
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
ewol::resource::Shader::~Shader() {
|
||||
if (nullptr != m_fileData) {
|
||||
delete [] m_fileData;
|
||||
m_fileData = nullptr;
|
||||
}
|
||||
if (0!=m_shader) {
|
||||
glDeleteShader(m_shader);
|
||||
m_shader = 0;
|
||||
}
|
||||
m_exist = false;
|
||||
}
|
||||
|
||||
static void checkGlError(const char* _op) {
|
||||
for (GLint error = glGetError(); error; error = glGetError()) {
|
||||
EWOL_ERROR("after " << _op << "() glError (" << error << ")");
|
||||
}
|
||||
}
|
||||
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
|
||||
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
|
||||
|
||||
void ewol::resource::Shader::updateContext() {
|
||||
if (true == m_exist) {
|
||||
// Do nothing == > too dangerous ...
|
||||
} else {
|
||||
// create the Shader
|
||||
if (nullptr == m_fileData) {
|
||||
m_shader = 0;
|
||||
return;
|
||||
}
|
||||
EWOL_INFO("Create Shader : '" << m_name << "'");
|
||||
m_shader = glCreateShader(m_type);
|
||||
if (!m_shader) {
|
||||
EWOL_ERROR("glCreateShader return error ...");
|
||||
checkGlError("glCreateShader");
|
||||
EWOL_CRITICAL(" can not load shader");
|
||||
return;
|
||||
} else {
|
||||
EWOL_INFO("Compile shader with GLID=" << m_shader);
|
||||
glShaderSource(m_shader, 1, (const char**)&m_fileData, nullptr);
|
||||
glCompileShader(m_shader);
|
||||
GLint compiled = 0;
|
||||
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled) {
|
||||
GLint infoLen = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
|
||||
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
|
||||
if (m_type == GL_VERTEX_SHADER){
|
||||
tmpShaderType = "GL_VERTEX_SHADER";
|
||||
}
|
||||
EWOL_ERROR("Could not compile \"" << tmpShaderType << "\" name='" << m_name << "'");
|
||||
EWOL_ERROR("Error " << l_bufferDisplayError);
|
||||
std::vector<std::string> lines = etk::split(m_fileData, '\n');
|
||||
for (size_t iii=0 ; iii<lines.size() ; iii++) {
|
||||
EWOL_ERROR("file " << (iii+1) << "|" << lines[iii]);
|
||||
}
|
||||
EWOL_CRITICAL(" can not load shader");
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_exist = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::Shader::removeContext() {
|
||||
if (true == m_exist) {
|
||||
glDeleteShader(m_shader);
|
||||
m_exist = false;
|
||||
m_shader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::Shader::removeContextToLate() {
|
||||
m_exist = false;
|
||||
m_shader = 0;
|
||||
}
|
||||
|
||||
void ewol::resource::Shader::reload() {
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.exist()) {
|
||||
EWOL_CRITICAL("File does not Exist : '" << file << "' : '" << file.getFileSystemName() << "'");
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t fileSize = file.fileSize();
|
||||
if (0 == fileSize) {
|
||||
EWOL_CRITICAL("This file is empty : " << file);
|
||||
return;
|
||||
}
|
||||
if (false == file.fileOpenRead()) {
|
||||
EWOL_CRITICAL("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
// remove previous data ...
|
||||
if (nullptr != m_fileData) {
|
||||
delete[] m_fileData;
|
||||
m_fileData = 0;
|
||||
}
|
||||
// allocate data
|
||||
m_fileData = new char[fileSize+5];
|
||||
if (nullptr == m_fileData) {
|
||||
EWOL_CRITICAL("Error Memory allocation size=" << fileSize);
|
||||
return;
|
||||
}
|
||||
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
file.fileRead(m_fileData, 1, fileSize);
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
|
||||
// now change the OGL context ...
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL__SHADER_H__
|
||||
#define __OPEN_GL__SHADER_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <ewol/resource/Resource.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace resource {
|
||||
/**
|
||||
* @brief Shader is a specific resources for opengl, used only in @ref Program. This are components of the renderer pipe-line
|
||||
*/
|
||||
class Shader : public ewol::Resource {
|
||||
private :
|
||||
bool m_exist; //!< The shader file existed and has been loaded
|
||||
char* m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
|
||||
GLuint m_shader; //!< opengl id of this element
|
||||
GLenum m_type; //!< Type of the current shader(vertex/fragment)
|
||||
protected:
|
||||
/**
|
||||
* @brief Contructor of an opengl Shader
|
||||
* @param[in] filename Standard file name format. see @ref etk::FSNode
|
||||
*/
|
||||
Shader();
|
||||
public:
|
||||
void init(const std::string& _filename);
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Shader);
|
||||
/**
|
||||
* @brief Destructor, remove the current Shader
|
||||
*/
|
||||
virtual ~Shader();
|
||||
public:
|
||||
/**
|
||||
* @brief get the opengl reference id of this shader.
|
||||
* @return The opengl id.
|
||||
*/
|
||||
GLuint getGL_ID() {
|
||||
return m_shader;
|
||||
};
|
||||
/**
|
||||
* @brief get the opengl type of this shader.
|
||||
* @return The type of this loaded shader.
|
||||
*/
|
||||
GLenum getShaderType() {
|
||||
return m_type;
|
||||
};
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
void updateContext();
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
void removeContext();
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
void removeContextToLate();
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
void reload();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,107 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <ewol/resource/Manager.h>
|
||||
#include <ewol/resource/Texture.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "resource::Texture"
|
||||
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
* @param[in] value Value that we want the next power of 2
|
||||
* @return result value
|
||||
*/
|
||||
static int32_t nextP2(int32_t _value) {
|
||||
int32_t val=1;
|
||||
for (int32_t iii=1; iii<31; iii++) {
|
||||
if (_value <= val) {
|
||||
return val;
|
||||
}
|
||||
val *=2;
|
||||
}
|
||||
EWOL_CRITICAL("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::Texture::init(const std::string& _filename) {
|
||||
ewol::Resource::init(_filename);
|
||||
}
|
||||
void ewol::resource::Texture::init() {
|
||||
ewol::Resource::init();
|
||||
}
|
||||
|
||||
ewol::resource::Texture::Texture() {
|
||||
addObjectType("ewol::compositing::Texture");
|
||||
m_loaded = false;
|
||||
m_texId = 0;
|
||||
m_endPointSize.setValue(1.0,1.0);
|
||||
}
|
||||
|
||||
ewol::resource::Texture::~Texture() {
|
||||
removeContext();
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::updateContext() {
|
||||
if (false == m_loaded) {
|
||||
// Request a new texture at openGl :
|
||||
glGenTextures(1, &m_texId);
|
||||
}
|
||||
// in all case we set the texture properties :
|
||||
// TODO : check error ???
|
||||
glBindTexture(GL_TEXTURE_2D, m_texId);
|
||||
// TODO : Check error ???
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
//--- mode nearest
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
//--- Mode linear
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
EWOL_INFO("TEXTURE: add [" << getId() << "]=" << m_data.getSize() << " OGl_Id=" <<m_texId);
|
||||
glTexImage2D(GL_TEXTURE_2D, // Target
|
||||
0, // Level
|
||||
GL_RGBA, // Format internal
|
||||
m_data.getWidth(),
|
||||
m_data.getHeight(),
|
||||
0, // Border
|
||||
GL_RGBA, // format
|
||||
GL_UNSIGNED_BYTE, // type
|
||||
m_data.getTextureDataPointer() );
|
||||
// now the data is loaded
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::removeContext() {
|
||||
if (true == m_loaded) {
|
||||
// Request remove texture ...
|
||||
EWOL_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId);
|
||||
glDeleteTextures(1, &m_texId);
|
||||
m_loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::removeContextToLate() {
|
||||
m_loaded = false;
|
||||
m_texId=0;
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(std::dynamic_pointer_cast<ewol::Resource>(shared_from_this()));
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::setImageSize(ivec2 _newSize) {
|
||||
_newSize.setValue( nextP2(_newSize.x()), nextP2(_newSize.y()) );
|
||||
m_data.resize(_newSize);
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_TEXTURE_H__
|
||||
#define __EWOL_TEXTURE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <egami/Image.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <ewol/resource/Resource.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace resource {
|
||||
class Texture : public ewol::Resource {
|
||||
protected:
|
||||
// openGl Context propoerties :
|
||||
egami::Image m_data;
|
||||
// openGl textureID :
|
||||
GLuint m_texId;
|
||||
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 -> 1.0
|
||||
vec2 m_endPointSize;
|
||||
// internal state of the openGl system :
|
||||
bool m_loaded;
|
||||
// Ewol internal API:
|
||||
public:
|
||||
void updateContext();
|
||||
void removeContext();
|
||||
void removeContextToLate();
|
||||
// middleware interface:
|
||||
public:
|
||||
GLuint getId() const {
|
||||
return m_texId;
|
||||
};
|
||||
const vec2& getUsableSize() const {
|
||||
return m_endPointSize;
|
||||
};
|
||||
const ivec2& getOpenGlSize() const {
|
||||
return m_data.getSize();
|
||||
};
|
||||
// Public API:
|
||||
protected:
|
||||
void init(const std::string& _filename);
|
||||
void init();
|
||||
Texture();
|
||||
public:
|
||||
DECLARE_RESOURCE_FACTORY(Texture);
|
||||
virtual ~Texture();
|
||||
public:
|
||||
// you must set the size here, because it will be set in multiple of pow(2)
|
||||
void setImageSize(ivec2 newSize);
|
||||
// get the reference on this image to draw nomething on it ...
|
||||
inline egami::Image& get() {
|
||||
return m_data;
|
||||
};
|
||||
// flush the data to send it at the openGl system
|
||||
void flush();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,183 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/resource/Manager.h>
|
||||
#include <ewol/resource/VirtualBufferObject.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "resource::VirtualBufferObject"
|
||||
|
||||
void ewol::resource::VirtualBufferObject::init(int32_t _number) {
|
||||
ewol::Resource::init();
|
||||
m_vbo.resize(_number, 0);
|
||||
m_vboUsed.resize(_number, false);
|
||||
m_buffer.resize(_number);
|
||||
m_vboSizeDataOffset.resize(_number, -1);
|
||||
EWOL_DEBUG("OGL : load VBO count=\"" << _number << "\"");
|
||||
}
|
||||
|
||||
ewol::resource::VirtualBufferObject::VirtualBufferObject() :
|
||||
m_exist(false) {
|
||||
addObjectType("ewol::VirtualBufferObject");
|
||||
m_resourceLevel = 3;
|
||||
}
|
||||
|
||||
ewol::resource::VirtualBufferObject::~VirtualBufferObject() {
|
||||
removeContext();
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::retreiveData() {
|
||||
EWOL_ERROR("TODO ... ");
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::updateContext() {
|
||||
if (false == m_exist) {
|
||||
// Allocate and assign a Vertex Array Object to our handle
|
||||
ewol::openGL::genBuffers(m_vbo);
|
||||
}
|
||||
m_exist = true;
|
||||
for (size_t iii=0; iii<m_vbo.size(); iii++) {
|
||||
EWOL_INFO("VBO : add [" << getId() << "]=" << m_buffer[iii].size() << "*sizeof(float) OGl_Id=" << m_vbo[iii]);
|
||||
if (true == m_vboUsed[iii]) {
|
||||
// select the buffer to set data inside it ...
|
||||
if (m_buffer[iii].size()>0) {
|
||||
ewol::openGL::bindBuffer(m_vbo[iii]);
|
||||
ewol::openGL::bufferData(sizeof(float)*m_buffer[iii].size(), &((m_buffer[iii])[0]), GL_STATIC_DRAW);
|
||||
}
|
||||
}
|
||||
}
|
||||
// un-bind it to permet to have no erreor in the next display ...
|
||||
ewol::openGL::unbindBuffer();
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::removeContext() {
|
||||
if (true == m_exist) {
|
||||
ewol::openGL::deleteBuffers(m_vbo);
|
||||
m_exist = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::removeContextToLate() {
|
||||
m_exist = false;
|
||||
for (size_t iii=0; iii<m_vbo.size(); iii++) {
|
||||
m_vbo[iii] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::reload() {
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(std::dynamic_pointer_cast<ewol::Resource>(shared_from_this()));
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 3;
|
||||
} else if (m_vboSizeDataOffset[_id] != 3) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.x());
|
||||
m_buffer[_id].push_back(_data.y());
|
||||
m_buffer[_id].push_back(_data.z());
|
||||
}
|
||||
|
||||
vec3 ewol::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _elementID) {
|
||||
if ((size_t)_elementID*3 > m_buffer[_id].size()) {
|
||||
return vec3(0,0,0);
|
||||
}
|
||||
return vec3(m_buffer[_id][3*_elementID],
|
||||
m_buffer[_id][3*_elementID+1],
|
||||
m_buffer[_id][3*_elementID+2]);
|
||||
}
|
||||
|
||||
int32_t ewol::resource::VirtualBufferObject::bufferSize(int32_t _id) {
|
||||
return m_buffer[_id].size()/m_vboSizeDataOffset[_id];
|
||||
}
|
||||
int32_t ewol::resource::VirtualBufferObject::getElementSize(int32_t _id) {
|
||||
return m_vboSizeDataOffset[_id];
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec2& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 2;
|
||||
} else if (m_vboSizeDataOffset[_id] != 2) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.x());
|
||||
m_buffer[_id].push_back(_data.y());
|
||||
}
|
||||
|
||||
vec2 ewol::resource::VirtualBufferObject::getOnBufferVec2(int32_t _id, int32_t _elementID) {
|
||||
if ((size_t)_elementID*2 > m_buffer[_id].size()) {
|
||||
return vec2(0,0);
|
||||
}
|
||||
return vec2(m_buffer[_id][2*_elementID],
|
||||
m_buffer[_id][2*_elementID+1]);
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,4>& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 4;
|
||||
} else if (m_vboSizeDataOffset[_id] != 4) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
m_buffer[_id].push_back(_data.b());
|
||||
m_buffer[_id].push_back(_data.a());
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,3>& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 3;
|
||||
} else if (m_vboSizeDataOffset[_id] != 3) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
m_buffer[_id].push_back(_data.b());
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,2>& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 2;
|
||||
} else if (m_vboSizeDataOffset[_id] != 2) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
}
|
||||
|
||||
void ewol::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,1>& _data) {
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 1;
|
||||
} else if (m_vboSizeDataOffset[_id] != 1) {
|
||||
EWOL_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
}
|
||||
|
@ -1,128 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __OPEN_GL__VIRTUAL_BUFFER_OBJECT_H__
|
||||
#define __OPEN_GL__VIRTUAL_BUFFER_OBJECT_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/resource/Resource.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <etk/Color.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace resource {
|
||||
/**
|
||||
* @brief VirtualBufferObject is a specific resources for opengl, this load the data directly in the graphic card ad keep these inside
|
||||
*/
|
||||
class VirtualBufferObject : public ewol::Resource {
|
||||
private :
|
||||
bool m_exist; //!< This data is availlable in the Graphic card
|
||||
std::vector<GLuint> m_vbo; //!< openGl ID of this VBO
|
||||
std::vector<bool> m_vboUsed; //!< true if the VBO is allocated or used ...
|
||||
std::vector<std::vector<float>> m_buffer; //!< data that is availlable in the VBO system ...
|
||||
std::vector<int8_t> m_vboSizeDataOffset; //!< Internal size of the VBO (dynamicly set)
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor of this VBO.
|
||||
* @param[in] accesMode Acces mode : ???
|
||||
*/
|
||||
VirtualBufferObject();
|
||||
void init(int32_t _number);
|
||||
public:
|
||||
DECLARE_RESOURCE_FACTORY(VirtualBufferObject);
|
||||
/**
|
||||
* @brief Destructor of this VBO.
|
||||
*/
|
||||
virtual ~VirtualBufferObject();
|
||||
public:
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
*/
|
||||
GLuint getGL_ID(int32_t _id) {
|
||||
return m_vbo[_id];
|
||||
};
|
||||
/**
|
||||
* @brief get a reference on hte buffer data for this VBO.
|
||||
* @param[in] id Id of the buffer requested
|
||||
* @return A reference on the data.
|
||||
*/
|
||||
std::vector<float>& getRefBuffer(int32_t _id) {
|
||||
m_vboUsed[_id] = true;
|
||||
return m_buffer[_id];
|
||||
};
|
||||
/**
|
||||
* @brief Get the buffer Number of element.
|
||||
* @param[in] _id VBO Element
|
||||
* @return Number of Float in the buffer.
|
||||
*/
|
||||
int32_t bufferSize(int32_t _id);
|
||||
/**
|
||||
* @brief Get the offset between element.
|
||||
* @param[in] _id VBO Element
|
||||
* @return Number of Float to jump between target.
|
||||
*/
|
||||
int32_t getElementSize(int32_t _id);
|
||||
/**
|
||||
* @brief push data on a buffer with a custum type :
|
||||
* @param[in] _id Id of the buffer requested.
|
||||
* @param[in] _data Direct data that might be set.
|
||||
*/
|
||||
void pushOnBuffer(int32_t _id, const vec3& _data);
|
||||
vec3 getOnBufferVec3(int32_t _id, int32_t _elementID);
|
||||
/**
|
||||
* @brief push data on a buffer with a custum type :
|
||||
* @param[in] _id Id of the buffer requested.
|
||||
* @param[in] _data Direct data that might be set.
|
||||
*/
|
||||
void pushOnBuffer(int32_t _id, const vec2& _data);
|
||||
vec2 getOnBufferVec2(int32_t _id, int32_t _elementID);
|
||||
/**
|
||||
* @brief push data on a buffer with a custum type :
|
||||
* @param[in] _id Id of the buffer requested.
|
||||
* @param[in] _data Direct data that might be set (Color).
|
||||
*/
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,4>& _data);
|
||||
//! @previous
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,3>& _data);
|
||||
//! @previous
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,2>& _data);
|
||||
//! @previous
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,1>& _data);
|
||||
/**
|
||||
* @brief get the data from the graphic card.
|
||||
*/
|
||||
void retreiveData();
|
||||
/**
|
||||
* @brief Send the data to the graphic card.
|
||||
*/
|
||||
void flush();
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
void updateContext();
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
void removeContext();
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
void removeContextToLate();
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
void reload();
|
||||
};
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
@ -255,9 +255,9 @@ void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
(int32_t)( 1));
|
||||
mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate;
|
||||
|
||||
ewol::openGL::push();
|
||||
gale::openGL::push();
|
||||
// set internal matrix system :
|
||||
ewol::openGL::setMatrix(tmpMat);
|
||||
gale::openGL::setMatrix(tmpMat);
|
||||
//int64_t ___startTime = ewol::getTime();
|
||||
onDraw();
|
||||
|
||||
@ -284,7 +284,7 @@ void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
mat4 tmpProjection = etk::matOrtho(-tmpclipX/2, tmpclipX/2, -m_size.y()/2, m_size.y()/2, -1, 1);
|
||||
mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate;
|
||||
// set internal matrix system :
|
||||
ewol::openGL::setMatrix(tmpMat);
|
||||
gale::openGL::setMatrix(tmpMat);
|
||||
//int64_t ___startTime = ewol::getTime();
|
||||
onDraw();
|
||||
//float ___localTime = (float)(ewol::getTime() - ___startTime) / 1000.0f;
|
||||
@ -300,14 +300,14 @@ void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
mat4 tmpProjection = etk::matOrtho(-m_size.x()/2, m_size.x()/2, -m_size.y()/2, m_size.y()/2, -1, 1);
|
||||
mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate;
|
||||
// set internal matrix system :
|
||||
ewol::openGL::setMatrix(tmpMat);
|
||||
gale::openGL::setMatrix(tmpMat);
|
||||
//int64_t ___startTime = ewol::getTime();
|
||||
onDraw();
|
||||
//float ___localTime = (float)(ewol::getTime() - ___startTime) / 1000.0f;
|
||||
//EWOL_DEBUG(" Widget2 : " << ___localTime << "ms ");
|
||||
}
|
||||
#endif
|
||||
ewol::openGL::pop();
|
||||
gale::openGL::pop();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ void ewol::widget::WidgetScrolled::onDraw() {
|
||||
}
|
||||
|
||||
void ewol::widget::WidgetScrolled::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
ewol::openGL::push();
|
||||
gale::openGL::push();
|
||||
if (m_scroollingMode == scroolModeCenter) {
|
||||
// here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left
|
||||
glViewport( m_origin.x(),
|
||||
@ -420,7 +420,7 @@ void ewol::widget::WidgetScrolled::systemDraw(const ewol::DrawProperty& _display
|
||||
mat4 tmpTranslate = etk::matTranslate(vec3(-m_maxSize.x()/2, -m_maxSize.y()/2, -1.0) );
|
||||
mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate;
|
||||
// set internal matrix system :
|
||||
ewol::openGL::setMatrix(tmpMat);
|
||||
gale::openGL::setMatrix(tmpMat);
|
||||
// Call the widget drawing methode
|
||||
onDraw();
|
||||
} if (m_scroollingMode == scroolModeGame) {
|
||||
@ -434,13 +434,13 @@ void ewol::widget::WidgetScrolled::systemDraw(const ewol::DrawProperty& _display
|
||||
mat4 tmpTranslate = etk::matTranslate(vec3( -m_maxSize.x()/2, -m_maxSize.y()/2, -1.0) );
|
||||
mat4 tmpMat = tmpProjection * tmpTranslate;
|
||||
// set internal matrix system :
|
||||
ewol::openGL::setMatrix(tmpMat);
|
||||
gale::openGL::setMatrix(tmpMat);
|
||||
// Call the widget drawing methode
|
||||
onDraw();
|
||||
} else {
|
||||
ewol::Widget::systemDraw(_displayProp);
|
||||
}
|
||||
ewol::openGL::pop();
|
||||
gale::openGL::pop();
|
||||
}
|
||||
|
||||
void ewol::widget::WidgetScrolled::setScrollingPositionDynamic(vec2 _borderWidth, const vec2& _currentPosition, bool _center) {
|
||||
|
@ -76,30 +76,30 @@ void ewol::widget::Windows::sysDraw() {
|
||||
// set the size of the open GL system
|
||||
glViewport(0,0,m_size.x(),m_size.y());
|
||||
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DITHER);
|
||||
//ewol::openGL::disable(ewol::openGL::FLAG_BLEND);
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_STENCIL_TEST);
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_ALPHA_TEST);
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_FOG);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DITHER);
|
||||
//gale::openGL::disable(gale::openGL::FLAG_BLEND);
|
||||
gale::openGL::disable(gale::openGL::FLAG_STENCIL_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_ALPHA_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_FOG);
|
||||
#if (!defined(__TARGET_OS__Android) && !defined(__TARGET_OS__IOs))
|
||||
glPixelZoom(1.0,1.0);
|
||||
#endif
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_TEXTURE_2D);
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||
gale::openGL::disable(gale::openGL::FLAG_TEXTURE_2D);
|
||||
gale::openGL::disable(gale::openGL::FLAG_DEPTH_TEST);
|
||||
|
||||
ewol::openGL::enable(ewol::openGL::FLAG_BLEND);
|
||||
gale::openGL::enable(gale::openGL::FLAG_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// clear the matrix system :
|
||||
mat4 newOne;
|
||||
ewol::openGL::setBasicMatrix(newOne);
|
||||
gale::openGL::setBasicMatrix(newOne);
|
||||
|
||||
ewol::DrawProperty displayProp;
|
||||
displayProp.m_windowsSize = m_size;
|
||||
displayProp.m_origin.setValue(0,0);
|
||||
displayProp.m_size = m_size;
|
||||
systemDraw(displayProp);
|
||||
ewol::openGL::disable(ewol::openGL::FLAG_BLEND);
|
||||
gale::openGL::disable(gale::openGL::FLAG_BLEND);
|
||||
return;
|
||||
}
|
||||
|
||||
|
550
lutin_ewol.py
550
lutin_ewol.py
@ -52,38 +52,6 @@ def create(target):
|
||||
'ewol/context/cursor.cpp',
|
||||
'ewol/context/InputManager.cpp'
|
||||
])
|
||||
if target.name=="Linux":
|
||||
myModule.add_src_file('ewol/context/X11/Context.cpp')
|
||||
elif target.name=="Windows":
|
||||
myModule.add_src_file('ewol/context/Windows/Context.cpp')
|
||||
elif target.name=="Android":
|
||||
myModule.add_src_file('ewol/context/Android/Context.cpp')
|
||||
myModule.add_src_file([
|
||||
'android/src/org/ewol/EwolCallback.java',
|
||||
'android/src/org/ewol/EwolConstants.java',
|
||||
'android/src/org/ewol/Ewol.java',
|
||||
'android/src/org/ewol/EwolRendererGL.java',
|
||||
'android/src/org/ewol/EwolSurfaceViewGL.java',
|
||||
'android/src/org/ewol/EwolActivity.java',
|
||||
'android/src/org/ewol/EwolWallpaper.java',
|
||||
'org.ewol.EwolConstants.javah'
|
||||
])
|
||||
myModule.add_path(tools.get_current_path(__file__) + '/android/src/', type='java')
|
||||
elif target.name=="MacOs":
|
||||
myModule.add_src_file([
|
||||
'ewol/context/MacOs/Context.mm',
|
||||
'ewol/context/MacOs/Interface.mm',
|
||||
'ewol/context/MacOs/Windows.mm',
|
||||
'ewol/context/MacOs/OpenglView.mm',
|
||||
'ewol/context/MacOs/AppDelegate.mm'])
|
||||
elif target.name=="IOs":
|
||||
myModule.add_src_file([
|
||||
'ewol/context/IOs/Context.cpp',
|
||||
'ewol/context/IOs/Interface.m',
|
||||
'ewol/context/IOs/OpenglView.mm',
|
||||
'ewol/context/IOs/AppDelegate.mm'])
|
||||
else:
|
||||
debug.error("unknow mode...")
|
||||
|
||||
# event properties :
|
||||
myModule.add_src_file([
|
||||
@ -131,13 +99,9 @@ def create(target):
|
||||
'ewol/resource/Image.cpp',
|
||||
'ewol/resource/ImageDF.cpp',
|
||||
'ewol/resource/Manager.cpp',
|
||||
'ewol/resource/Program.cpp',
|
||||
'ewol/resource/Resource.cpp',
|
||||
'ewol/resource/Shader.cpp',
|
||||
'ewol/resource/Texture.cpp',
|
||||
'ewol/resource/TexturedFont.cpp',
|
||||
'ewol/resource/DistanceFieldFont.cpp',
|
||||
'ewol/resource/VirtualBufferObject.cpp'
|
||||
'ewol/resource/DistanceFieldFont.cpp'
|
||||
])
|
||||
|
||||
# widget :
|
||||
@ -195,7 +159,7 @@ def create(target):
|
||||
myModule.copy_folder('data/translate/*','translate/ewol/')
|
||||
|
||||
# name of the dependency
|
||||
myModule.add_module_depend(['etk', 'freetype', 'exml', 'ejson', 'egami', 'edtaa3', 'date'])
|
||||
myModule.add_module_depend(['etk', 'gale', 'freetype', 'exml', 'ejson', 'egami', 'edtaa3', 'date'])
|
||||
|
||||
myModule.add_export_path(tools.get_current_path(__file__))
|
||||
|
||||
@ -205,515 +169,5 @@ def create(target):
|
||||
"-DEWOL_VERSION=\"\\\""+ewolVersionID+"\\\"\""
|
||||
])
|
||||
|
||||
if target.name=="Linux":
|
||||
myModule.add_export_flag('link', '-lGL')
|
||||
#`pkg-config --cflags directfb` `pkg-config --libs directfb`
|
||||
#ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_X11__)","y")
|
||||
myModule.add_export_flag('link', '-lX11')
|
||||
#endif
|
||||
#ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_DIRECT_FB__)","y")
|
||||
#myModule.add_export_flag('link', ['-L/usr/local/lib', '-ldirectfb', '-lfusion', '-ldirect'])
|
||||
#endif
|
||||
elif target.name=="Android":
|
||||
myModule.add_module_depend(["SDK", "jvm-basics"])
|
||||
myModule.add_export_flag('link', "-lGLESv2")
|
||||
# add tre creator of the basic java class ...
|
||||
target.add_action("PACKAGE", 50, "ewol-auto-wrapper", tool_generate_main_java_class)
|
||||
# TODO : Add the same for BINARY to create a console interface ?
|
||||
elif target.name=="Windows":
|
||||
myModule.add_module_depend("glew")
|
||||
elif target.name=="MacOs":
|
||||
myModule.add_export_flag('link', [
|
||||
"-framework Cocoa",
|
||||
"-framework OpenGL",
|
||||
"-framework QuartzCore",
|
||||
"-framework AppKit"])
|
||||
elif target.name=="IOs":
|
||||
myModule.add_export_flag('link', [
|
||||
"-framework OpenGLES",
|
||||
"-framework CoreGraphics",
|
||||
"-framework UIKit",
|
||||
"-framework GLKit",
|
||||
"-framework Foundation",
|
||||
"-framework QuartzCore"])
|
||||
|
||||
return myModule
|
||||
|
||||
|
||||
|
||||
##################################################################
|
||||
##
|
||||
## Android specific section
|
||||
##
|
||||
##################################################################
|
||||
def tool_generate_main_java_class(target, module, package_name):
|
||||
file_list = []
|
||||
|
||||
debug.debug("------------------------------------------------------------------------")
|
||||
debug.debug("Generate android wrapping for '" + package_name + "'")
|
||||
debug.debug("------------------------------------------------------------------------")
|
||||
application_name = package_name
|
||||
if target.config["mode"] == "debug":
|
||||
application_name += "debug"
|
||||
target.folder_java_project= target.get_build_folder(package_name) \
|
||||
+ "/src/" \
|
||||
+ module.package_prop["COMPAGNY_TYPE"] \
|
||||
+ "/" + module.package_prop["COMPAGNY_NAME2"] \
|
||||
+ "/" + application_name + "/"
|
||||
|
||||
java_file_wrapper = target.folder_java_project + "/" + application_name + ".java"
|
||||
|
||||
android_package_name = module.package_prop["COMPAGNY_TYPE"]+"."+module.package_prop["COMPAGNY_NAME2"]+"." + application_name
|
||||
|
||||
debug.print_element("pkg", "absractionFile", "<==", "dynamic file")
|
||||
# Create folder :
|
||||
tools.create_directory_of_file(java_file_wrapper)
|
||||
debug.debug("create file : '" + java_file_wrapper + "'")
|
||||
# Create file :
|
||||
tmpFile = open(java_file_wrapper + "_tmp", 'w')
|
||||
|
||||
tmpFile.write( "/**\n")
|
||||
tmpFile.write( " * @author Edouard DUPIN, Kevin BILLONNEAU\n")
|
||||
tmpFile.write( " * @copyright 2011, Edouard DUPIN, all right reserved\n")
|
||||
tmpFile.write( " * @license APACHE v2.0 (see license file)\n")
|
||||
tmpFile.write( " * @note This file is autogenerate ==> see documantation to generate your own\n")
|
||||
tmpFile.write( " */\n")
|
||||
tmpFile.write( "package "+ android_package_name + ";\n")
|
||||
tmpFile.write( "import android.util.Log;\n")
|
||||
if module.package_prop["ANDROID_APPL_TYPE"]=="APPL":
|
||||
tmpFile.write( "import org.ewol.EwolActivity;\n")
|
||||
else:
|
||||
tmpFile.write( "import org.ewol.EwolWallpaper;\n")
|
||||
tmpFile.write( "\n")
|
||||
|
||||
if "GENERATE_SECTION__IMPORT" in module.package_prop:
|
||||
for elem in module.package_prop["GENERATE_SECTION__IMPORT"]:
|
||||
for line in elem:
|
||||
tmpFile.write( line + "\n")
|
||||
if module.package_prop["ANDROID_APPL_TYPE"]=="APPL":
|
||||
tmpFile.write( "public class " + application_name + " extends EwolActivity {\n")
|
||||
else:
|
||||
tmpFile.write( "public class " + application_name + " extends EwolWallpaper {\n")
|
||||
tmpFile.write( " public static final String SHARED_PREFS_NAME = \"" + application_name + "settings\";\n")
|
||||
|
||||
if "GENERATE_SECTION__DECLARE" in module.package_prop:
|
||||
for elem in module.package_prop["GENERATE_SECTION__DECLARE"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
|
||||
tmpFile.write( " \n")
|
||||
tmpFile.write( " static {\n")
|
||||
tmpFile.write( " try {\n")
|
||||
tmpFile.write( " System.loadLibrary(\"" + package_name + "\");\n")
|
||||
tmpFile.write( " } catch (UnsatisfiedLinkError e) {\n")
|
||||
tmpFile.write( " Log.e(\"" + application_name + "\", \"error getting lib(): \" + e);\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( " \n")
|
||||
if module.package_prop["ANDROID_APPL_TYPE"]!="APPL":
|
||||
tmpFile.write( " public Engine onCreateEngine() {\n")
|
||||
tmpFile.write( " Engine tmpEngine = super.onCreateEngine();\n")
|
||||
tmpFile.write( " initApkPath(\"" + module.package_prop["COMPAGNY_TYPE"]+"\", \""+module.package_prop["COMPAGNY_NAME2"]+"\", \"" + application_name + "\");\n")
|
||||
tmpFile.write( " return tmpEngine;\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__CONSTRUCTOR" in module.package_prop:
|
||||
tmpFile.write( " public " + application_name + "() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__CONSTRUCTOR"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
tmpFile.write( " public void onCreate(android.os.Bundle savedInstanceState) {\n")
|
||||
tmpFile.write( " super.onCreate(savedInstanceState);\n")
|
||||
tmpFile.write( " initApkPath(\"" + module.package_prop["COMPAGNY_TYPE"]+"\", \""+module.package_prop["COMPAGNY_NAME2"]+"\", \"" + application_name + "\");\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_CREATE" in module.package_prop:
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_CREATE"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
|
||||
if "GENERATE_SECTION__ON_START" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onStart() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_START"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " super.onStart();\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_RESTART" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onRestart() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_RESTART"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " super.onRestart();\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_RESUME" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onResume() {\n")
|
||||
tmpFile.write( " super.onResume();\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_RESUME"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_PAUSE" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onPause() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_PAUSE"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " super.onPause();\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_STOP" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onStop() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_STOP"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " super.onStop();\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
if "GENERATE_SECTION__ON_DESTROY" in module.package_prop:
|
||||
tmpFile.write( " @Override protected void onDestroy() {\n")
|
||||
for elem in module.package_prop["GENERATE_SECTION__ON_DESTROY"]:
|
||||
for line in elem:
|
||||
tmpFile.write( " " + line + "\n")
|
||||
tmpFile.write( " super.onDestroy();\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( "}\n")
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
|
||||
tools.move_if_needed(java_file_wrapper + "_tmp", java_file_wrapper);
|
||||
# add java file to build:
|
||||
module.add_src_file([java_file_wrapper])
|
||||
|
||||
"""
|
||||
## todo:
|
||||
tools.create_directory_of_file(target.get_staging_folder(package_name) + "/res/drawable/icon.png");
|
||||
if "ICON" in module.package_prop.keys() \
|
||||
and module.package_prop["ICON"] != "":
|
||||
image.resize(module.package_prop["ICON"], target.get_staging_folder(package_name) + "/res/drawable/icon.png", 256, 256)
|
||||
else:
|
||||
# to be sure that we have all time a resource ...
|
||||
tmpFile = open(target.get_staging_folder(package_name) + "/res/drawable/plop.txt", 'w')
|
||||
tmpFile.write('plop\n')
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
|
||||
"""
|
||||
if module.package_prop["ANDROID_MANIFEST"] == "":
|
||||
# force manifest file:
|
||||
module.package_prop["ANDROID_MANIFEST"] = target.get_build_folder(package_name) + "/AndroidManifest.xml";
|
||||
debug.debug(" create file: '" + module.package_prop["ANDROID_MANIFEST"] + "'")
|
||||
if "VERSION_CODE" not in module.package_prop:
|
||||
module.package_prop["VERSION_CODE"] = "1"
|
||||
debug.print_element("pkg", "AndroidManifest.xml", "<==", "package configurations")
|
||||
tools.create_directory_of_file(module.package_prop["ANDROID_MANIFEST"])
|
||||
tmpFile = open(module.package_prop["ANDROID_MANIFEST"], 'w')
|
||||
tmpFile.write( '<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
tmpFile.write( '<!-- Manifest is autoGenerated with Ewol ... do not patch it-->\n')
|
||||
tmpFile.write( '<manifest xmlns:android="http://schemas.android.com/apk/res/android" \n')
|
||||
tmpFile.write( ' package="' + android_package_name + '" \n')
|
||||
tmpFile.write( ' android:versionCode="'+module.package_prop["VERSION_CODE"]+'" \n')
|
||||
tmpFile.write( ' android:versionName="'+module.package_prop["VERSION"]+'"> \n')
|
||||
tmpFile.write( ' <uses-feature android:glEsVersion="0x00020000" android:required="true" />\n')
|
||||
tmpFile.write( ' <uses-sdk android:minSdkVersion="' + str(target.boardId) + '" \n')
|
||||
tmpFile.write( ' android:targetSdkVersion="' + str(target.boardId) + '" /> \n')
|
||||
if module.package_prop["ANDROID_APPL_TYPE"]=="APPL":
|
||||
tmpFile.write( ' <application android:label="' + application_name + '" \n')
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( ' android:icon="@drawable/icon" \n')
|
||||
if target.config["mode"] == "debug":
|
||||
tmpFile.write( ' android:debuggable="true" \n')
|
||||
tmpFile.write( ' >\n')
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
tmpFile.write( ' <meta-data android:name="com.google.android.gms.version" \n')
|
||||
tmpFile.write( ' android:value="@integer/google_play_services_version"/>\n')
|
||||
|
||||
tmpFile.write( ' <activity android:name=".' + application_name + '" \n')
|
||||
tmpFile.write( ' android:label="' + module.package_prop['NAME'])
|
||||
if target.config["mode"] == "debug":
|
||||
tmpFile.write("-debug")
|
||||
tmpFile.write( '"\n')
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( ' android:icon="@drawable/icon" \n')
|
||||
tmpFile.write( ' android:hardwareAccelerated="true" \n')
|
||||
tmpFile.write( ' android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> \n')
|
||||
tmpFile.write( ' <intent-filter> \n')
|
||||
tmpFile.write( ' <action android:name="android.intent.action.MAIN" /> \n')
|
||||
tmpFile.write( ' <category android:name="android.intent.category.LAUNCHER" /> \n')
|
||||
tmpFile.write( ' </intent-filter> \n')
|
||||
tmpFile.write( ' </activity> \n')
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
tmpFile.write( ' <activity android:name="com.google.android.gms.ads.AdActivity"\n')
|
||||
tmpFile.write( ' android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>\n')
|
||||
|
||||
tmpFile.write( ' </application>\n')
|
||||
else:
|
||||
tmpFile.write( ' <application android:label="' + application_name + '" \n')
|
||||
tmpFile.write( ' android:permission="android.permission.BIND_WALLPAPER" \n')
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( ' android:icon="@drawable/icon"\n')
|
||||
tmpFile.write( ' >\n')
|
||||
tmpFile.write( ' <service android:name=".' + application_name + '" \n')
|
||||
tmpFile.write( ' android:label="' + module.package_prop['NAME'])
|
||||
if target.config["mode"] == "debug":
|
||||
tmpFile.write("-debug")
|
||||
tmpFile.write( '"\n')
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( ' android:icon="@drawable/icon"\n')
|
||||
tmpFile.write( ' >\n')
|
||||
tmpFile.write( ' <intent-filter>\n')
|
||||
tmpFile.write( ' <action android:name="android.service.wallpaper.WallpaperService" />\n')
|
||||
tmpFile.write( ' </intent-filter>\n')
|
||||
tmpFile.write( ' <meta-data android:name="android.service.wallpaper"\n')
|
||||
tmpFile.write( ' android:resource="@xml/' + application_name + '_resource" />\n')
|
||||
tmpFile.write( ' </service>\n')
|
||||
if len(module.package_prop["ANDROID_WALLPAPER_PROPERTIES"])!=0:
|
||||
tmpFile.write( ' <activity android:label="Setting"\n')
|
||||
tmpFile.write( ' android:name=".' + application_name + 'Settings"\n')
|
||||
tmpFile.write( ' android:theme="@android:style/Theme.Light.WallpaperSettings"\n')
|
||||
tmpFile.write( ' android:exported="true"\n')
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( ' android:icon="@drawable/icon"\n')
|
||||
tmpFile.write( ' >\n')
|
||||
tmpFile.write( ' </activity>\n')
|
||||
tmpFile.write( ' </application>\n')
|
||||
# write package autorisations :
|
||||
if True==target.check_right_package(module.package_prop, "WRITE_EXTERNAL_STORAGE"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "CAMERA"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.CAMERA" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.CAMERA" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "INTERNET"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.INTERNET" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.INTERNET" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "ACCESS_NETWORK_STATE"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.ACCESS_NETWORK_STATE" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "MODIFY_AUDIO_SETTINGS"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "READ_CALENDAR"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.READ_CALENDAR" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.READ_CALENDAR" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "READ_CONTACTS"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.READ_CONTACTS" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.READ_CONTACTS" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "READ_FRAME_BUFFER"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.READ_FRAME_BUFFER" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.READ_FRAME_BUFFER" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "READ_PROFILE"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.READ_PROFILE" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.READ_PROFILE" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "RECORD_AUDIO"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.RECORD_AUDIO" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.RECORD_AUDIO" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "SET_ORIENTATION"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.SET_ORIENTATION" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.SET_ORIENTATION" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "VIBRATE"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.VIBRATE" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.VIBRATE" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "ACCESS_COARSE_LOCATION"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> \n')
|
||||
if True==target.check_right_package(module.package_prop, "ACCESS_FINE_LOCATION"):
|
||||
tmpFile.write( ' <permission android:name="android.permission.ACCESS_FINE_LOCATION" /> \n')
|
||||
tmpFile.write( ' <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> \n')
|
||||
tmpFile.write( '</manifest>\n\n')
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
# end generating android manifest
|
||||
|
||||
if module.package_prop["ANDROID_APPL_TYPE"]!="APPL":
|
||||
#create the Wallpaper sub files : (main element for the application
|
||||
debug.print_element("pkg", application_name + "_resource.xml", "<==", "package configurations")
|
||||
tools.create_directory_of_file(target.get_build_folder(package_name) + "/res/xml/" + application_name + "_resource.xml")
|
||||
tmpFile = open(target.get_build_folder(package_name) + "/res/xml/" + application_name + "_resource.xml", 'w')
|
||||
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
tmpFile.write( "<wallpaper xmlns:android=\"http://schemas.android.com/apk/res/android\"\n")
|
||||
if len(module.package_prop["ANDROID_WALLPAPER_PROPERTIES"])!=0:
|
||||
tmpFile.write( " android:settingsActivity=\""+android_package_name + "."+ application_name + "Settings\"\n")
|
||||
if "ICON" in module.package_prop.keys():
|
||||
tmpFile.write( " android:thumbnail=\"@drawable/icon\"\n")
|
||||
tmpFile.write( " />\n")
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
# create wallpaper setting if needed (class and config file)
|
||||
if len(module.package_prop["ANDROID_WALLPAPER_PROPERTIES"])!=0:
|
||||
tools.create_directory_of_file(target.folder_java_project + application_name + "Settings.java")
|
||||
debug.print_element("pkg", target.folder_java_project + application_name + "Settings.java", "<==", "package configurations")
|
||||
tmpFile = open(target.folder_java_project + application_name + "Settings.java", 'w');
|
||||
tmpFile.write( "package " + android_package_name + ";\n")
|
||||
tmpFile.write( "\n")
|
||||
tmpFile.write( "import " + android_package_name + ".R;\n")
|
||||
tmpFile.write( "\n")
|
||||
tmpFile.write( "import android.content.SharedPreferences;\n")
|
||||
tmpFile.write( "import android.os.Bundle;\n")
|
||||
tmpFile.write( "import android.preference.PreferenceActivity;\n")
|
||||
tmpFile.write( "\n")
|
||||
tmpFile.write( "public class " + application_name + "Settings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener\n")
|
||||
tmpFile.write( "{\n")
|
||||
tmpFile.write( " @Override protected void onCreate(Bundle icicle) {\n")
|
||||
tmpFile.write( " super.onCreate(icicle);\n")
|
||||
tmpFile.write( " getPreferenceManager().setSharedPreferencesName("+ application_name + ".SHARED_PREFS_NAME);\n")
|
||||
tmpFile.write( " addPreferencesFromResource(R.xml."+ application_name + "_settings);\n")
|
||||
tmpFile.write( " getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( " @Override protected void onResume() {\n")
|
||||
tmpFile.write( " super.onResume();\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( " @Override protected void onDestroy() {\n")
|
||||
tmpFile.write( " getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);\n")
|
||||
tmpFile.write( " super.onDestroy();\n")
|
||||
tmpFile.write( " }\n")
|
||||
tmpFile.write( " public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) { }\n")
|
||||
tmpFile.write( "}\n")
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
|
||||
debug.print_element("pkg", target.get_build_folder(package_name) + "/res/xml/" + application_name + "_settings.xml", "<==", "package configurations")
|
||||
tools.create_directory_of_file(target.get_build_folder(package_name) + "/res/xml/" + application_name + "_settings.xml")
|
||||
tmpFile = open(target.get_build_folder(package_name) + "/res/xml/" + application_name + "_settings.xml", 'w');
|
||||
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
tmpFile.write( "<PreferenceScreen xmlns:android=\"http://schemas.android.com/apk/res/android\"\n")
|
||||
tmpFile.write( " android:title=\"Settings\"\n")
|
||||
tmpFile.write( " android:key=\"" + application_name + "_settings\">\n")
|
||||
WALL_haveArray = False
|
||||
for WALL_type, WALL_key, WALL_title, WALL_summary, WALL_other in module.package_prop["ANDROID_WALLPAPER_PROPERTIES"]:
|
||||
debug.info("find : '" + WALL_type + "'");
|
||||
if WALL_type == "list":
|
||||
debug.info(" create : LIST");
|
||||
tmpFile.write( " <ListPreference android:key=\"" + application_name + "_" + WALL_key + "\"\n")
|
||||
tmpFile.write( " android:title=\"" + WALL_title + "\"\n")
|
||||
tmpFile.write( " android:summary=\"" + WALL_summary + "\"\n")
|
||||
tmpFile.write( " android:entries=\"@array/" + application_name + "_" + WALL_key + "_names\"\n")
|
||||
tmpFile.write( " android:entryValues=\"@array/" + application_name + "_" + WALL_key + "_prefix\"/>\n")
|
||||
WALL_haveArray=True
|
||||
elif WALL_type == "bool":
|
||||
debug.info(" create : CHECKBOX");
|
||||
tmpFile.write( " <CheckBoxPreference android:key=\"" + application_name + "_" + WALL_key + "\"\n")
|
||||
tmpFile.write( " android:title=\"" + WALL_title + "\"\n")
|
||||
tmpFile.write( " android:summary=\"" + WALL_summary + "\"\n")
|
||||
tmpFile.write( " android:summaryOn=\"" + WALL_other[0] + "\"\n")
|
||||
tmpFile.write( " android:summaryOff=\"" + WALL_other[1] + "\"/>\n")
|
||||
tmpFile.write( "</PreferenceScreen>\n")
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
if WALL_haveArray==True:
|
||||
for WALL_type, WALL_key, WALL_title, WALL_summary, WALL_other in module.package_prop["ANDROID_WALLPAPER_PROPERTIES"]:
|
||||
if WALL_type == "list":
|
||||
debug.print_element("pkg", target.get_build_folder(package_name) + "/res/values/" + WALL_key + ".xml", "<==", "package configurations")
|
||||
tools.create_directory_of_file(target.get_build_folder(package_name) + "/res/values/" + WALL_key + ".xml")
|
||||
tmpFile = open(target.get_build_folder(package_name) + "/res/values/" + WALL_key + ".xml", 'w');
|
||||
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
tmpFile.write( "<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n")
|
||||
tmpFile.write( " <string-array name=\"" + application_name + "_" + WALL_key + "_names\">\n")
|
||||
for WALL_subKey, WALL_display in WALL_other:
|
||||
tmpFile.write( " <item>" + WALL_display + "</item>\n")
|
||||
tmpFile.write( " </string-array>\n")
|
||||
tmpFile.write( " <string-array name=\"" + application_name + "_" + WALL_key + "_prefix\">\n")
|
||||
for WALL_subKey, WALL_display in WALL_other:
|
||||
tmpFile.write( " <item>" + WALL_subKey + "</item>\n")
|
||||
tmpFile.write( " </string-array>\n")
|
||||
tmpFile.write( "</resources>\n")
|
||||
tmpFile.flush()
|
||||
tmpFile.close()
|
||||
|
||||
|
||||
"""
|
||||
#add properties on wallpaper :
|
||||
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["list", key, title, summary, [["key","value display"],["key2","value display 2"]])
|
||||
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["list", "testpattern", "Select test pattern", "Choose which test pattern to display", [["key","value display"],["key2","value display 2"]]])
|
||||
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["bool", key, title, summary, ["enable string", "disable String"])
|
||||
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["bool", "movement", "Motion", "Apply movement to test pattern", ["Moving test pattern", "Still test pattern"]
|
||||
#copy needed resources :
|
||||
for res_source, res_dest in module.package_prop["ANDROID_RESOURCES"]:
|
||||
if res_source == "":
|
||||
continue
|
||||
tools.copy_file(res_source , target.get_staging_folder(package_name) + "/res/" + res_dest + "/" + os.path.basename(res_source), force=True)
|
||||
"""
|
||||
"""
|
||||
# Doc :
|
||||
# http://asantoso.wordpress.com/2009/09/15/how-to-build-android-application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/
|
||||
debug.print_element("pkg", "R.java", "<==", "Resources files")
|
||||
tools.create_directory_of_file(target.get_staging_folder(package_name) + "/src/noFile")
|
||||
androidToolPath = target.folder_sdk + "/build-tools/"
|
||||
# find android tool version
|
||||
dirnames = tools.get_list_sub_folder(androidToolPath)
|
||||
if len(dirnames) != 1:
|
||||
debug.error("an error occured when getting the tools for android")
|
||||
androidToolPath += dirnames[0] + "/"
|
||||
|
||||
adModResouceFolder = ""
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
adModResouceFolder = " -S " + target.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/res/ "
|
||||
cmdLine = androidToolPath + "aapt p -f " \
|
||||
+ "-M " + target.get_staging_folder(package_name) + "/AndroidManifest.xml " \
|
||||
+ "-F " + target.get_staging_folder(package_name) + "/resources.res " \
|
||||
+ "-I " + target.folder_sdk + "/platforms/android-" + str(target.boardId) + "/android.jar "\
|
||||
+ "-S " + target.get_staging_folder(package_name) + "/res/ " \
|
||||
+ adModResouceFolder \
|
||||
+ "-J " + target.get_staging_folder(package_name) + "/src/ "
|
||||
multiprocess.run_command(cmdLine)
|
||||
#aapt package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library}
|
||||
# -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]
|
||||
|
||||
tools.create_directory_of_file(target.get_staging_folder(package_name) + "/build/classes/noFile")
|
||||
debug.print_element("pkg", "*.class", "<==", "*.java")
|
||||
# more information with : -Xlint
|
||||
# + java_file_wrapper + " "\ # this generate ex: out/Android/debug/staging/tethys/src/com/edouarddupin/tethys/edn.java
|
||||
|
||||
#generate android java files:
|
||||
filesString=""
|
||||
for element in module.package_prop["ANDROID_JAVA_FILES"]:
|
||||
if element=="DEFAULT":
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolAudioTask.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolCallback.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolConstants.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/Ewol.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolRendererGL.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolSurfaceViewGL.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolActivity.java "
|
||||
filesString += target.folder_ewol + "/android/src/org/ewol/EwolWallpaper.java "
|
||||
else:
|
||||
filesString += element + " "
|
||||
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
filesString += target.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/src/android/UnusedStub.java "
|
||||
|
||||
if len(module.package_prop["ANDROID_WALLPAPER_PROPERTIES"])!=0:
|
||||
filesString += target.folder_java_project + application_name + "Settings.java "
|
||||
|
||||
adModJarFile = ""
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
adModJarFile = ":" + target.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"
|
||||
|
||||
cmdLine = "javac " \
|
||||
+ "-d " + target.get_staging_folder(package_name) + "/build/classes " \
|
||||
+ "-classpath " + target.folder_sdk + "/platforms/android-" + str(target.boardId) + "/android.jar" \
|
||||
+ adModJarFile + " " \
|
||||
+ filesString \
|
||||
+ java_file_wrapper + " " \
|
||||
+ target.get_staging_folder(package_name) + "/src/R.java "
|
||||
multiprocess.run_command(cmdLine)
|
||||
|
||||
debug.print_element("pkg", ".dex", "<==", "*.class")
|
||||
cmdLine = androidToolPath + "dx " \
|
||||
+ "--dex --no-strict " \
|
||||
+ "--output=" + target.get_staging_folder(package_name) + "/build/" + application_name + ".dex " \
|
||||
+ target.get_staging_folder(package_name) + "/build/classes/ "
|
||||
|
||||
if "ADMOD_ID" in module.package_prop:
|
||||
cmdLine += target.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar "
|
||||
multiprocess.run_command(cmdLine)
|
||||
"""
|
||||
return {"files":file_list}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user