mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 19:51:49 +00:00
PLAYGROUND3D: Added dimming test using vertex arrays
This commit is contained in:
parent
06b5c259d6
commit
7a4b769887
@ -167,10 +167,10 @@ shaders/stark_shadow.vertex FILE "engines/stark/shaders/stark_shadow
|
||||
#if PLUGIN_ENABLED_STATIC(WINTERMUTE)
|
||||
shaders/wme_fade.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_fade.fragment"
|
||||
shaders/wme_fade.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_fade.vertex"
|
||||
shaders/wme_flat_shadow_mask.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.fragment"
|
||||
shaders/wme_flat_shadow_mask.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.vertex"
|
||||
shaders/wme_flat_shadow_modelx.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.fragment"
|
||||
shaders/wme_flat_shadow_modelx.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.vertex"
|
||||
shaders/wme_flat_shadow_mask.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.fragment"
|
||||
shaders/wme_flat_shadow_mask.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.vertex"
|
||||
shaders/wme_flat_shadow_modelx.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.fragment"
|
||||
shaders/wme_flat_shadow_modelx.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.vertex"
|
||||
shaders/wme_geometry.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_geometry.fragment"
|
||||
shaders/wme_geometry.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_geometry.vertex"
|
||||
shaders/wme_line.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_line.fragment"
|
||||
@ -187,6 +187,8 @@ shaders/wme_sprite.vertex FILE "engines/wintermute/base/gfx/ope
|
||||
#if PLUGIN_ENABLED_STATIC(PLAYGROUND3D)
|
||||
shaders/playground3d_cube.fragment FILE "engines/playground3d/shaders/playground3d_cube.fragment"
|
||||
shaders/playground3d_cube.vertex FILE "engines/playground3d/shaders/playground3d_cube.vertex"
|
||||
shaders/playground3d_fade.fragment FILE "engines/playground3d/shaders/playground3d_fade.fragment"
|
||||
shaders/playground3d_fade.vertex FILE "engines/playground3d/shaders/playground3d_fade.vertex"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
virtual ~Renderer();
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void clear(const Math::Vector4d &clearColor) = 0;
|
||||
|
||||
/**
|
||||
* Swap the buffers, making the drawn screen visible
|
||||
@ -56,6 +56,7 @@ public:
|
||||
|
||||
virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
|
||||
virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
|
||||
virtual void dimRegionInOut(float fade) = 0;
|
||||
|
||||
protected:
|
||||
OSystem *_system;
|
||||
|
@ -33,6 +33,14 @@
|
||||
|
||||
namespace Playground3d {
|
||||
|
||||
static const GLfloat dimRegionVertices[] = {
|
||||
// X Y
|
||||
-0.5f, 0.5f,
|
||||
0.5f, 0.5f,
|
||||
-0.5f, -0.5f,
|
||||
0.5f, -0.5f,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxOpenGL(OSystem *system) {
|
||||
return new OpenGLRenderer(system);
|
||||
}
|
||||
@ -60,12 +68,13 @@ void OpenGLRenderer::init() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::clear() {
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
void OpenGLRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -130,6 +139,36 @@ void OpenGLRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::dimRegionInOut(float fade) {
|
||||
Common::Rect vp = viewport();
|
||||
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glColor4f(0.0f, 0.0f, 0.0f, 1.0f - fade);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &dimRegionVertices[0]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
||||
#endif
|
||||
|
@ -41,10 +41,11 @@ public:
|
||||
|
||||
virtual void init() override;
|
||||
|
||||
virtual void clear() override;
|
||||
virtual void clear(const Math::Vector4d &clearColor) override;
|
||||
|
||||
virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void dimRegionInOut(float fade) override;
|
||||
|
||||
private:
|
||||
void drawFace(uint face);
|
||||
|
@ -39,6 +39,14 @@
|
||||
|
||||
namespace Playground3d {
|
||||
|
||||
static const GLfloat dimRegionVertices[] = {
|
||||
// X Y
|
||||
-0.5f, 0.5f,
|
||||
0.5f, 0.5f,
|
||||
-0.5f, -0.5f,
|
||||
0.5f, -0.5f,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxOpenGLShader(OSystem *system) {
|
||||
return new ShaderRenderer(system);
|
||||
}
|
||||
@ -47,13 +55,17 @@ ShaderRenderer::ShaderRenderer(OSystem *system) :
|
||||
Renderer(system),
|
||||
_currentViewport(kOriginalWidth, kOriginalHeight),
|
||||
_cubeShader(nullptr),
|
||||
_cubeVBO(0) {
|
||||
_fadeShader(nullptr),
|
||||
_cubeVBO(0),
|
||||
_fadeVBO(0) {
|
||||
}
|
||||
|
||||
ShaderRenderer::~ShaderRenderer() {
|
||||
OpenGL::ShaderGL::freeBuffer(_cubeVBO);
|
||||
OpenGL::ShaderGL::freeBuffer(_fadeVBO);
|
||||
|
||||
delete _cubeShader;
|
||||
delete _fadeShader;
|
||||
}
|
||||
|
||||
void ShaderRenderer::init() {
|
||||
@ -63,17 +75,22 @@ void ShaderRenderer::init() {
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
static const char* attributes[] = { "position", "normal", "color", "texcoord", NULL };
|
||||
_cubeShader = OpenGL::ShaderGL::fromFiles("playground3d_cube", attributes);
|
||||
static const char *cubeAttributes[] = { "position", "normal", "color", "texcoord", NULL };
|
||||
_cubeShader = OpenGL::ShaderGL::fromFiles("playground3d_cube", cubeAttributes);
|
||||
_cubeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices);
|
||||
_cubeShader->enableVertexAttribute("texcoord", _cubeVBO, 2, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 0);
|
||||
_cubeShader->enableVertexAttribute("position", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 8);
|
||||
_cubeShader->enableVertexAttribute("normal", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 20);
|
||||
_cubeShader->enableVertexAttribute("color", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 32);
|
||||
|
||||
static const char* fadeAttributes[] = { "position", nullptr };
|
||||
_fadeShader = OpenGL::ShaderGL::fromFiles("playground3d_fade", fadeAttributes);
|
||||
_fadeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(dimRegionVertices), dimRegionVertices);
|
||||
_fadeShader->enableVertexAttribute("position", _fadeVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
||||
}
|
||||
|
||||
void ShaderRenderer::clear() {
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
void ShaderRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -100,6 +117,21 @@ void ShaderRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V
|
||||
error("Polygon offset test not implemented yet");
|
||||
}
|
||||
|
||||
void ShaderRenderer::dimRegionInOut(float fade) {
|
||||
Common::Rect vp = viewport();
|
||||
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
_fadeShader->use();
|
||||
_fadeShader->setUniform1f("alphaLevel", 1.0 - fade);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
_fadeShader->unbind();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
||||
#endif
|
||||
|
@ -41,15 +41,18 @@ public:
|
||||
|
||||
virtual void init() override;
|
||||
|
||||
virtual void clear() override;
|
||||
virtual void clear(const Math::Vector4d &clearColor) override;
|
||||
|
||||
virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void dimRegionInOut(float fade) override;
|
||||
|
||||
private:
|
||||
OpenGL::ShaderGL *_cubeShader;
|
||||
OpenGL::ShaderGL *_fadeShader;
|
||||
|
||||
GLuint _cubeVBO;
|
||||
GLuint _fadeVBO;
|
||||
|
||||
Common::Rect _currentViewport;
|
||||
};
|
||||
|
@ -35,6 +35,18 @@
|
||||
|
||||
namespace Playground3d {
|
||||
|
||||
static const TGLfloat dimRegionVertices[] = {
|
||||
// X Y
|
||||
-0.5f, 0.5f,
|
||||
0.5f, 0.5f,
|
||||
-0.5f, -0.5f,
|
||||
0.5f, -0.5f,
|
||||
};
|
||||
|
||||
static const TGLuint dimRegionIndices[] = {
|
||||
0, 1, 2, 3
|
||||
};
|
||||
|
||||
Renderer *CreateGfxTinyGL(OSystem *system) {
|
||||
return new TinyGLRenderer(system);
|
||||
}
|
||||
@ -66,8 +78,8 @@ void TinyGLRenderer::init() {
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::clear() {
|
||||
tglClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
void TinyGLRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
tglClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
|
||||
tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -137,4 +149,36 @@ void TinyGLRenderer::flipBuffer() {
|
||||
g_system->copyRectToScreen(_fb->getPixelBuffer(), _fb->linesize, 0, 0, _fb->xsize, _fb->ysize);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::dimRegionInOut(float fade) {
|
||||
Common::Rect vp = viewport();
|
||||
tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglPushMatrix();
|
||||
tglLoadIdentity();
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglPushMatrix();
|
||||
tglLoadIdentity();
|
||||
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE, TGL_ONE_MINUS_SRC_ALPHA);
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
tglColor4f(0.0f, 0.0f, 0.0f, 1.0f - fade);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 0, dimRegionVertices);
|
||||
tglDrawElements(TGL_TRIANGLE_STRIP, 4, TGL_UNSIGNED_INT, dimRegionIndices);
|
||||
//tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglPopMatrix();
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglPopMatrix();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
@ -41,10 +41,11 @@ public:
|
||||
|
||||
virtual void init() override;
|
||||
|
||||
virtual void clear() override;
|
||||
virtual void clear(const Math::Vector4d &clearColor) override;
|
||||
|
||||
virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
virtual void dimRegionInOut(float fade) override;
|
||||
|
||||
virtual void flipBuffer() override;
|
||||
|
||||
|
@ -46,7 +46,8 @@ bool Playground3dEngine::hasFeature(EngineFeature f) const {
|
||||
|
||||
Playground3dEngine::Playground3dEngine(OSystem *syst)
|
||||
: Engine(syst), _system(syst), _frameLimiter(0),
|
||||
_rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0) {
|
||||
_rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0),
|
||||
_clearColor(0.0f, 0.0f, 0.0f, 1.0f), _fade(1.0f), _fadeIn(false) {
|
||||
}
|
||||
|
||||
Playground3dEngine::~Playground3dEngine() {
|
||||
@ -57,21 +58,25 @@ Playground3dEngine::~Playground3dEngine() {
|
||||
Common::Error Playground3dEngine::run() {
|
||||
_gfx = createRenderer(_system);
|
||||
_gfx->init();
|
||||
_gfx->clear();
|
||||
|
||||
_frameLimiter = new Gfx::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
|
||||
|
||||
_system->showMouse(true);
|
||||
|
||||
// 1 - rotated colorfull cube
|
||||
// 2 - rotated two traingles with depth offset
|
||||
// 2 - rotated two triangles with depth offset
|
||||
// 3 - fade in/out
|
||||
int testId = 1;
|
||||
|
||||
switch (testId) {
|
||||
case 1:
|
||||
_clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
_rotateAngleX = 45, _rotateAngleY = 45, _rotateAngleZ = 10;
|
||||
break;
|
||||
case 2:
|
||||
_clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
case 3:
|
||||
_clearColor = Math::Vector4d(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
@ -119,8 +124,23 @@ void Playground3dEngine::drawPolyOffsetTest() {
|
||||
_rotateAngleY = 0;
|
||||
}
|
||||
|
||||
void Playground3dEngine::dimRegionInOut() {
|
||||
_gfx->dimRegionInOut(_fade);
|
||||
if (_fadeIn)
|
||||
_fade += 0.01f;
|
||||
else
|
||||
_fade -= 0.01f;
|
||||
if (_fade > 1.0f) {
|
||||
_fade = 1;
|
||||
_fadeIn = false;
|
||||
} else if (_fade < 0.0f) {
|
||||
_fade = 0;
|
||||
_fadeIn = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Playground3dEngine::drawFrame(int testId) {
|
||||
_gfx->clear();
|
||||
_gfx->clear(_clearColor);
|
||||
|
||||
float pitch = 0.0f;
|
||||
float heading = 0.0f;
|
||||
@ -134,6 +154,9 @@ void Playground3dEngine::drawFrame(int testId) {
|
||||
case 2:
|
||||
drawPolyOffsetTest();
|
||||
break;
|
||||
case 3:
|
||||
dimRegionInOut();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
@ -49,11 +49,15 @@ private:
|
||||
OSystem *_system;
|
||||
Renderer *_gfx;
|
||||
Gfx::FrameLimiter *_frameLimiter;
|
||||
Math::Vector4d _clearColor;
|
||||
float _fade;
|
||||
bool _fadeIn;
|
||||
|
||||
float _rotateAngleX, _rotateAngleY, _rotateAngleZ;
|
||||
|
||||
void drawAndRotateCube();
|
||||
void drawPolyOffsetTest();
|
||||
void dimRegionInOut();
|
||||
};
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
@ -6,8 +6,7 @@ OUTPUT
|
||||
uniform bool textured;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
outColor = vec4(Color, 1.0);
|
||||
if (textured) {
|
||||
outColor *= texture(tex, Texcoord);
|
||||
|
@ -13,8 +13,7 @@ uniform vec3 modelPos;
|
||||
out vec2 Texcoord;
|
||||
out vec3 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
Texcoord = texcoord;
|
||||
|
||||
vec4 pos = rotateMatrix * vec4(position, 1.0);
|
||||
|
8
engines/playground3d/shaders/playground3d_fade.fragment
Normal file
8
engines/playground3d/shaders/playground3d_fade.fragment
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform float alphaLevel;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(0.0, 0.0, 0.0, alphaLevel);
|
||||
}
|
5
engines/playground3d/shaders/playground3d_fade.vertex
Normal file
5
engines/playground3d/shaders/playground3d_fade.vertex
Normal file
@ -0,0 +1,5 @@
|
||||
in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user