* option to pass -opengl1 or -opengl2 as argument * note that with this commit there are a lot of graphics regressions and the master will remaing unstable for a while * shaders disabled for a whilemaster
parent
a4a00a49fe
commit
58d76e255d
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "painterogl1.h"
|
||||
#include "graphics.h"
|
||||
|
||||
PainterOGL1 *g_painterOGL1 = nullptr;
|
||||
|
||||
PainterOGL1::PainterOGL1()
|
||||
{
|
||||
m_matrixMode = GL_PROJECTION;
|
||||
resetState();
|
||||
}
|
||||
|
||||
void PainterOGL1::refreshState()
|
||||
{
|
||||
Painter::refreshState();
|
||||
updateGlColor();
|
||||
updateGlMatrixMode();
|
||||
updateGlProjectionMatrix();
|
||||
updateGlTextureMatrix();
|
||||
}
|
||||
|
||||
void PainterOGL1::bind()
|
||||
{
|
||||
Painter::bind();
|
||||
|
||||
// vertex and texture coord arrays are always enabled
|
||||
// to avoid massive enable/disables, thus improving frame rate
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void PainterOGL1::unbind()
|
||||
{
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
{
|
||||
int vertexCount = coordsBuffer.getVertexCount();
|
||||
if(vertexCount == 0)
|
||||
return;
|
||||
|
||||
bool textured = coordsBuffer.getTextureCoordCount() != 0;
|
||||
if(textured)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// use vertex arrays if possible, much faster
|
||||
if(g_graphics.canUseDrawArrays()) {
|
||||
// update coords buffer hardware caches if enabled
|
||||
coordsBuffer.updateCaches();
|
||||
bool hardwareCached = coordsBuffer.isHardwareCached();
|
||||
|
||||
// only set texture coords arrays when needed
|
||||
if(textured) {
|
||||
if(hardwareCached) {
|
||||
coordsBuffer.getHardwareTextureCoordArray()->bind();
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
|
||||
} else
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, coordsBuffer.getTextureCoordArray());
|
||||
}
|
||||
|
||||
// set vertex array
|
||||
if(hardwareCached) {
|
||||
coordsBuffer.getHardwareVertexArray()->bind();
|
||||
glVertexPointer(2, GL_FLOAT, 0, nullptr);
|
||||
} else
|
||||
glVertexPointer(2, GL_FLOAT, 0, coordsBuffer.getVertexArray());
|
||||
|
||||
if(hardwareCached)
|
||||
HardwareBuffer::unbind(HardwareBuffer::VertexBuffer);
|
||||
|
||||
// draw the element in coords buffers
|
||||
glDrawArrays(drawMode, 0, vertexCount);
|
||||
} else {
|
||||
int verticesSize = vertexCount*2;
|
||||
float *vertices = coordsBuffer.getVertexArray();
|
||||
float *texCoords = coordsBuffer.getTextureCoordArray();
|
||||
|
||||
// use glBegin/glEnd, this is not available in OpenGL ES
|
||||
// and is considered much slower then glDrawArrays,
|
||||
// but this code is executed in really old graphics cards
|
||||
glBegin(drawMode);
|
||||
for(int i=0;i<verticesSize;i+=2) {
|
||||
if(textured)
|
||||
glTexCoord2f(texCoords[i], texCoords[i+1]);
|
||||
glVertex2f(vertices[i], vertices[i+1]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void PainterOGL1::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(!texture->getId())
|
||||
return;
|
||||
|
||||
setTexture(texture.get());
|
||||
drawCoords(coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addQuad(dest, src);
|
||||
|
||||
setTexture(texture.get());
|
||||
drawCoords(m_coordsBuffer, TriangleStrip);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addRepeatedRects(dest, src);
|
||||
|
||||
setTexture(texture.get());
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawFilledRect(const Rect& dest)
|
||||
{
|
||||
if(dest.isEmpty())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addRect(dest);
|
||||
|
||||
setTexture(nullptr);
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||
{
|
||||
if(dest.isEmpty() || innerLineWidth == 0)
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
|
||||
|
||||
setTexture(nullptr);
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL1::setMatrixMode(PainterOGL1::MatrixMode matrixMode)
|
||||
{
|
||||
if(m_matrixMode == matrixMode)
|
||||
return;
|
||||
m_matrixMode = matrixMode;
|
||||
updateGlMatrixMode();
|
||||
}
|
||||
|
||||
void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix)
|
||||
{
|
||||
m_projectionMatrix = projectionMatrix;
|
||||
updateGlProjectionMatrix();
|
||||
}
|
||||
|
||||
void PainterOGL1::setTextureMatrix(const Matrix2& textureMatrix)
|
||||
{
|
||||
m_textureMatrix = textureMatrix;
|
||||
updateGlTextureMatrix();
|
||||
}
|
||||
|
||||
void PainterOGL1::setColor(const Color& color)
|
||||
{
|
||||
if(m_color == color)
|
||||
return;
|
||||
m_color = color;
|
||||
updateGlColor();
|
||||
}
|
||||
|
||||
void PainterOGL1::setOpacity(float opacity)
|
||||
{
|
||||
if(m_opacity == opacity)
|
||||
return;
|
||||
m_opacity = opacity;
|
||||
updateGlColor();
|
||||
}
|
||||
|
||||
void PainterOGL1::updateGlColor()
|
||||
{
|
||||
glColor4f(m_color.rF(), m_color.gF(), m_color.bF(), m_color.aF() * m_opacity);
|
||||
}
|
||||
|
||||
void PainterOGL1::updateGlMatrixMode()
|
||||
{
|
||||
glMatrixMode(m_matrixMode);
|
||||
}
|
||||
|
||||
void PainterOGL1::updateGlProjectionMatrix()
|
||||
{
|
||||
float glProjectionMatrix[] = {
|
||||
m_projectionMatrix(1,1), m_projectionMatrix(1,2), 0.0f, m_projectionMatrix(1,3),
|
||||
m_projectionMatrix(2,1), m_projectionMatrix(2,2), 0.0f, m_projectionMatrix(2,3),
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
m_projectionMatrix(3,1), m_projectionMatrix(3,2), 0.0f, m_projectionMatrix(3,3),
|
||||
};
|
||||
|
||||
setMatrixMode(MatrixProjection);
|
||||
glLoadMatrixf(glProjectionMatrix);
|
||||
}
|
||||
|
||||
void PainterOGL1::updateGlTextureMatrix()
|
||||
{
|
||||
float glTextureMatrix[] = {
|
||||
m_textureMatrix(1,1), m_textureMatrix(1,2), 0.0f, 0.0f,
|
||||
m_textureMatrix(2,1), m_textureMatrix(2,2), 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
setMatrixMode(MatrixTexture);
|
||||
glLoadMatrixf(glTextureMatrix);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 PAINTEROGL1_H
|
||||
#define PAINTEROGL1_H
|
||||
|
||||
#include "painter.h"
|
||||
|
||||
/**
|
||||
* Painter using OpenGL 1.0 fixed-function rendering pipeline,
|
||||
* compatible with OpenGL ES 1.0 and intended to be used on
|
||||
* older graphics cards. Shaders are not available
|
||||
* for this painter engine.
|
||||
*/
|
||||
class PainterOGL1 : public Painter
|
||||
{
|
||||
public:
|
||||
enum MatrixMode {
|
||||
MatrixProjection = GL_PROJECTION,
|
||||
MatrixTexture = GL_TEXTURE
|
||||
};
|
||||
|
||||
PainterOGL1();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
void refreshState();
|
||||
|
||||
void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles);
|
||||
void drawTextureCoords(CoordsBuffer& coordsBuffer, 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);
|
||||
|
||||
void setMatrixMode(MatrixMode matrixMode);
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||
void setTextureMatrix(const Matrix2& textureMatrix);
|
||||
void setColor(const Color& color);
|
||||
void setOpacity(float opacity);
|
||||
|
||||
private:
|
||||
void updateGlColor();
|
||||
void updateGlMatrixMode();
|
||||
void updateGlProjectionMatrix();
|
||||
void updateGlTextureMatrix();
|
||||
|
||||
GLenum m_matrixMode;
|
||||
};
|
||||
|
||||
extern PainterOGL1 *g_painterOGL1;
|
||||
|
||||
#endif
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "painterogl2.h"
|
||||
#include "texture.h"
|
||||
#include "paintershadermanager.h"
|
||||
|
||||
PainterOGL2 *g_painterOGL2 = nullptr;
|
||||
|
||||
PainterOGL2::PainterOGL2()
|
||||
{
|
||||
m_drawProgram = nullptr;
|
||||
resetState();
|
||||
|
||||
g_shaders.init();
|
||||
}
|
||||
|
||||
PainterOGL2::~PainterOGL2()
|
||||
{
|
||||
g_shaders.terminate();
|
||||
}
|
||||
|
||||
void PainterOGL2::bind()
|
||||
{
|
||||
Painter::bind();
|
||||
|
||||
// vertex and texture coord attributes are always enabled
|
||||
// to avoid massive enable/disables, thus improving frame rate
|
||||
PainterShaderProgram::enableAttributeArray(PainterShaderProgram::VERTEX_ATTR);
|
||||
PainterShaderProgram::enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
||||
}
|
||||
|
||||
void PainterOGL2::unbind()
|
||||
{
|
||||
PainterShaderProgram::disableAttributeArray(PainterShaderProgram::VERTEX_ATTR);
|
||||
PainterShaderProgram::disableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
||||
PainterShaderProgram::release();
|
||||
}
|
||||
|
||||
void PainterOGL2::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
{
|
||||
int vertexCount = coordsBuffer.getVertexCount();
|
||||
if(vertexCount == 0)
|
||||
return;
|
||||
|
||||
bool textured = coordsBuffer.getTextureCoordCount() > 0;
|
||||
|
||||
// update shader with the current painter state
|
||||
m_drawProgram->bind();
|
||||
m_drawProgram->setProjectionMatrix(m_projectionMatrix);
|
||||
if(textured)
|
||||
m_drawProgram->setTextureMatrix(m_textureMatrix);
|
||||
m_drawProgram->setOpacity(m_opacity);
|
||||
m_drawProgram->setColor(m_color);
|
||||
m_drawProgram->updateTime();
|
||||
|
||||
// update coords buffer hardware caches if enabled
|
||||
coordsBuffer.updateCaches();
|
||||
bool hardwareCached = coordsBuffer.isHardwareCached();
|
||||
|
||||
// only set texture coords arrays when needed
|
||||
if(textured) {
|
||||
if(hardwareCached) {
|
||||
coordsBuffer.getHardwareTextureCoordArray()->bind();
|
||||
m_drawProgram->setAttributeArray(PainterShaderProgram::TEXCOORD_ATTR, nullptr, 2);
|
||||
} else
|
||||
m_drawProgram->setAttributeArray(PainterShaderProgram::TEXCOORD_ATTR, coordsBuffer.getTextureCoordArray(), 2);
|
||||
}
|
||||
|
||||
// set vertex array
|
||||
if(hardwareCached) {
|
||||
coordsBuffer.getHardwareVertexArray()->bind();
|
||||
m_drawProgram->setAttributeArray(PainterShaderProgram::VERTEX_ATTR, nullptr, 2);
|
||||
HardwareBuffer::unbind(HardwareBuffer::VertexBuffer);
|
||||
} else
|
||||
m_drawProgram->setAttributeArray(PainterShaderProgram::VERTEX_ATTR, coordsBuffer.getVertexArray(), 2);
|
||||
|
||||
// draw the element in coords buffers
|
||||
glDrawArrays(drawMode, 0, vertexCount);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(!texture->getId())
|
||||
return;
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
setTexture(texture);
|
||||
drawCoords(coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addQuad(dest, src);
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
setTexture(texture);
|
||||
drawCoords(m_coordsBuffer, TriangleStrip);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addRepeatedRects(dest, src);
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
setTexture(texture);
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawFilledRect(const Rect& dest)
|
||||
{
|
||||
if(dest.isEmpty())
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addRect(dest);
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawSolidColorProgram().get());
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||
{
|
||||
if(dest.isEmpty() || innerLineWidth == 0)
|
||||
return;
|
||||
|
||||
m_coordsBuffer.clear();
|
||||
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawSolidColorProgram().get());
|
||||
drawCoords(m_coordsBuffer);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 PAINTEROGL2_H
|
||||
#define PAINTEROGL2_H
|
||||
|
||||
#include "painter.h"
|
||||
|
||||
/**
|
||||
* Painter using OpenGL 2.0 programmable rendering pipeline,
|
||||
* compatible with OpenGL ES 2.0. Only recent cards support
|
||||
* this painter engine.
|
||||
*/
|
||||
class PainterOGL2 : public Painter
|
||||
{
|
||||
public:
|
||||
PainterOGL2();
|
||||
~PainterOGL2();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles);
|
||||
void drawTextureCoords(CoordsBuffer& coordsBuffer, 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 setDrawProgram(PainterShaderProgram *drawProgram) { m_drawProgram = drawProgram; }
|
||||
|
||||
private:
|
||||
PainterShaderProgram *m_drawProgram;
|
||||
};
|
||||
|
||||
extern PainterOGL2 *g_painterOGL2;
|
||||
|
||||
#endif
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 const std::string glslMainVertexShader = "\n\
|
||||
highp vec4 calculatePosition();\n\
|
||||
void main() {\n\
|
||||
gl_Position = calculatePosition();\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslMainWithTexCoordsVertexShader = "\n\
|
||||
attribute highp vec2 a_texCoord;\n\
|
||||
uniform highp mat2 textureMatrix;\n\
|
||||
varying highp vec2 texCoord;\n\
|
||||
highp vec4 calculatePosition();\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
gl_Position = calculatePosition();\n\
|
||||
texCoord = textureMatrix * a_texCoord;\n\
|
||||
}\n";
|
||||
|
||||
static std::string glslPositionOnlyVertexShader = "\n\
|
||||
attribute highp vec2 a_vertex;\n\
|
||||
uniform highp mat3 projectionMatrix;\n\
|
||||
highp vec4 calculatePosition() {\n\
|
||||
return vec4(projectionMatrix * vec3(a_vertex.xy, 1), 1);\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslMainFragmentShader = "\n\
|
||||
uniform lowp float opacity;\n\
|
||||
lowp vec4 calculatePixel();\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
gl_FragColor = calculatePixel();\n\
|
||||
gl_FragColor.a *= opacity;\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslTextureSrcFragmentShader = "\n\
|
||||
varying mediump vec2 texCoord;\n\
|
||||
uniform lowp vec4 color;\n\
|
||||
uniform sampler2D tex0;\n\
|
||||
lowp vec4 calculatePixel() {\n\
|
||||
return texture2D(tex0, texCoord) * color;\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslSolidColorFragmentShader = "\n\
|
||||
uniform lowp vec4 color;\n\
|
||||
lowp vec4 calculatePixel() {\n\
|
||||
return color;\n\
|
||||
}\n";
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "paintershadermanager.h"
|
||||
#include "painterogl2.h"
|
||||
#include "texture.h"
|
||||
#include "painterogl2_shadersources.h"
|
||||
#include "paintershaderprogram.h"
|
||||
#include "shaderprogram.h"
|
||||
#include "graphics.h"
|
||||
|
||||
PainterShaderManager g_shaders;
|
||||
|
||||
void PainterShaderManager::init()
|
||||
{
|
||||
m_drawTexturedProgram = createShader();
|
||||
assert(m_drawTexturedProgram);
|
||||
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader);
|
||||
m_drawTexturedProgram->link();
|
||||
|
||||
m_drawSolidColorProgram = createShader();
|
||||
assert(m_drawSolidColorProgram);
|
||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
||||
m_drawSolidColorProgram->link();
|
||||
}
|
||||
|
||||
void PainterShaderManager::terminate()
|
||||
{
|
||||
m_drawTexturedProgram = nullptr;
|
||||
m_drawSolidColorProgram = nullptr;
|
||||
}
|
||||
|
||||
PainterShaderProgramPtr PainterShaderManager::createShader()
|
||||
{
|
||||
if(!g_graphics.canUseShaders())
|
||||
return nullptr;
|
||||
return PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
}
|
||||
|
||||
PainterShaderProgramPtr PainterShaderManager::createTexturedFragmentShader(const std::string& shaderFile)
|
||||
{
|
||||
PainterShaderProgramPtr shader = createShader();
|
||||
if(!shader)
|
||||
return nullptr;
|
||||
|
||||
shader->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||
shader->addShaderFromSourceFile(Shader::Fragment, shaderFile);
|
||||
|
||||
if(!shader->link())
|
||||
return nullptr;
|
||||
|
||||
return shader;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 PAINTERSHADERMANAGER_H
|
||||
#define PAINTERSHADERMANAGER_H
|
||||
|
||||
#include "paintershaderprogram.h"
|
||||
|
||||
class PainterShaderManager
|
||||
{
|
||||
public:
|
||||
void init();
|
||||
void terminate();
|
||||
|
||||
PainterShaderProgramPtr createShader();
|
||||
PainterShaderProgramPtr createTexturedFragmentShader(const std::string& shaderFile);
|
||||
|
||||
const PainterShaderProgramPtr& getDrawTexturedProgram() { return m_drawTexturedProgram; }
|
||||
const PainterShaderProgramPtr& getDrawSolidColorProgram() { return m_drawSolidColorProgram; }
|
||||
|
||||
private:
|
||||
PainterShaderProgramPtr m_drawTexturedProgram;
|
||||
PainterShaderProgramPtr m_drawSolidColorProgram;
|
||||
};
|
||||
|
||||
extern PainterShaderManager g_shaders;
|
||||
|
||||
#endif
|
Loading…
Reference in new issue