2014-01-13 23:42:06 +00:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-04-05 16:18:42 +00:00
|
|
|
*
|
2014-01-13 23:42:06 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-05 16:18:42 +00:00
|
|
|
*
|
2014-01-13 23:42:06 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-06-10 17:05:47 +00:00
|
|
|
// Matrix calculations taken from the glm library
|
|
|
|
// Which is covered by the MIT license
|
|
|
|
// And has this additional copyright note:
|
|
|
|
/* Copyright (c) 2005 - 2012 G-Truc Creation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-01-13 23:42:06 +00:00
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/textconsole.h"
|
|
|
|
|
|
|
|
#if defined(USE_GLES2) || defined(USE_OPENGL_SHADERS)
|
|
|
|
|
|
|
|
#include "graphics/colormasks.h"
|
|
|
|
#include "graphics/surface.h"
|
|
|
|
|
2012-12-26 10:43:52 +00:00
|
|
|
#include "math/glmath.h"
|
2014-01-13 23:42:06 +00:00
|
|
|
#include "math/vector2d.h"
|
|
|
|
#include "math/rect2d.h"
|
|
|
|
#include "math/quat.h"
|
|
|
|
|
2016-01-04 21:23:01 +00:00
|
|
|
#include "graphics/opengl/shader.h"
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
#include "engines/myst3/gfx.h"
|
|
|
|
#include "engines/myst3/gfx_opengl_texture.h"
|
|
|
|
#include "engines/myst3/gfx_opengl_shaders.h"
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
namespace Myst3 {
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-06-22 19:46:50 +00:00
|
|
|
Renderer *CreateGfxOpenGLShader(OSystem *system) {
|
|
|
|
return new ShaderRenderer(system);
|
|
|
|
}
|
2014-07-06 10:14:27 +00:00
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
static const GLfloat boxVertices[] = {
|
2014-07-03 18:18:21 +00:00
|
|
|
// XS YT
|
|
|
|
0.0, 0.0,
|
|
|
|
1.0, 0.0,
|
|
|
|
0.0, 1.0,
|
|
|
|
1.0, 1.0,
|
2014-01-13 23:42:06 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::setupQuadEBO() {
|
2015-03-22 13:25:38 +00:00
|
|
|
unsigned short quadIndices[6 * 100];
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
unsigned short start = 0;
|
2015-03-22 13:25:38 +00:00
|
|
|
for (unsigned short *p = quadIndices; p < &quadIndices[6 * 100]; p += 6) {
|
2014-07-03 18:18:21 +00:00
|
|
|
p[0] = p[3] = start++;
|
|
|
|
p[1] = start++;
|
|
|
|
p[2] = p[4] = start++;
|
|
|
|
p[5] = start++;
|
|
|
|
}
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2020-09-28 16:37:37 +00:00
|
|
|
_quadEBO = OpenGL::ShaderGL::createBuffer(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadIndices), quadIndices, GL_STATIC_DRAW);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 10:43:52 +00:00
|
|
|
Math::Vector2d ShaderRenderer::scaled(float x, float y) const {
|
2015-05-02 06:42:01 +00:00
|
|
|
return Math::Vector2d(x / _currentViewport.width(), y / _currentViewport.height());
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
ShaderRenderer::ShaderRenderer(OSystem *system) :
|
2015-04-18 15:21:36 +00:00
|
|
|
Renderer(system),
|
2014-07-03 18:18:21 +00:00
|
|
|
_prevText(""),
|
|
|
|
_prevTextPosition(0,0),
|
2015-05-02 06:42:01 +00:00
|
|
|
_currentViewport(kOriginalWidth, kOriginalHeight),
|
2015-03-22 13:25:38 +00:00
|
|
|
_boxShader(nullptr),
|
|
|
|
_cubeShader(nullptr),
|
|
|
|
_rect3dShader(nullptr),
|
|
|
|
_textShader(nullptr),
|
2014-07-06 08:31:07 +00:00
|
|
|
_boxVBO(0),
|
|
|
|
_cubeVBO(0),
|
|
|
|
_rect3dVBO(0),
|
|
|
|
_textVBO(0),
|
|
|
|
_quadEBO(0) {
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
ShaderRenderer::~ShaderRenderer() {
|
2020-09-28 16:37:37 +00:00
|
|
|
OpenGL::ShaderGL::freeBuffer(_boxVBO);
|
|
|
|
OpenGL::ShaderGL::freeBuffer(_cubeVBO);
|
|
|
|
OpenGL::ShaderGL::freeBuffer(_rect3dVBO);
|
|
|
|
OpenGL::ShaderGL::freeBuffer(_textVBO);
|
|
|
|
OpenGL::ShaderGL::freeBuffer(_quadEBO);
|
2014-07-06 08:31:07 +00:00
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
delete _boxShader;
|
|
|
|
delete _cubeShader;
|
|
|
|
delete _rect3dShader;
|
|
|
|
delete _textShader;
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
Texture *ShaderRenderer::createTexture(const Graphics::Surface *surface) {
|
2016-01-09 07:22:26 +00:00
|
|
|
return new OpenGLTexture(surface);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::freeTexture(Texture *texture) {
|
2014-07-03 18:18:21 +00:00
|
|
|
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
|
|
|
delete glTexture;
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 10:43:52 +00:00
|
|
|
void ShaderRenderer::init() {
|
2014-07-06 10:14:27 +00:00
|
|
|
debug("Initializing OpenGL Renderer with shaders");
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2012-12-26 10:43:52 +00:00
|
|
|
computeScreenViewport();
|
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-06 08:31:07 +00:00
|
|
|
static const char* attributes[] = { "position", "texcoord", NULL };
|
2020-09-28 16:37:37 +00:00
|
|
|
_boxShader = OpenGL::ShaderGL::fromFiles("myst3_box", attributes);
|
|
|
|
_boxVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(boxVertices), boxVertices);
|
2015-03-22 13:25:38 +00:00
|
|
|
_boxShader->enableVertexAttribute("position", _boxVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
|
|
|
_boxShader->enableVertexAttribute("texcoord", _boxVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2020-09-28 16:37:37 +00:00
|
|
|
_cubeShader = OpenGL::ShaderGL::fromFiles("myst3_cube", attributes);
|
|
|
|
_cubeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices);
|
2015-03-22 13:25:38 +00:00
|
|
|
_cubeShader->enableVertexAttribute("texcoord", _cubeVBO, 2, GL_FLOAT, GL_TRUE, 5 * sizeof(float), 0);
|
|
|
|
_cubeShader->enableVertexAttribute("position", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 2 * sizeof(float));
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2020-09-28 16:37:37 +00:00
|
|
|
_rect3dShader = OpenGL::ShaderGL::fromFiles("myst3_cube", attributes);
|
|
|
|
_rect3dVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, 20 * sizeof(float), NULL);
|
2015-03-22 13:25:38 +00:00
|
|
|
_rect3dShader->enableVertexAttribute("texcoord", _rect3dVBO, 2, GL_FLOAT, GL_TRUE, 5 * sizeof(float), 0);
|
|
|
|
_rect3dShader->enableVertexAttribute("position", _rect3dVBO, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 2 * sizeof(float));
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2020-09-28 16:37:37 +00:00
|
|
|
_textShader = OpenGL::ShaderGL::fromFiles("myst3_text", attributes);
|
|
|
|
_textVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, 100 * 16 * sizeof(float), NULL, GL_DYNAMIC_DRAW);
|
2015-03-22 13:25:38 +00:00
|
|
|
_textShader->enableVertexAttribute("texcoord", _textVBO, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(float), 0);
|
|
|
|
_textShader->enableVertexAttribute("position", _textVBO, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(float), 2 * sizeof(float));
|
2014-02-07 22:15:23 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
setupQuadEBO();
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::clear() {
|
2017-10-01 13:19:08 +00:00
|
|
|
glClearColor(0.f, 0.f, 0.f, 1.f); // Solid black
|
2014-07-03 18:18:21 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 06:42:01 +00:00
|
|
|
void ShaderRenderer::selectTargetWindow(Window *window, bool is3D, bool scaled) {
|
|
|
|
if (!window) {
|
|
|
|
// No window found ...
|
|
|
|
if (scaled) {
|
|
|
|
// ... in scaled mode draw in the original game screen area
|
|
|
|
Common::Rect vp = viewport();
|
|
|
|
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
|
|
|
|
_currentViewport = Common::Rect(kOriginalWidth, kOriginalHeight);
|
|
|
|
} else {
|
|
|
|
// ... otherwise, draw on the whole screen
|
|
|
|
glViewport(0, 0, _system->getWidth(), _system->getHeight());
|
|
|
|
_currentViewport = Common::Rect(_system->getWidth(), _system->getHeight());
|
|
|
|
}
|
2012-12-26 10:43:52 +00:00
|
|
|
} else {
|
2015-05-02 06:42:01 +00:00
|
|
|
// Found a window, draw inside it
|
|
|
|
Common::Rect vp = window->getPosition();
|
|
|
|
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-05-02 06:42:01 +00:00
|
|
|
if (scaled) {
|
|
|
|
_currentViewport = window->getOriginalPosition();
|
|
|
|
} else {
|
|
|
|
_currentViewport = vp;
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::drawRect2D(const Common::Rect &rect, uint32 color) {
|
2014-07-03 18:18:21 +00:00
|
|
|
uint8 a, r, g, b;
|
|
|
|
Graphics::colorToARGB< Graphics::ColorMasks<8888> >(color, a, r, g, b);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
_boxShader->use();
|
|
|
|
_boxShader->setUniform("textured", false);
|
|
|
|
_boxShader->setUniform("color", Math::Vector4d(r / 255.0, g / 255.0, b / 255.0, a / 255.0));
|
|
|
|
_boxShader->setUniform("verOffsetXY", scaled(rect.left, rect.top));
|
|
|
|
_boxShader->setUniform("verSizeWH", scaled(rect.width(), rect.height()));
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glDepthMask(GL_FALSE);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
if (a != 255) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(GL_TRUE);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect,
|
2014-07-03 18:18:21 +00:00
|
|
|
Texture *texture, float transparency, bool additiveBlending) {
|
|
|
|
|
|
|
|
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
|
|
|
|
|
|
|
const float tLeft = textureRect.left / (float)glTexture->internalWidth;
|
|
|
|
const float tWidth = textureRect.width() / (float)glTexture->internalWidth;
|
|
|
|
const float tTop = textureRect.top / (float)glTexture->internalHeight;
|
|
|
|
const float tHeight = textureRect.height() / (float)glTexture->internalHeight;
|
|
|
|
|
|
|
|
const float sLeft = screenRect.left;
|
|
|
|
const float sTop = screenRect.top;
|
|
|
|
const float sWidth = screenRect.width();
|
|
|
|
const float sHeight = screenRect.height();
|
|
|
|
|
|
|
|
if (transparency >= 0.0) {
|
|
|
|
if (additiveBlending) {
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
} else {
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
} else {
|
|
|
|
transparency = 1.0;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
_boxShader->use();
|
|
|
|
_boxShader->setUniform("textured", true);
|
|
|
|
_boxShader->setUniform("color", Math::Vector4d(1.0f, 1.0f, 1.0f, transparency));
|
|
|
|
_boxShader->setUniform("verOffsetXY", scaled(sLeft, sTop));
|
|
|
|
_boxShader->setUniform("verSizeWH", scaled(sWidth, sHeight));
|
|
|
|
_boxShader->setUniform("texOffsetXY", Math::Vector2d(tLeft, tTop));
|
|
|
|
_boxShader->setUniform("texSizeWH", Math::Vector2d(tWidth, tHeight));
|
2019-11-08 13:50:20 +00:00
|
|
|
_boxShader->setUniform("flipY", glTexture->upsideDown);
|
2014-07-03 18:18:21 +00:00
|
|
|
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, glTexture->id);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(GL_TRUE);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::draw2DText(const Common::String &text, const Common::Point &position) {
|
2014-07-03 18:18:21 +00:00
|
|
|
OpenGLTexture *glFont = static_cast<OpenGLTexture *>(_font);
|
|
|
|
|
|
|
|
// The font only has uppercase letters
|
|
|
|
Common::String textToDraw = text;
|
|
|
|
textToDraw.toUppercase();
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
|
|
|
|
if (_prevText != textToDraw || _prevTextPosition != position) {
|
|
|
|
_prevText = textToDraw;
|
|
|
|
_prevTextPosition = position;
|
|
|
|
|
2015-05-02 06:42:01 +00:00
|
|
|
float x = position.x / (float) _currentViewport.width();
|
|
|
|
float y = position.y / (float) _currentViewport.height();
|
2014-07-03 18:18:21 +00:00
|
|
|
|
|
|
|
float *bufData = new float[16 * textToDraw.size()];
|
|
|
|
float *cur = bufData;
|
|
|
|
|
|
|
|
for (uint i = 0; i < textToDraw.size(); i++) {
|
|
|
|
Common::Rect textureRect = getFontCharacterRect(textToDraw[i]);
|
2015-05-02 06:42:01 +00:00
|
|
|
float w = textureRect.width() / (float) _currentViewport.width();
|
|
|
|
float h = textureRect.height() / (float) _currentViewport.height();
|
2014-07-03 18:18:21 +00:00
|
|
|
|
|
|
|
float cw = textureRect.width() / (float)glFont->internalWidth;
|
|
|
|
float ch = textureRect.height() / (float)glFont->internalHeight;
|
|
|
|
float cx = textureRect.left / (float)glFont->internalWidth;
|
|
|
|
float cy = textureRect.top / (float)glFont->internalHeight;
|
|
|
|
|
|
|
|
const float charData[] = {
|
|
|
|
cx, cy + ch, x, y,
|
|
|
|
cx + cw, cy + ch, x + w, y,
|
|
|
|
cx + cw, cy, x + w, y + h,
|
|
|
|
cx, cy, x, y + h,
|
|
|
|
};
|
|
|
|
|
|
|
|
memcpy(cur, charData, 16 * sizeof(float));
|
|
|
|
cur += 16;
|
|
|
|
|
2015-05-02 06:42:01 +00:00
|
|
|
x += (textureRect.width() - 3) / (float) _currentViewport.width();
|
2014-07-03 18:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, _textVBO);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, textToDraw.size() * 16 * sizeof(float), bufData);
|
|
|
|
delete[] bufData;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
_textShader->use();
|
2014-07-03 18:18:21 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, glFont->id);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _quadEBO);
|
|
|
|
glDrawElements(GL_TRIANGLES, 6 * textToDraw.size(), GL_UNSIGNED_SHORT, 0);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::drawCube(Texture **textures) {
|
2014-07-03 18:18:21 +00:00
|
|
|
OpenGLTexture *texture0 = static_cast<OpenGLTexture *>(textures[0]);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glDepthMask(GL_FALSE);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
_cubeShader->use();
|
|
|
|
_cubeShader->setUniform1f("texScale", texture0->width / (float) texture0->internalWidth);
|
|
|
|
_cubeShader->setUniform("mvpMatrix", _mvpMatrix);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[0])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[1])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[2])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[3])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[4])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2015-03-22 13:18:07 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[5])->id);
|
2014-07-03 18:18:21 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
glDepthMask(GL_TRUE);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
void ShaderRenderer::drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
|
2014-07-03 18:18:21 +00:00
|
|
|
const Math::Vector3d &topRight, const Math::Vector3d &bottomRight, Texture *texture) {
|
|
|
|
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
|
|
|
|
|
|
|
const float w = glTexture->width / (float)glTexture->internalWidth;
|
|
|
|
const float h = glTexture->height / (float)glTexture->internalHeight;
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, glTexture->id);
|
|
|
|
|
|
|
|
const GLfloat vertices[] = {
|
|
|
|
// S T X Y Z
|
|
|
|
0, 0, -topLeft.x(), topLeft.y(), topLeft.z(),
|
|
|
|
0, h, -bottomLeft.x(), bottomLeft.y(), bottomLeft.z(),
|
|
|
|
w, 0, -topRight.x(), topRight.y(), topRight.z(),
|
|
|
|
w, h, -bottomRight.x(), bottomRight.y(), bottomRight.z(),
|
|
|
|
};
|
|
|
|
|
2015-03-22 13:25:38 +00:00
|
|
|
_rect3dShader->use();
|
|
|
|
_rect3dShader->setUniform1f("texScale", 1.0f);
|
|
|
|
_rect3dShader->setUniform("mvpMatrix", _mvpMatrix);
|
2014-07-03 18:18:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, _rect3dVBO);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, 20 * sizeof(float), vertices);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(GL_TRUE);
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 21:04:27 +00:00
|
|
|
Graphics::Surface *ShaderRenderer::getScreenshot() {
|
2012-12-26 10:43:52 +00:00
|
|
|
Common::Rect screen = viewport();
|
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
Graphics::Surface *s = new Graphics::Surface();
|
2017-08-20 07:04:15 +00:00
|
|
|
s->create(screen.width(), screen.height(), Texture::getRGBAPixelFormat());
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2017-08-20 07:04:15 +00:00
|
|
|
glReadPixels(screen.left, screen.top, screen.width(), screen.height(), GL_RGBA, GL_UNSIGNED_BYTE, s->getPixels());
|
2014-01-13 23:42:06 +00:00
|
|
|
|
2014-09-01 07:47:46 +00:00
|
|
|
flipVertical(s);
|
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
return s;
|
2014-01-13 23:42:06 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 13:50:20 +00:00
|
|
|
Texture *ShaderRenderer::copyScreenshotToTexture() {
|
|
|
|
OpenGLTexture *texture = new OpenGLTexture();
|
|
|
|
|
|
|
|
Common::Rect screen = viewport();
|
|
|
|
texture->copyFromFramebuffer(screen);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-07-03 18:18:21 +00:00
|
|
|
} // End of namespace Myst3
|
2014-01-13 23:42:06 +00:00
|
|
|
|
|
|
|
#endif
|