Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GLVideoDriver: Another method to drawing lines, implementing DrawLine…

…, removed 'transpose' param from GLSLProgram::SetUniformMatrixValue

 (always GL_FALSE in GLES)
  • Loading branch information...
commit d1e5a0efe92dc2632bfb595ce69e0ae06c0128a3 1 parent ea789a0
@BehoIder BehoIder authored lynxlynxlynx committed
View
8 gemrb/plugins/SDLVideo/GLSLProgram.cpp
@@ -232,20 +232,20 @@ bool GLSLProgram::SetUniformValue(std::string uniformName, const unsigned char s
}
}
-bool GLSLProgram::SetUniformMatrixValue(std::string uniformName, const unsigned char size, GLsizei count, GLboolean transpose, const GLfloat* value)
+bool GLSLProgram::SetUniformMatrixValue(std::string uniformName, const unsigned char size, GLsizei count, const GLfloat* value)
{
GLint location = getUniformLocation(uniformName);
if (location == -1) return false;
switch(size)
{
case 2:
- glUniformMatrix2fv(location, count, transpose, value);
+ glUniformMatrix2fv(location, count, GL_FALSE, value);
return true;
case 3:
- glUniformMatrix3fv(location, count, transpose, value);
+ glUniformMatrix3fv(location, count, GL_FALSE, value);
return true;
case 4:
- glUniformMatrix4fv(location, count, transpose, value);
+ glUniformMatrix4fv(location, count, GL_FALSE, value);
return true;
default:
GLSLProgram::errMessage = "GLSLProgram error: Invalid uniform size";
View
2  gemrb/plugins/SDLVideo/GLSLProgram.h
@@ -27,7 +27,7 @@ namespace GemRB
bool SetUniformValue(std::string uniformName, const unsigned char size, GLint value1, GLint value2 = 0, GLint value3 = 0, GLint value4 = 0);
bool SetUniformValue(std::string uniformName, const unsigned char size, GLsizei count, const GLfloat* value);
bool SetUniformValue(std::string uniformName, const unsigned char size, GLsizei count, const GLint* value);
- bool SetUniformMatrixValue(std::string uniformName, const unsigned char size, GLsizei count, GLboolean transpose, const GLfloat* value);
+ bool SetUniformMatrixValue(std::string uniformName, const unsigned char size, GLsizei count, const GLfloat* value);
GLint GetAttribLocation(std::string attribName);
private:
static std::string errMessage;
View
78 gemrb/plugins/SDLVideo/SDL20GLVideo.cpp
@@ -156,7 +156,7 @@ bool GLVideoDriver::createPrograms()
}
program32->Use();
program32->SetUniformValue("s_texture", 1, 0);
- program32->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ program32->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
programPal = GLSLProgram::CreateFromFiles("Shaders/Sprite.glslv", "Shaders/SpritePal.glslf");
if (!programPal)
@@ -169,7 +169,7 @@ bool GLVideoDriver::createPrograms()
programPal->SetUniformValue("s_texture", 1, 0);
programPal->SetUniformValue("s_palette", 1, 1);
programPal->SetUniformValue("s_mask", 1, 2);
- programPal->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ programPal->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
programPalGrayed = GLSLProgram::CreateFromFiles("Shaders/Sprite.glslv", "Shaders/SpritePalGrayed.glslf");
if (!programPalGrayed)
@@ -182,7 +182,7 @@ bool GLVideoDriver::createPrograms()
programPal->SetUniformValue("s_texture", 1, 0);
programPal->SetUniformValue("s_palette", 1, 1);
programPal->SetUniformValue("s_mask", 1, 2);
- programPalGrayed->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ programPalGrayed->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
programPalSepia = GLSLProgram::CreateFromFiles("Shaders/Sprite.glslv", "Shaders/SpritePalSepia.glslf");
if (!programPalSepia)
@@ -195,7 +195,7 @@ bool GLVideoDriver::createPrograms()
programPal->SetUniformValue("s_texture", 1, 0);
programPal->SetUniformValue("s_palette", 1, 1);
programPal->SetUniformValue("s_mask", 1, 2);;
- programPalSepia->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ programPalSepia->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
programEllipse = GLSLProgram::CreateFromFiles("Shaders/Ellipse.glslv", "Shaders/Ellipse.glslf");
if (!programEllipse)
@@ -205,7 +205,7 @@ bool GLVideoDriver::createPrograms()
return false;
}
programEllipse->Use();
- programEllipse->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ programEllipse->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
programRect = GLSLProgram::CreateFromFiles("Shaders/Rect.glslv", "Shaders/Rect.glslf");
if (!programRect)
@@ -215,7 +215,7 @@ bool GLVideoDriver::createPrograms()
return false;
}
programRect->Use();
- programRect->SetUniformMatrixValue("u_matrix", 4, 1, GL_FALSE, matrix);
+ programRect->SetUniformMatrixValue("u_matrix", 4, 1, matrix);
lastUsedProgram = NULL;
return true;
@@ -428,6 +428,33 @@ void GLVideoDriver::drawColoredRect(const Region& rgn, const Color& color)
}
}
+void GLVideoDriver::drawLine(short x1, short y1, short x2, short y2, const Color& color)
+{
+ if (SDL_ALPHA_TRANSPARENT == color.a) return;
+ useProgram(programRect);
+ glViewport(0, 0, width, height);
+ glScissor(0, 0, width, height);
+ GLfloat data[] =
+ {
+ -1.0f + (GLfloat)x1*2/width, 1.0f - (GLfloat)y1*2/height,
+ -1.0f + (GLfloat)x2*2/width, 1.0f - (GLfloat)y2*2/height
+ };
+ GLuint buffer;
+ glGenBuffers(1, &buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
+
+ GLint a_position = programRect->GetAttribLocation("a_position");
+ glVertexAttribPointer(a_position, VERTEX_SIZE, GL_FLOAT, GL_FALSE, 0, 0);
+ programRect->SetUniformValue("u_color", 4, (GLfloat)color.r/255, (GLfloat)color.g/255, (GLfloat)color.b/255, (GLfloat)color.a/255);
+
+ glEnableVertexAttribArray(a_position);
+ glDrawArrays(GL_LINES, 0, 2);
+ glDisableVertexAttribArray(a_position);
+
+ glDeleteBuffers(1, &buffer);
+}
+
void GLVideoDriver::drawEllipse(int cx /*center*/, int cy /*center*/, unsigned short xr, unsigned short yr, float thickness, const Color& color)
{
const float support = 0.75;
@@ -591,46 +618,36 @@ void GLVideoDriver::DrawRect(const Region& rgn, const Color& color, bool fill, b
void GLVideoDriver::DrawHLine(short x1, short y, short x2, const Color& color, bool clipped)
{
- if (x1 > x2)
- {
- short tmpx = x1;
- x1 = x2;
- x2 = tmpx;
- }
if (clipped)
{
x1 = x1 + xCorr - Viewport.x;
x2 = x2 + xCorr - Viewport.x;
y = y + yCorr - Viewport.y;
}
- Region rgn;
- rgn.x = x1;
- rgn.y = y;
- rgn.h = 1;
- rgn.w = x2 - x1;
- return drawColoredRect(rgn, color);
+ return drawLine(x1, y, x2, y, color);
}
void GLVideoDriver::DrawVLine(short x, short y1, short y2, const Color& color, bool clipped)
{
- if (y1 > y2)
+ if (clipped)
{
- short tmpy = y1;
- y1 = y2;
- y2 = tmpy;
+ x = x + xCorr - Viewport.x;
+ y1 = y1 + yCorr - Viewport.y;
+ y2 = y2 + yCorr - Viewport.y;
}
+ return drawLine(x, y1, x, y2, color);
+}
+
+void GLVideoDriver::DrawLine(short x1, short y1, short x2, short y2, const Color& color, bool clipped)
+{
if (clipped)
{
- x = x + xCorr - Viewport.x;
+ x1 = x1 + xCorr - Viewport.x;
+ x2 = x2 + xCorr - Viewport.x;
y1 = y1 + yCorr - Viewport.y;
y2 = y2 + yCorr - Viewport.y;
}
- Region rgn;
- rgn.x = x;
- rgn.y = y1;
- rgn.w = 1;
- rgn.h = y2 - y1;
- return drawColoredRect(rgn, color);
+ return drawLine(x1, y1, x2, y2, color);
}
void GLVideoDriver::DrawEllipse(short cx, short cy, unsigned short xr, unsigned short yr, const Color& color, bool clipped)
@@ -650,6 +667,9 @@ void GLVideoDriver::DrawEllipse(short cx, short cy, unsigned short xr, unsigned
return drawEllipse(cx, cy, xr, yr, 3, color);
}
+void GLVideoDriver::DrawEllipseSegment(short cx, short cy, unsigned short xr, unsigned short yr, const Color& color, double anglefrom, double angleto, bool drawlines, bool clipped)
+{}
+
void GLVideoDriver::DrawCircle(short cx, short cy, unsigned short r, const Color& color, bool clipped)
{
return DrawEllipse(cx, cy, r, r, color, clipped);
View
5 gemrb/plugins/SDLVideo/SDL20GLVideo.h
@@ -34,11 +34,12 @@ namespace GemRB
GLPaletteManager* paletteManager; // palette manager instance
- void useProgram(GLSLProgram* program); // use this instead glUseProgram
+ void useProgram(GLSLProgram* program); // use this instead program->Use()
bool createPrograms();
void blitSprite(GLTextureSprite2D* spr, int x, int y, const Region* clip, Palette* attachedPal = NULL, unsigned int flags = 0, const Color* tint = NULL, GLTextureSprite2D* mask = NULL);
void drawColoredRect(const Region& rgn, const Color& color);
void drawEllipse(int cx, int cy, unsigned short xr, unsigned short yr, float thickness, const Color& color);
+ void drawLine(short x1, short y1, short x2, short y2, const Color& color);
public:
~GLVideoDriver();
@@ -54,8 +55,10 @@ namespace GemRB
void DrawRect(const Region& rgn, const Color& color, bool fill = true, bool clipped = false);
void DrawHLine(short x1, short y, short x2, const Color& color, bool clipped = false);
void DrawVLine(short x, short y1, short y2, const Color& color, bool clipped = false);
+ void DrawLine(short x1, short y1, short x2, short y2, const Color& color, bool clipped = false);
void DrawEllipse(short cx, short cy, unsigned short xr, unsigned short yr, const Color& color, bool clipped = true);
void DrawCircle(short cx, short cy, unsigned short r, const Color& color, bool clipped = true);
+ void DrawEllipseSegment(short cx, short cy, unsigned short xr, unsigned short yr, const Color& color, double anglefrom, double angleto, bool drawlines = true, bool clipped = true);
void DestroyMovieScreen();
Sprite2D* GetScreenshot(Region r);
};
View
2  gemrb/plugins/SDLVideo/SDLVideo.h
@@ -117,7 +117,7 @@ class SDLVideoDriver : public Video {
void DrawPolyline(Gem_Polygon* poly, const Color& color, bool fill = false);
virtual void DrawHLine(short x1, short y, short x2, const Color& color, bool clipped = false);
virtual void DrawVLine(short x, short y1, short y2, const Color& color, bool clipped = false);
- void DrawLine(short x1, short y1, short x2, short y2, const Color& color, bool clipped = false);
+ virtual void DrawLine(short x1, short y1, short x2, short y2, const Color& color, bool clipped = false);
/** Blits a Sprite filling the Region */
void BlitTiled(Region rgn, const Sprite2D* img, bool anchor = false);
Please sign in to comment.
Something went wrong with that request. Please try again.