parent
cf0aab6d4d
commit
7eead50806
@ -0,0 +1,5 @@
|
||||
function dumpWidgets()
|
||||
for i=1,UI.root:getChildCount() do
|
||||
print(UI.root:getChildByIndex(i):getId())
|
||||
end
|
||||
end
|
@ -1,43 +1,33 @@
|
||||
local eventId = 0
|
||||
local eventsTable = { }
|
||||
local orig = { scheduleEvent = scheduleEvent,
|
||||
addEvent = addEvent }
|
||||
local eventList = {}
|
||||
|
||||
-- fix original scheduleEvent
|
||||
function scheduleEvent(func, delay)
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
if eventList[id] then
|
||||
if eventList[id].active then
|
||||
func()
|
||||
end
|
||||
eventList[id] = nil
|
||||
end
|
||||
end
|
||||
eventsTable[id] = proxyFunc
|
||||
orig.scheduleEvent(proxyFunc, delay)
|
||||
eventList[id] = { func = proxyFunc, active = true }
|
||||
if delay and delay > 0 then
|
||||
g_dispatcher.scheduleEvent(proxyFunc, delay)
|
||||
else
|
||||
g_dispatcher.addEvent(proxyFunc, false)
|
||||
end
|
||||
return id
|
||||
end
|
||||
|
||||
-- FIXME: the event function can be collected
|
||||
-- and the dispatcher would call an invalid function, generating an warning
|
||||
function addEvent(func)
|
||||
return scheduleEvent(func, 0)
|
||||
end
|
||||
|
||||
function removeEvent(id)
|
||||
if id and eventsTable[id] then
|
||||
eventsTable[id] = nil
|
||||
if id and eventList[id] then
|
||||
eventList[id].active = false
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- fix original addEvent
|
||||
function addEvent(func)
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
end
|
||||
end
|
||||
eventsTable[id] = proxyFunc
|
||||
orig.addEvent(proxyFunc)
|
||||
return id
|
||||
end
|
@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "painter.h"
|
||||
#include "texture.h"
|
||||
#include "paintershadersources.h"
|
||||
#include "paintershaderprogram.h"
|
||||
#include "shaderprogram.h"
|
||||
#include "graphics.h"
|
||||
|
||||
Painter g_painter;
|
||||
|
||||
void Painter::init()
|
||||
{
|
||||
setColor(Fw::white);
|
||||
setOpacity(255);
|
||||
setCompositionMode(CompositionMode_SourceOver);
|
||||
|
||||
PainterShaderProgramPtr program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader);
|
||||
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
|
||||
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
|
||||
program->addShaderFromSourceCode(Shader::Fragment, glslTextureSrcFragmentShader);
|
||||
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||
program->bindAttributeLocation(TEXTURE_COORDS_ATTR, "textureCoord");
|
||||
assert(program->link());
|
||||
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::TEXTURE_TRANSFORM_MATRIX_UNIFORM, "textureTransformMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::COLOR_UNIFORM, "color");
|
||||
program->bindUniformLocation(PainterShaderProgram::OPACITY_UNIFORM, "opacity");
|
||||
program->bindUniformLocation(PainterShaderProgram::TEXTURE_UNIFORM, "texture");
|
||||
m_drawTexturedProgram = program;
|
||||
|
||||
program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
program->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader);
|
||||
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
|
||||
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
|
||||
program->addShaderFromSourceCode(Shader::Fragment, glslSolidColorFragmentShader);
|
||||
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||
assert(program->link());
|
||||
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::COLOR_UNIFORM, "color");
|
||||
program->bindUniformLocation(PainterShaderProgram::OPACITY_UNIFORM, "opacity");
|
||||
m_drawSolidColorProgram = program;
|
||||
}
|
||||
|
||||
void Painter::terminate()
|
||||
{
|
||||
m_drawTexturedProgram.reset();
|
||||
m_drawSolidColorProgram.reset();
|
||||
}
|
||||
|
||||
void Painter::updateProjectionMatrix(const Size& viewportSize, bool inverseYAxis)
|
||||
{
|
||||
// The projection matrix converts from Painter's coordinate system to GL's coordinate system
|
||||
// * GL's viewport is 2x2, Painter's is width x height
|
||||
// * GL has +y -> -y going from bottom -> top, Painter is the other way round
|
||||
// * GL has [0,0] in the center, Painter has it in the top-left
|
||||
//
|
||||
// This results in the Projection matrix below, which is multiplied by the painter's
|
||||
// transformation matrix, as shown below:
|
||||
//
|
||||
// Projection Matrix Painter Coord GL Coord
|
||||
// ------------------------------------------------ --------- ---------
|
||||
// | 2.0 / width | 0.0 | -1.0 | | x | | y' |
|
||||
// | 0.0 | -2.0 / height | 1.0 | * | y | = | x' |
|
||||
// | 0.0 | 0.0 | 0.0 | | 1 | | 0 |
|
||||
// ------------------------------------------------ --------- ---------
|
||||
float w = viewportSize.width();
|
||||
float h = viewportSize.height();
|
||||
if(inverseYAxis) {
|
||||
m_projectionMatrix[0][0] = 2.0f/w; m_projectionMatrix[0][1] = 0.0f; m_projectionMatrix[0][2] =-1.0f;
|
||||
m_projectionMatrix[1][0] = 0.0f; m_projectionMatrix[1][1] = 2.0f/h; m_projectionMatrix[1][2] =-1.0f;
|
||||
m_projectionMatrix[2][0] = 0.0f; m_projectionMatrix[2][1] = 0.0f; m_projectionMatrix[2][2] = 0.0f;
|
||||
} else {
|
||||
m_projectionMatrix[0][0] = 2.0f/w; m_projectionMatrix[0][1] = 0.0f; m_projectionMatrix[0][2] =-1.0f;
|
||||
m_projectionMatrix[1][0] = 0.0f; m_projectionMatrix[1][1] =-2.0f/h; m_projectionMatrix[1][2] = 1.0f;
|
||||
m_projectionMatrix[2][0] = 0.0f; m_projectionMatrix[2][1] = 0.0f; m_projectionMatrix[2][2] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture)
|
||||
{
|
||||
drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize()));
|
||||
}
|
||||
|
||||
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
GLfloat vertexCoords[] = { (float)dest.left(), (float)dest.top(),
|
||||
(float)dest.right()+1, (float)dest.top(),
|
||||
(float)dest.left(), (float)dest.bottom()+1,
|
||||
(float)dest.right()+1, (float)dest.bottom()+1 };
|
||||
|
||||
GLfloat textureCoords[] = { (float)src.left(), (float)src.top(),
|
||||
(float)src.right()+1, (float)src.top(),
|
||||
(float)src.left(), (float)src.bottom()+1,
|
||||
(float)src.right()+1, (float)src.bottom()+1 };
|
||||
|
||||
m_drawTexturedProgram->prepareForDraw();
|
||||
m_drawTexturedProgram->setProjectionMatrix(m_projectionMatrix);
|
||||
m_drawTexturedProgram->setOpacity(m_currentOpacity);
|
||||
m_drawTexturedProgram->setColor(m_currentColor);
|
||||
m_drawTexturedProgram->setTexture(texture);
|
||||
m_drawTexturedProgram->setVertexCoords(vertexCoords);
|
||||
m_drawTexturedProgram->setTextureCoords(textureCoords);
|
||||
m_drawTexturedProgram->drawTriangleStrip(4);
|
||||
m_drawTexturedProgram->releaseFromDraw();
|
||||
}
|
||||
|
||||
void Painter::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
//TODO: use vertex arrays..
|
||||
Rect virtualDest(0, 0, dest.size());
|
||||
for(int y = 0; y <= virtualDest.height(); y += src.height()) {
|
||||
for(int x = 0; x <= virtualDest.width(); x += src.width()) {
|
||||
Rect partialDest(x, y, src.size());
|
||||
Rect partialSrc = src;
|
||||
|
||||
// partialCoords to screenCoords bottomRight
|
||||
if(partialDest.bottom() > virtualDest.bottom()) {
|
||||
partialSrc.setBottom(partialSrc.bottom() + (virtualDest.bottom() - partialDest.bottom()));
|
||||
partialDest.setBottom(virtualDest.bottom());
|
||||
}
|
||||
if(partialDest.right() > virtualDest.right()) {
|
||||
partialSrc.setRight(partialSrc.right() + (virtualDest.right() - partialDest.right()));
|
||||
partialDest.setRight(virtualDest.right());
|
||||
}
|
||||
|
||||
partialDest.translate(dest.topLeft());
|
||||
drawTexturedRect(partialDest, texture, partialSrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::drawFilledRect(const Rect& dest)
|
||||
{
|
||||
if(dest.isEmpty())
|
||||
return;
|
||||
|
||||
GLfloat right = dest.right()+1;
|
||||
GLfloat bottom = dest.bottom()+1;
|
||||
GLfloat top = dest.top();
|
||||
GLfloat left = dest.left();
|
||||
|
||||
GLfloat vertexCoords[] = { left, top,
|
||||
right, top,
|
||||
left, bottom,
|
||||
right, bottom };
|
||||
|
||||
m_drawSolidColorProgram->prepareForDraw();
|
||||
m_drawSolidColorProgram->setProjectionMatrix(m_projectionMatrix);
|
||||
m_drawSolidColorProgram->setOpacity(m_currentOpacity);
|
||||
m_drawSolidColorProgram->setColor(m_currentColor);
|
||||
m_drawSolidColorProgram->setVertexCoords(vertexCoords);
|
||||
m_drawSolidColorProgram->drawTriangleStrip(4);
|
||||
m_drawSolidColorProgram->releaseFromDraw();
|
||||
}
|
||||
|
||||
void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||
{
|
||||
if(dest.isEmpty() || innerLineWidth == 0)
|
||||
return;
|
||||
|
||||
GLfloat right = dest.right()+1;
|
||||
GLfloat bottom = dest.bottom()+1;
|
||||
GLfloat top = dest.top();
|
||||
GLfloat left = dest.left();
|
||||
GLfloat w = innerLineWidth;
|
||||
|
||||
GLfloat vertexCoords[] = { left, top,
|
||||
right, top,
|
||||
left, top+w,
|
||||
right, top+w,
|
||||
right-w, top+w,
|
||||
right, bottom,
|
||||
right-w, bottom,
|
||||
right-w, bottom-w,
|
||||
left, bottom,
|
||||
left, bottom-w,
|
||||
left+w, bottom-w,
|
||||
left, top+w,
|
||||
left+w, top+w };
|
||||
|
||||
m_drawSolidColorProgram->prepareForDraw();
|
||||
m_drawSolidColorProgram->setProjectionMatrix(m_projectionMatrix);
|
||||
m_drawSolidColorProgram->setOpacity(m_currentOpacity);
|
||||
m_drawSolidColorProgram->setColor(m_currentColor);
|
||||
m_drawSolidColorProgram->setVertexCoords(vertexCoords);
|
||||
m_drawSolidColorProgram->drawTriangleStrip(13);
|
||||
m_drawSolidColorProgram->releaseFromDraw();
|
||||
}
|
||||
|
||||
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||
{
|
||||
switch(compositionMode) {
|
||||
case CompositionMode_SourceOver:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case CompositionMode_ColorizeDest:
|
||||
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PAINTER_H
|
||||
#define PAINTER_H
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
class Painter
|
||||
{
|
||||
public:
|
||||
enum CompositionMode {
|
||||
CompositionMode_SourceOver,
|
||||
CompositionMode_ColorizeDest
|
||||
};
|
||||
|
||||
void init();
|
||||
void terminate();
|
||||
|
||||
void updateProjectionMatrix(const Size& viewportSize, bool inverseYAxis = false);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawFilledRect(const Rect& dest);
|
||||
void drawBoundingRect(const Rect& dest, int innerLineWidth = 1);
|
||||
|
||||
void setColor(const Color& color) { m_currentColor = color; }
|
||||
Color getColor() { return m_currentColor; }
|
||||
|
||||
void setOpacity(int opacity) { m_currentOpacity = opacity / 255.0f; }
|
||||
int getOpacity() { return m_currentOpacity * 255.0f; }
|
||||
|
||||
void setCompositionMode(CompositionMode compositionMode);
|
||||
|
||||
private:
|
||||
PainterShaderProgramPtr m_drawTexturedProgram;
|
||||
PainterShaderProgramPtr m_drawSolidColorProgram;
|
||||
GLfloat m_projectionMatrix[3][3];
|
||||
Color m_currentColor;
|
||||
GLfloat m_currentOpacity;
|
||||
};
|
||||
|
||||
extern Painter g_painter;
|
||||
|
||||
#endif
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "paintershaderprogram.h"
|
||||
#include "painter.h"
|
||||
#include "texture.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
void PainterShaderProgram::setProjectionMatrix(float projectionMatrix[3][3])
|
||||
{
|
||||
setUniformValue(PROJECTION_MATRIX_UNIFORM, projectionMatrix, true);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setColor(const Color& color)
|
||||
{
|
||||
setUniformValue(COLOR_UNIFORM,
|
||||
color.r() / 255.0f,
|
||||
color.g() / 255.0f,
|
||||
color.b() / 255.0f,
|
||||
color.a() / 255.0f);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setOpacity(GLfloat opacity)
|
||||
{
|
||||
setUniformValue(OPACITY_UNIFORM, opacity);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setTexture(const TexturePtr& texture)
|
||||
{
|
||||
float w = texture->getGlSize().width();
|
||||
float h = texture->getGlSize().height();
|
||||
|
||||
GLfloat textureTransformMatrix[2][2] = {
|
||||
{ 1.0f/w, 0.0f },
|
||||
{ 0.0f, 1.0f/h }
|
||||
};
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getId());
|
||||
setUniformValue(TEXTURE_UNIFORM, 0);
|
||||
setUniformValue(TEXTURE_TRANSFORM_MATRIX_UNIFORM, textureTransformMatrix, true);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setVertexCoords(const GLfloat *vertices)
|
||||
{
|
||||
enableAttributeArray(PainterShaderProgram::VERTEX_COORDS_ATTR);
|
||||
setAttributeArray(PainterShaderProgram::VERTEX_COORDS_ATTR, vertices, 2);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setTextureCoords(const GLfloat *textureCoords)
|
||||
{
|
||||
enableAttributeArray(PainterShaderProgram::TEXTURE_COORDS_ATTR);
|
||||
setAttributeArray(PainterShaderProgram::TEXTURE_COORDS_ATTR, textureCoords, 2);
|
||||
m_mustDisableTexCoordsArray = true;
|
||||
}
|
||||
|
||||
void PainterShaderProgram::prepareForDraw()
|
||||
{
|
||||
assert(bind());
|
||||
}
|
||||
|
||||
void PainterShaderProgram::drawTriangleStrip(int numVertices)
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::releaseFromDraw()
|
||||
{
|
||||
if(m_mustDisableTexCoordsArray) {
|
||||
disableAttributeArray(PainterShaderProgram::TEXTURE_COORDS_ATTR);
|
||||
m_mustDisableTexCoordsArray = false;
|
||||
}
|
||||
|
||||
if(m_mustDisableVertexArray) {
|
||||
disableAttributeArray(PainterShaderProgram::VERTEX_COORDS_ATTR);
|
||||
m_mustDisableVertexArray = false;
|
||||
}
|
||||
|
||||
//release();
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PAINTERSHADER_H
|
||||
#define PAINTERSHADER_H
|
||||
|
||||
#include "shaderprogram.h"
|
||||
|
||||
class PainterShaderProgram : public ShaderProgram
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
VERTEX_COORDS_ATTR = 0,
|
||||
TEXTURE_COORDS_ATTR = 1,
|
||||
PROJECTION_MATRIX_UNIFORM = 0,
|
||||
TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1,
|
||||
COLOR_UNIFORM = 2,
|
||||
OPACITY_UNIFORM = 3,
|
||||
TEXTURE_UNIFORM = 4
|
||||
};
|
||||
|
||||
void setProjectionMatrix(GLfloat projectionMatrix[3][3]);
|
||||
void setColor(const Color& color);
|
||||
void setOpacity(GLfloat opacity);
|
||||
void setTexture(const TexturePtr& texture);
|
||||
void setVertexCoords(const GLfloat *vertices);
|
||||
void setTextureCoords(const GLfloat *textureCoords);
|
||||
|
||||
void prepareForDraw();
|
||||
void drawTriangleStrip(int numVertices);
|
||||
void releaseFromDraw();
|
||||
|
||||
private:
|
||||
Boolean<false> m_mustDisableVertexArray;
|
||||
Boolean<false> m_mustDisableTexCoordsArray;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
static int VERTEX_COORDS_ATTR = 0;
|
||||
static int TEXTURE_COORDS_ATTR = 1;
|
||||
|
||||
static int PROJECTION_MATRIX_UNIFORM = 0;
|
||||
static int TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1;
|
||||
static int COLOR_UNIFORM = 2;
|
||||
static int OPACITY_UNIFORM = 3;
|
||||
static int TEXTURE_UNIFORM = 4;
|
||||
|
||||
static const char *glslMainVertexShader = "\n\
|
||||
vec4 calculatePosition();\n\
|
||||
void main() {\n\
|
||||
gl_Position = calculatePosition();\n\
|
||||
}\n";
|
||||
|
||||
static const char *glslMainWithTexCoordsVertexShader = "\n\
|
||||
attribute vec2 textureCoord;\n\
|
||||
uniform mat2 textureTransformMatrix;\n\
|
||||
varying vec2 textureCoords;\n\
|
||||
vec4 calculatePosition();\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
gl_Position = calculatePosition();\n\
|
||||
textureCoords = textureTransformMatrix * textureCoord;\n\
|
||||
}\n";
|
||||
|
||||
static const char *glslPositionOnlyVertexShader = "\n\
|
||||
attribute vec2 vertexCoord;\n\
|
||||
uniform mat3 projectionMatrix;\n\
|
||||
vec4 calculatePosition() {\n\
|
||||
return vec4(projectionMatrix * vec3(vertexCoord.xy, 1), 1);\n\
|
||||
}\n";
|
||||
|
||||
static const char *glslMainFragmentShader = "\n\
|
||||
uniform float opacity;\n\
|
||||
vec4 calculatePixel();\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
gl_FragColor = calculatePixel() * opacity;\n\
|
||||
}\n";
|
||||
|
||||
static const char *glslTextureSrcFragmentShader = "\n\
|
||||
varying vec2 textureCoords;\n\
|
||||
uniform vec4 color;\n\
|
||||
uniform sampler2D texture;\n\
|
||||
vec4 calculatePixel() {\n\
|
||||
return texture2D(texture, textureCoords) * color;\n\
|
||||
}\n";
|
||||
|
||||
static const char *glslSolidColorFragmentShader = "\n\
|
||||
uniform vec4 color;\n\
|
||||
vec4 calculatePixel() {\n\
|
||||
return color;\n\
|
||||
}\n";
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
Shader::Shader(Shader::ShaderType shaderType)
|
||||
{
|
||||
m_shaderType = shaderType;
|
||||
switch(shaderType) {
|
||||
case Vertex:
|
||||
m_shaderId = glCreateShader(GL_VERTEX_SHADER);
|
||||
break;
|
||||
case Fragment:
|
||||
m_shaderId = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!m_shaderId)
|
||||
logFatal("Unable to create GL shader");
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
glDeleteShader(m_shaderId);
|
||||
}
|
||||
|
||||
bool Shader::compileSourceCode(const std::string& sourceCode)
|
||||
{
|
||||
const char *c_source = sourceCode.c_str();
|
||||
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
||||
glCompileShader(m_shaderId);
|
||||
|
||||
int res;
|
||||
glGetShaderiv(m_shaderId, GL_COMPILE_STATUS, &res);
|
||||
return (res == GL_TRUE);
|
||||
}
|
||||
|
||||
bool Shader::compileSourceFile(const std::string& sourceFile)
|
||||
{
|
||||
std::ifstream fin(sourceFile);
|
||||
std::string sourceCode((std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>());
|
||||
return compileSourceCode(sourceCode);
|
||||
}
|
||||
|
||||
std::string Shader::log()
|
||||
{
|
||||
std::string infoLog;
|
||||
GLint infoLogLength;
|
||||
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, NULL, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
enum ShaderType {
|
||||
Vertex,
|
||||
Fragment
|
||||
};
|
||||
|
||||
Shader(ShaderType shaderType);
|
||||
~Shader();
|
||||
|
||||
bool compileSourceCode(const std::string& sourceCode);
|
||||
bool compileSourceFile(const std::string& sourceFile);
|
||||
std::string log();
|
||||
|
||||
GLuint getShaderId() { return m_shaderId; }
|
||||
ShaderType getShaderType() { return m_shaderType; }
|
||||
|
||||
private:
|
||||
GLuint m_shaderId;
|
||||
ShaderType m_shaderType;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shaderprogram.h"
|
||||
|
||||
GLuint ShaderProgram::m_currentProgram = 0;
|
||||
|
||||
ShaderProgram::ShaderProgram()
|
||||
{
|
||||
m_linked = false;
|
||||
m_programId = glCreateProgram();
|
||||
m_uniformLocations.fill(-1);
|
||||
if(!m_programId)
|
||||
logFatal("Unable to create GL shader program");
|
||||
}
|
||||
|
||||
ShaderProgram::~ShaderProgram()
|
||||
{
|
||||
glDeleteProgram(m_programId);
|
||||
}
|
||||
|
||||
bool ShaderProgram::addShader(const ShaderPtr& shader) {
|
||||
glAttachShader(m_programId, shader->getShaderId());
|
||||
m_linked = false;
|
||||
m_shaders.push_back(shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode) {
|
||||
ShaderPtr shader(new Shader(shaderType));
|
||||
if(!shader->compileSourceCode(sourceCode)) {
|
||||
logError("failed to compile shader: ", shader->log());
|
||||
return false;
|
||||
}
|
||||
return addShader(shader);
|
||||
}
|
||||
|
||||
bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) {
|
||||
ShaderPtr shader(new Shader(shaderType));
|
||||
if(!shader->compileSourceFile(sourceFile)) {
|
||||
logError("failed to compile shader: ", shader->log());
|
||||
return false;
|
||||
}
|
||||
return addShader(shader);
|
||||
}
|
||||
|
||||
void ShaderProgram::removeShader(const ShaderPtr& shader)
|
||||
{
|
||||
auto it = std::find(m_shaders.begin(), m_shaders.end(), shader);
|
||||
if(it == m_shaders.end())
|
||||
return;
|
||||
|
||||
glDetachShader(m_programId, shader->getShaderId());
|
||||
m_shaders.erase(it);
|
||||
m_linked = false;
|
||||
}
|
||||
|
||||
void ShaderProgram::removeAllShaders()
|
||||
{
|
||||
while(!m_shaders.empty())
|
||||
removeShader(m_shaders.front());
|
||||
}
|
||||
|
||||
bool ShaderProgram::link()
|
||||
{
|
||||
if(m_linked)
|
||||
return true;
|
||||
|
||||
glLinkProgram(m_programId);
|
||||
|
||||
GLint value;
|
||||
glGetProgramiv(m_programId, GL_LINK_STATUS, &value);
|
||||
m_linked = (value != GL_FALSE);
|
||||
|
||||
if(!m_linked)
|
||||
logTraceWarning(log());
|
||||
return m_linked;
|
||||
}
|
||||
|
||||
bool ShaderProgram::bind()
|
||||
{
|
||||
if(m_currentProgram != m_programId) {
|
||||
if(!m_linked && !link())
|
||||
return false;
|
||||
glUseProgram(m_programId);
|
||||
m_currentProgram = m_programId;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShaderProgram::release()
|
||||
{
|
||||
m_currentProgram = 0;
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
std::string ShaderProgram::log()
|
||||
{
|
||||
std::string infoLog;
|
||||
GLint infoLogLength;
|
||||
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_programId, infoLogLength-1, NULL, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
}
|
||||
|
||||
int ShaderProgram::getAttributeLocation(const char* name)
|
||||
{
|
||||
return glGetAttribLocation(m_programId, name);
|
||||
}
|
||||
|
||||
void ShaderProgram::bindAttributeLocation(int location, const char* name)
|
||||
{
|
||||
return glBindAttribLocation(m_programId, location, name);
|
||||
}
|
||||
|
||||
void ShaderProgram::bindUniformLocation(int location, const char* name)
|
||||
{
|
||||
assert(m_linked);
|
||||
assert(location >= 0 && location < 10);
|
||||
m_uniformLocations[location] = glGetUniformLocation(m_programId, name);
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SHADERPROGRAM_H
|
||||
#define SHADERPROGRAM_H
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
class ShaderProgram
|
||||
{
|
||||
enum {
|
||||
MAX_UNIFORM_LOCATIONS = 10
|
||||
};
|
||||
public:
|
||||
ShaderProgram();
|
||||
~ShaderProgram();
|
||||
|
||||
bool addShader(const ShaderPtr& shader);
|
||||
bool addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode);
|
||||
bool addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile);
|
||||
void removeShader(const ShaderPtr& shader);
|
||||
void removeAllShaders();
|
||||
bool link();
|
||||
bool bind();
|
||||
void release();
|
||||
std::string log();
|
||||
|
||||
void disableAttributeArray(int location) { glDisableVertexAttribArray(location); }
|
||||
void enableAttributeArray(int location) { glEnableVertexAttribArray(location); }
|
||||
void disableAttributeArray(const char *name) { glDisableVertexAttribArray(getAttributeLocation(name)); }
|
||||
void enableAttributeArray(const char *name) { glEnableVertexAttribArray(getAttributeLocation(name)); }
|
||||
|
||||
int getAttributeLocation(const char *name);
|
||||
void bindAttributeLocation(int location, const char *name);
|
||||
void bindUniformLocation(int location, const char *name);
|
||||
|
||||
void setAttributeArray(int location, const GLfloat *values, int size, int stride = 0) { glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, stride, values); }
|
||||
void setAttributeValue(int location, GLfloat value) { glVertexAttrib1f(location, value); }
|
||||
void setAttributeValue(int location, GLfloat x, GLfloat y) { glVertexAttrib2f(location, x, y); }
|
||||
void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z) { glVertexAttrib3f(location, x, y, z); }
|
||||
void setAttributeArray(const char *name, const GLfloat *values, int size, int stride = 0) { glVertexAttribPointer(getAttributeLocation(name), size, GL_FLOAT, GL_FALSE, stride, values); }
|
||||
void setAttributeValue(const char *name, GLfloat value) { glVertexAttrib1f(getAttributeLocation(name), value); }
|
||||
void setAttributeValue(const char *name, GLfloat x, GLfloat y) { glVertexAttrib2f(getAttributeLocation(name), x, y); }
|
||||
void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z) { glVertexAttrib3f(getAttributeLocation(name), x, y, z); }
|
||||
|
||||
void setUniformValue(int location, GLint value) { glUniform1i(m_uniformLocations[location], value); }
|
||||
void setUniformValue(int location, GLfloat value) { glUniform1f(m_uniformLocations[location], value); }
|
||||
void setUniformValue(int location, GLfloat x, GLfloat y) { glUniform2f(m_uniformLocations[location], x, y); }
|
||||
void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z) { glUniform3f(m_uniformLocations[location], x, y, z); }
|
||||
void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { glUniform4f(m_uniformLocations[location], x, y, z, w); }
|
||||
void setUniformValue(int location, GLfloat mat2[2][2], bool transpose) { glUniformMatrix2fv(m_uniformLocations[location], 1, transpose ? GL_TRUE : GL_FALSE, (GLfloat *)mat2); }
|
||||
void setUniformValue(int location, GLfloat mat3[3][3], bool transpose) { glUniformMatrix3fv(m_uniformLocations[location], 1, transpose ? GL_TRUE : GL_FALSE, (GLfloat *)mat3); }
|
||||
void setUniformValue(const char *name, GLint value) { glUniform1i(glGetUniformLocation(m_programId, name), value); }
|
||||
void setUniformValue(const char *name, GLfloat value) { glUniform1f(glGetUniformLocation(m_programId, name), value); }
|
||||
void setUniformValue(const char *name, GLfloat x, GLfloat y) { glUniform2f(glGetUniformLocation(m_programId, name), x, y); }
|
||||
void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z) { glUniform3f(glGetUniformLocation(m_programId, name), x, y, z); }
|
||||
void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { glUniform4f(glGetUniformLocation(m_programId, name), x, y, z, w); }
|
||||
void setUniformValue(const char *name, GLfloat mat2[2][2], bool transpose = false) { glUniformMatrix2fv(glGetUniformLocation(m_programId, name), 1, transpose ? GL_TRUE : GL_FALSE, (GLfloat *)mat2); }
|
||||
void setUniformValue(const char *name, GLfloat mat3[3][3], bool transpose = false) { glUniformMatrix3fv(glGetUniformLocation(m_programId, name), 1, transpose ? GL_TRUE : GL_FALSE, (GLfloat *)mat3); }
|
||||
|
||||
// Point, PointF, Color, Size, SizeF,
|
||||
bool isLinked() { return m_linked; }
|
||||
GLuint getProgramId() { return m_programId; }
|
||||
ShaderList getShaders() { return m_shaders; }
|
||||
|
||||
private:
|
||||
bool m_linked;
|
||||
GLuint m_programId;
|
||||
static GLuint m_currentProgram;
|
||||
ShaderList m_shaders;
|
||||
std::array<GLint, MAX_UNIFORM_LOCATIONS> m_uniformLocations;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in new issue