Initial commit
This commit is contained in:
1061
engines/wintermute/base/gfx/tinygl/base_render_tinygl.cpp
Normal file
1061
engines/wintermute/base/gfx/tinygl/base_render_tinygl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
176
engines/wintermute/base/gfx/tinygl/base_render_tinygl.h
Normal file
176
engines/wintermute/base/gfx/tinygl/base_render_tinygl.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WINTERMUTE_BASE_RENDER_TINYGL_H
|
||||
#define WINTERMUTE_BASE_RENDER_TINYGL_H
|
||||
|
||||
#include "engines/wintermute/base/gfx/base_renderer3d.h"
|
||||
#include "engines/wintermute/dctypes.h"
|
||||
|
||||
#include "graphics/transform_struct.h"
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class BaseSurfaceTinyGL;
|
||||
|
||||
class BaseRenderTinyGL : public BaseRenderer3D {
|
||||
friend class BaseSurfaceTinyGL;
|
||||
friend class Mesh3DSTinyGL;
|
||||
friend class XMeshTinyGL;
|
||||
friend class ShadowVolumeTinyGL;
|
||||
|
||||
struct SpriteVertex {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float u;
|
||||
float v;
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
|
||||
struct RectangleVertex {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
struct SimpleShadowVertex {
|
||||
float nx;
|
||||
float ny;
|
||||
float nz;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float u;
|
||||
float v;
|
||||
};
|
||||
|
||||
public:
|
||||
BaseRenderTinyGL(BaseGame *inGame = nullptr);
|
||||
~BaseRenderTinyGL() override;
|
||||
|
||||
bool invalidateTexture(BaseSurface *texture) override;
|
||||
|
||||
bool invalidateDeviceObjects() override;
|
||||
bool restoreDeviceObjects() override;
|
||||
|
||||
bool resetDevice() override;
|
||||
|
||||
void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) override;
|
||||
|
||||
void setAmbientLightRenderState() override;
|
||||
|
||||
int getMaxActiveLights() override;
|
||||
void lightEnable(int index, bool enable) override;
|
||||
void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction, const DXVector4 &diffuse, bool spotlight) override;
|
||||
|
||||
void enableCulling() override;
|
||||
void disableCulling() override;
|
||||
|
||||
bool enableShadows() override;
|
||||
bool disableShadows() override;
|
||||
bool shadowVolumeSupported() override;
|
||||
|
||||
BaseImage *takeScreenshot(int newWidth = 0, int newHeight = 0) override;
|
||||
bool fadeToColor(byte r, byte g, byte b, byte a) override;
|
||||
|
||||
bool flip() override;
|
||||
bool clear() override;
|
||||
|
||||
bool setViewport(int left, int top, int right, int bottom) override;
|
||||
bool drawLine(int x1, int y1, int x2, int y2, uint32 color) override;
|
||||
bool fillRect(int x, int y, int w, int h, uint32 color) override;
|
||||
|
||||
DXMatrix *buildMatrix(DXMatrix* out, const DXVector2 *centre, const DXVector2 *scaling, float angle);
|
||||
void transformVertices(struct SpriteVertex *vertices, const DXVector2 *centre, const DXVector2 *scaling, float angle);
|
||||
|
||||
bool setProjection() override;
|
||||
bool setProjection2D();
|
||||
bool setWorldTransform(const DXMatrix &transform) override;
|
||||
bool setViewTransform(const DXMatrix &transform) override;
|
||||
bool setProjectionTransform(const DXMatrix &transform) override;
|
||||
|
||||
bool initRenderer(int width, int height, bool windowed) override;
|
||||
bool setup2D(bool force = false) override;
|
||||
bool setup3D(Camera3D *camera, bool force = false) override;
|
||||
|
||||
Common::String getName() const override {
|
||||
return "TinyGL software renderer";
|
||||
};
|
||||
bool displayDebugInfo() override {
|
||||
return STATUS_FAILED;
|
||||
};
|
||||
bool drawShaderQuad() override {
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
float getScaleRatioX() const override {
|
||||
return 1.0f;
|
||||
}
|
||||
float getScaleRatioY() const override {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
BaseSurface *createSurface() override;
|
||||
|
||||
bool startSpriteBatch() override;
|
||||
bool endSpriteBatch() override;
|
||||
bool commitSpriteBatch() override;
|
||||
|
||||
bool drawSpriteEx(BaseSurface *texture, const Common::Rect32 &rect, const DXVector2 &pos, const DXVector2 &rot, const DXVector2 &scale,
|
||||
float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) override;
|
||||
|
||||
void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
|
||||
const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) override;
|
||||
void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) override;
|
||||
|
||||
Mesh3DS *createMesh3DS() override;
|
||||
XMesh *createXMesh() override;
|
||||
ShadowVolume *createShadowVolume() override;
|
||||
|
||||
bool setViewport3D(DXViewport *viewport) override;
|
||||
|
||||
void postfilter() override;
|
||||
void setPostfilter(PostFilter postFilter) override { _postFilterMode = postFilter; };
|
||||
|
||||
private:
|
||||
bool setupLines();
|
||||
void displaySimpleShadow(BaseObject *object) override;
|
||||
|
||||
Graphics::TSpriteBlendMode _blendMode;
|
||||
SimpleShadowVertex _simpleShadow[4];
|
||||
Common::Array<DXVector4> _lightPositions;
|
||||
Common::Array<DXVector3> _lightDirections;
|
||||
//TGLuint _postfilterTexture;
|
||||
bool _shadowVolumesSupported;
|
||||
};
|
||||
|
||||
} // wintermute namespace
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
|
||||
#endif
|
||||
462
engines/wintermute/base/gfx/tinygl/base_surface_tinygl.cpp
Normal file
462
engines/wintermute/base/gfx/tinygl/base_surface_tinygl.cpp
Normal file
@@ -0,0 +1,462 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/algorithm.h"
|
||||
|
||||
#include "graphics/transform_tools.h"
|
||||
|
||||
#include "engines/wintermute/base/base_game.h"
|
||||
#include "engines/wintermute/base/base_engine.h"
|
||||
#include "engines/wintermute/base/gfx/base_image.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "engines/wintermute/base/gfx/3dutils.h"
|
||||
#include "engines/wintermute/base/gfx/tinygl/base_surface_tinygl.h"
|
||||
#include "engines/wintermute/base/gfx/tinygl/base_render_tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
BaseSurfaceTinyGL::BaseSurfaceTinyGL(BaseGame *game, BaseRenderer3D *renderer)
|
||||
: BaseSurface(game), _tex(0), _renderer(renderer), _imageData(nullptr), _maskData(nullptr), _pixelOpReady(false), _surfaceModified(false), _texture2D(true) {
|
||||
_blitImage = tglGenBlitImage();
|
||||
}
|
||||
|
||||
BaseSurfaceTinyGL::~BaseSurfaceTinyGL() {
|
||||
_renderer->invalidateTexture(this);
|
||||
if (_tex) {
|
||||
tglDeleteTextures(1, &_tex);
|
||||
_tex = 0;
|
||||
}
|
||||
|
||||
if (_imageData) {
|
||||
_imageData->free();
|
||||
delete _imageData;
|
||||
_imageData = nullptr;
|
||||
}
|
||||
|
||||
if (_maskData) {
|
||||
_maskData->free();
|
||||
delete _maskData;
|
||||
_maskData = nullptr;
|
||||
}
|
||||
|
||||
tglDeleteBlitImage(_blitImage);
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::invalidate() {
|
||||
_renderer->invalidateTexture(this);
|
||||
if (_tex) {
|
||||
tglDeleteTextures(1, &_tex);
|
||||
_tex = 0;
|
||||
}
|
||||
|
||||
if (_imageData) {
|
||||
_imageData->free();
|
||||
delete _imageData;
|
||||
_imageData = nullptr;
|
||||
}
|
||||
|
||||
_valid = false;
|
||||
_surfaceModified = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::prepareToDraw() {
|
||||
_lastUsedTime = _game->_liveTimer;
|
||||
|
||||
if (!_valid) {
|
||||
loadImage();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::displayTransZoom(int x, int y, Common::Rect32 rect, float zoomX, float zoomY, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
||||
prepareToDraw();
|
||||
|
||||
_renderer->drawSprite(dynamic_cast<BaseSurface *>(this), rect, zoomX, zoomY, DXVector2(x, y), alpha, false, blendMode, mirrorX, mirrorY);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::displayTrans(int x, int y, Common::Rect32 rect, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) {
|
||||
prepareToDraw();
|
||||
|
||||
_renderer->drawSprite(dynamic_cast<BaseSurface *>(this), rect, 100, 100, DXVector2(x + offsetX, y + offsetY), alpha, false, blendMode, mirrorX, mirrorY);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::display(int x, int y, Common::Rect32 rect, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
||||
prepareToDraw();
|
||||
|
||||
_renderer->drawSprite(dynamic_cast<BaseSurface *>(this), rect, 100, 100, DXVector2(x, y), 0xFFFFFFFF, true, blendMode, mirrorX, mirrorY);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::displayTransRotate(int x, int y, float rotate, int32 hotspotX, int32 hotspotY, Common::Rect32 rect, float zoomX, float zoomY, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
||||
prepareToDraw();
|
||||
|
||||
x -= hotspotX;
|
||||
y -= hotspotY;
|
||||
|
||||
DXVector2 position(x, y);
|
||||
DXVector2 rotation;
|
||||
rotation._x = x + hotspotX * (zoomX / 100.0f);
|
||||
rotation._y = y + hotspotY * (zoomY / 100.0f);
|
||||
DXVector2 scale(zoomX / 100.0f, zoomY / 100.0f);
|
||||
float angle = degToRad(rotate);
|
||||
|
||||
_renderer->drawSpriteEx(dynamic_cast<BaseSurface *>(this), rect, position, rotation, scale, angle, alpha, false, blendMode, mirrorX, mirrorY);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::displayTiled(int x, int y, Common::Rect32 rect, int numTimesX, int numTimesY) {
|
||||
prepareToDraw();
|
||||
|
||||
DXVector2 scale(numTimesX, numTimesY);
|
||||
_renderer->drawSpriteEx(dynamic_cast<BaseSurface *>(this), rect, DXVector2(x, y), DXVector2(0, 0), scale, 0, 0xFFFFFFFF, false, Graphics::BLEND_NORMAL, false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::create(const char *filename, bool texture2D, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime, bool keepLoaded) {
|
||||
if (defaultCK) {
|
||||
ckRed = 255;
|
||||
ckGreen = 0;
|
||||
ckBlue = 255;
|
||||
}
|
||||
|
||||
_texture2D = texture2D;
|
||||
|
||||
Common::String surfacefilename = filename;
|
||||
BaseImage img = BaseImage();
|
||||
if (!img.getImageInfo(surfacefilename, _width, _height)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lifeTime != -1 && _lifeTime == 0) {
|
||||
_valid = false;
|
||||
}
|
||||
|
||||
_ckDefault = defaultCK;
|
||||
_ckRed = ckRed;
|
||||
_ckGreen = ckGreen;
|
||||
_ckBlue = ckBlue;
|
||||
|
||||
if (!_filename || scumm_stricmp(_filename, filename) != 0) {
|
||||
setFilename(filename);
|
||||
}
|
||||
|
||||
if (_lifeTime == 0 || lifeTime == -1 || lifeTime > _lifeTime) {
|
||||
_lifeTime = lifeTime;
|
||||
}
|
||||
|
||||
_keepLoaded = keepLoaded;
|
||||
if (_keepLoaded) {
|
||||
_lifeTime = -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::loadImage() {
|
||||
if (!_filename || !_filename[0]) {
|
||||
return false;
|
||||
}
|
||||
Common::String filename = _filename;
|
||||
|
||||
BaseImage img = BaseImage();
|
||||
if (!img.loadFile(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (img.getSurface()->format.bytesPerPixel == 1 && img.getPalette() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool needsColorKey = false;
|
||||
bool replaceAlpha = true;
|
||||
|
||||
if (_imageData) {
|
||||
_imageData->free();
|
||||
delete _imageData;
|
||||
_imageData = nullptr;
|
||||
}
|
||||
|
||||
_imageData = img.getSurface()->convertTo(Graphics::PixelFormat::createFormatRGBA32(), img.getPalette(), img.getPaletteCount());
|
||||
|
||||
if (filename.matchString("savegame:*g", true)) {
|
||||
uint8 r, g, b, a;
|
||||
for (int x = 0; x < _imageData->w; x++) {
|
||||
for (int y = 0; y < _imageData->h; y++) {
|
||||
_imageData->format.colorToARGB(_imageData->getPixel(x, y), a, r, g, b);
|
||||
uint8 grey = (uint8)((0.2126f * r + 0.7152f * g + 0.0722f * b) + 0.5f);
|
||||
_imageData->setPixel(x, y, _imageData->format.ARGBToColor(a, grey, grey, grey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filename.hasSuffix(".bmp")) {
|
||||
// Ignores alpha channel for BMPs
|
||||
needsColorKey = true;
|
||||
} else if (filename.hasSuffix(".jpg")) {
|
||||
// Ignores alpha channel for JPEGs
|
||||
needsColorKey = true;
|
||||
} else if (BaseEngine::instance().getTargetExecutable() < WME_LITE) {
|
||||
// WME 1.x always use colorkey, even for images with transparency
|
||||
needsColorKey = true;
|
||||
replaceAlpha = false;
|
||||
} else if (BaseEngine::instance().isFoxTail()) {
|
||||
// FoxTail does not use colorkey
|
||||
needsColorKey = false;
|
||||
} else if (img.getSurface()->format.aBits() == 0) {
|
||||
// generic WME Lite does not use colorkey for non-BMPs with transparency
|
||||
needsColorKey = true;
|
||||
}
|
||||
|
||||
if (needsColorKey) {
|
||||
// We set the pixel color to transparent black,
|
||||
// like D3DX, if it matches the color key.
|
||||
_imageData->applyColorKey(_ckRed, _ckGreen, _ckBlue, replaceAlpha, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Bug #6572 WME: Rosemary - Sprite flaw on going upwards
|
||||
// Some Rosemary sprites have non-fully transparent pixels
|
||||
// In original WME it wasn't seen because sprites were downscaled
|
||||
// Let's set alpha to 0 if it is smaller then some treshold
|
||||
if (BaseEngine::instance().getGameId() == "rosemary" && filename.hasPrefix("actors") && _imageData->format.bytesPerPixel == 4) {
|
||||
uint32 mask = _imageData->format.ARGBToColor(255, 0, 0, 0);
|
||||
uint32 treshold = _imageData->format.ARGBToColor(16, 0, 0, 0);
|
||||
uint32 blank = _imageData->format.ARGBToColor(0, 0, 0, 0);
|
||||
|
||||
for (int x = 0; x < _imageData->w; x++) {
|
||||
for (int y = 0; y < _imageData->h; y++) {
|
||||
uint32 pixel = _imageData->getPixel(x, y);
|
||||
if ((pixel & mask) > blank && (pixel & mask) < treshold) {
|
||||
_imageData->setPixel(x, y, blank);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
putSurface(*_imageData);
|
||||
|
||||
/* TODO: Delete _imageData if we no longer need to access the pixel data? */
|
||||
|
||||
_valid = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::create(int width, int height) {
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
_valid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::putSurface(const Graphics::Surface &surface, bool hasAlpha) {
|
||||
if (!_imageData) {
|
||||
_imageData = new Graphics::Surface();
|
||||
}
|
||||
|
||||
if (_imageData && _imageData != &surface) {
|
||||
_imageData->copyFrom(surface);
|
||||
writeAlpha(_imageData, _maskData);
|
||||
}
|
||||
|
||||
_width = surface.w;
|
||||
_height = surface.h;
|
||||
|
||||
if (_texture2D) {
|
||||
tglUploadBlitImage(_blitImage, *_imageData, 0, false);
|
||||
} else {
|
||||
if (!_valid) {
|
||||
tglGenTextures(1, &_tex);
|
||||
}
|
||||
_texWidth = Common::nextHigher2(_width);
|
||||
_texHeight = Common::nextHigher2(_height);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _tex);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_S, TGL_REPEAT);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_T, TGL_REPEAT);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_LINEAR);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, _width, _height, 0, TGL_RGBA, TGL_UNSIGNED_BYTE, _imageData->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
}
|
||||
_valid = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::putPixel(int x, int y, byte r, byte g, byte b, byte a) {
|
||||
if (!_pixelOpReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x < 0 || y < 0 || x >= _width || y >= _height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_imageData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_imageData->setPixel(x, y, _imageData->format.ARGBToColor(a, r, g, b));
|
||||
|
||||
_surfaceModified = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::getPixel(int x, int y, byte *r, byte *g, byte *b, byte *a) const {
|
||||
if (!_pixelOpReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x < 0 || y < 0 || x >= _width || y >= _height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_imageData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8 alpha, red, green, blue;
|
||||
_imageData->format.colorToARGB(_imageData->getPixel(x, y), alpha, red, green, blue);
|
||||
*r = red;
|
||||
*g = green;
|
||||
*b = blue;
|
||||
*a = alpha;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::startPixelOp() {
|
||||
if (!prepareToDraw())
|
||||
return false;
|
||||
_pixelOpReady = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::endPixelOp() {
|
||||
_pixelOpReady = false;
|
||||
if (_surfaceModified) {
|
||||
if (_texture2D) {
|
||||
tglUploadBlitImage(_blitImage, *_imageData, 0, false);
|
||||
} else {
|
||||
tglBindTexture(TGL_TEXTURE_2D, _tex);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, _width, _height, 0, TGL_RGBA, TGL_UNSIGNED_BYTE, _imageData->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
}
|
||||
_surfaceModified = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseSurfaceTinyGL::isTransparentAtLite(int x, int y) const {
|
||||
if (!_pixelOpReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x < 0 || y < 0 || x >= _width || y >= _height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_imageData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8 a, r, g, b;
|
||||
_imageData->format.colorToARGB(_imageData->getPixel(x, y), a, r, g, b);
|
||||
// Keep behavior in sync with the 2D renderer, which implements the WME Lite logic
|
||||
// by comparing alpha against 128.
|
||||
// This differs from the original WME1 sources, where alpha is compared against 0.
|
||||
// The likely reason for this discrepancy is a difference in how bitmaps are
|
||||
// converted after loading.
|
||||
if (a <= 128) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseSurfaceTinyGL::setTexture() {
|
||||
prepareToDraw();
|
||||
|
||||
if (!_texture2D) {
|
||||
tglBindTexture(TGL_TEXTURE_2D, _tex);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool BaseSurfaceTinyGL::setAlphaImage(const char *filename) {
|
||||
BaseImage *alphaImage = new BaseImage();
|
||||
if (!alphaImage->loadFile(filename)) {
|
||||
delete alphaImage;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_maskData) {
|
||||
_maskData->free();
|
||||
delete _maskData;
|
||||
_maskData = nullptr;
|
||||
}
|
||||
|
||||
Graphics::AlphaType type = alphaImage->getSurface()->detectAlpha();
|
||||
if (type != Graphics::ALPHA_OPAQUE) {
|
||||
_maskData = alphaImage->getSurface()->convertTo(Graphics::PixelFormat::createFormatRGBA32());
|
||||
}
|
||||
|
||||
delete alphaImage;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseSurfaceTinyGL::writeAlpha(Graphics::Surface *surface, const Graphics::Surface *mask) {
|
||||
if (mask && surface->w == mask->w && surface->h == mask->h) {
|
||||
assert(mask->pitch == mask->w * 4);
|
||||
assert(mask->format.bytesPerPixel == 4);
|
||||
assert(surface->pitch == surface->w * 4);
|
||||
assert(surface->format.bytesPerPixel == 4);
|
||||
const byte *alphaData = (const byte *)mask->getPixels();
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
int alphaPlace = (mask->format.aShift / 8);
|
||||
#else
|
||||
int alphaPlace = 3 - (mask->format.aShift / 8);
|
||||
#endif
|
||||
alphaData += alphaPlace;
|
||||
byte *imgData = (byte *)surface->getPixels();
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
imgData += (surface->format.aShift / 8);
|
||||
#else
|
||||
imgData += 3 - (surface->format.aShift / 8);
|
||||
#endif
|
||||
for (int i = 0; i < surface->w * surface->h; i++) {
|
||||
*imgData = *alphaData;
|
||||
alphaData += 4;
|
||||
imgData += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
101
engines/wintermute/base/gfx/tinygl/base_surface_tinygl.h
Normal file
101
engines/wintermute/base/gfx/tinygl/base_surface_tinygl.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WINTERMUTE_BASE_SURFACE_TINYGL_H
|
||||
#define WINTERMUTE_BASE_SURFACE_TINYGL_H
|
||||
|
||||
#include "engines/wintermute/base/gfx/base_surface.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class BaseGame;
|
||||
class BaseRenderer3D;
|
||||
|
||||
class BaseSurfaceTinyGL : public BaseSurface {
|
||||
public:
|
||||
BaseSurfaceTinyGL(BaseGame *game, BaseRenderer3D *renderer);
|
||||
~BaseSurfaceTinyGL();
|
||||
|
||||
bool invalidate() override;
|
||||
bool prepareToDraw() override;
|
||||
|
||||
bool displayTransRotate(int x, int y, float rotate, int32 hotspotX, int32 hotspotY, Common::Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
|
||||
bool displayTransZoom(int x, int y, Common::Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
|
||||
bool displayTrans(int x, int y, Common::Rect32 rect, uint32 alpha = 0xFFFFFFFF, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override;
|
||||
bool display(int x, int y, Common::Rect32 rect, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
|
||||
bool displayTiled(int x, int y, Common::Rect32 rect, int numTimesX, int numTimesY) override;
|
||||
bool create(const char *filename, bool texture2D, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime = -1, bool keepLoaded = false) override;
|
||||
bool create(int width, int height) override;
|
||||
bool setAlphaImage(const char *filename) override;
|
||||
bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override;
|
||||
bool putPixel(int x, int y, byte r, byte g, byte b, byte a) override;
|
||||
bool getPixel(int x, int y, byte *r, byte *g, byte *b, byte *a = nullptr) const override;
|
||||
bool startPixelOp() override;
|
||||
bool endPixelOp() override;
|
||||
bool isTransparentAtLite(int x, int y) const override;
|
||||
|
||||
void setTexture();
|
||||
|
||||
int getWidth() override {
|
||||
return _width;
|
||||
}
|
||||
|
||||
int getHeight() override {
|
||||
return _height;
|
||||
}
|
||||
|
||||
uint getGLTextureWidth() const {
|
||||
return _texWidth;
|
||||
}
|
||||
|
||||
uint getGLTextureHeight() const {
|
||||
return _texHeight;
|
||||
}
|
||||
|
||||
TinyGL::BlitImage *getBlitImage() {
|
||||
return _blitImage;
|
||||
}
|
||||
|
||||
private:
|
||||
TGLuint _tex;
|
||||
BaseRenderer3D *_renderer;
|
||||
Graphics::Surface *_imageData;
|
||||
Graphics::Surface *_maskData;
|
||||
uint _texWidth{};
|
||||
uint _texHeight{};
|
||||
bool _pixelOpReady;
|
||||
bool _surfaceModified;
|
||||
TinyGL::BlitImage *_blitImage;
|
||||
bool _texture2D;
|
||||
|
||||
bool loadImage();
|
||||
void writeAlpha(Graphics::Surface *surface, const Graphics::Surface *mask);
|
||||
};
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
|
||||
#endif
|
||||
60
engines/wintermute/base/gfx/tinygl/mesh3ds_tinygl.cpp
Normal file
60
engines/wintermute/base/gfx/tinygl/mesh3ds_tinygl.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/wintermute/wintypes.h"
|
||||
|
||||
#include "graphics/opengl/system_headers.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "engines/wintermute/base/gfx/tinygl/mesh3ds_tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
Mesh3DSTinyGL::Mesh3DSTinyGL(BaseGame *inGame) : Mesh3DS(inGame) {
|
||||
_vertexCount = 0;
|
||||
_vertexData = nullptr;
|
||||
}
|
||||
|
||||
Mesh3DSTinyGL::~Mesh3DSTinyGL() {
|
||||
}
|
||||
|
||||
void Mesh3DSTinyGL::fillVertexBuffer() {
|
||||
_vertexCount = _numFaces * 3;
|
||||
_vertexData = (Mesh3DSVertex *)_vb.ptr();
|
||||
}
|
||||
|
||||
void Mesh3DSTinyGL::render(bool color) {
|
||||
if (_vertexCount == 0)
|
||||
return;
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_COLOR_ARRAY);
|
||||
tglVertexPointer(3, TGL_FLOAT, sizeof(Mesh3DSVertex), &_vertexData[0]._x);
|
||||
tglColorPointer(4, TGL_FLOAT, sizeof(Mesh3DSVertex), &_vertexData[0]._r);
|
||||
tglDrawArrays(TGL_TRIANGLES, 0, _vertexCount);
|
||||
tglDisableClientState(TGL_COLOR_ARRAY);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
49
engines/wintermute/base/gfx/tinygl/mesh3ds_tinygl.h
Normal file
49
engines/wintermute/base/gfx/tinygl/mesh3ds_tinygl.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WINTERMUTE_MESH_TINYGL_H
|
||||
#define WINTERMUTE_MESH_TINYGL_H
|
||||
|
||||
#include "engines/wintermute/base/gfx/3dmesh.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class Mesh3DSTinyGL : public Mesh3DS {
|
||||
public:
|
||||
Mesh3DSTinyGL(BaseGame *inGame);
|
||||
~Mesh3DSTinyGL();
|
||||
void fillVertexBuffer() override;
|
||||
void render(bool color) override;
|
||||
|
||||
private:
|
||||
Mesh3DSVertex *_vertexData;
|
||||
uint16 _vertexCount;
|
||||
};
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
|
||||
#endif
|
||||
261
engines/wintermute/base/gfx/tinygl/meshx_tinygl.cpp
Normal file
261
engines/wintermute/base/gfx/tinygl/meshx_tinygl.cpp
Normal file
@@ -0,0 +1,261 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is based on WME.
|
||||
* http://dead-code.org/redir.php?target=wme
|
||||
* Copyright (c) 2003-2013 Jan Nedoma and contributors
|
||||
*/
|
||||
|
||||
#include "engines/wintermute/base/gfx/xmaterial.h"
|
||||
#include "engines/wintermute/base/gfx/3deffect.h"
|
||||
#include "engines/wintermute/base/gfx/3deffect_params.h"
|
||||
#include "engines/wintermute/base/gfx/skin_mesh_helper.h"
|
||||
#include "engines/wintermute/base/base_game.h"
|
||||
#include "engines/wintermute/base/base_engine.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "engines/wintermute/base/gfx/tinygl/base_surface_tinygl.h"
|
||||
#include "engines/wintermute/base/gfx/tinygl/base_render_tinygl.h"
|
||||
#include "engines/wintermute/base/gfx/tinygl/meshx_tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
XMeshTinyGL::XMeshTinyGL(BaseGame *inGame) : XMesh(inGame) {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
XMeshTinyGL::~XMeshTinyGL() {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool XMeshTinyGL::render(XModel *model) {
|
||||
if (!_blendedMesh)
|
||||
return false;
|
||||
|
||||
// For WME DX, mesh model is not visible, possible it's clipped.
|
||||
// For OpenGL, mesh is visible, skip draw it here instead in core.
|
||||
if (!_game->_renderer3D->_camera)
|
||||
return false;
|
||||
|
||||
auto fvf = _blendedMesh->getFVF();
|
||||
uint32 vertexSize = DXGetFVFVertexSize(fvf) / sizeof(float);
|
||||
float *vertexData = (float *)_blendedMesh->getVertexBuffer().ptr();
|
||||
if (vertexData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
uint32 offset = 0, normalOffset = 0, textureOffset = 0;
|
||||
if (fvf & DXFVF_XYZ) {
|
||||
offset += sizeof(DXVector3) / sizeof(float);
|
||||
}
|
||||
if (fvf & DXFVF_NORMAL) {
|
||||
normalOffset = offset;
|
||||
offset += sizeof(DXVector3) / sizeof(float);
|
||||
}
|
||||
if (fvf & DXFVF_DIFFUSE) {
|
||||
offset += sizeof(DXColorValue) / sizeof(float);
|
||||
}
|
||||
if (fvf & DXFVF_TEX1) {
|
||||
textureOffset = offset;
|
||||
}
|
||||
uint32 *indexData = (uint32 *)_blendedMesh->getIndexBuffer().ptr();
|
||||
|
||||
bool noAttrs = false;
|
||||
auto attrsTable = _blendedMesh->getAttributeTable();
|
||||
uint32 numAttrs = attrsTable->_size;
|
||||
DXAttributeRange *attrs;
|
||||
if (numAttrs == 0) {
|
||||
noAttrs = true;
|
||||
numAttrs = 1;
|
||||
attrs = new DXAttributeRange[numAttrs];
|
||||
} else {
|
||||
attrs = attrsTable->_ptr;
|
||||
}
|
||||
|
||||
if (noAttrs) {
|
||||
attrs[0]._attribId = 0;
|
||||
attrs[0]._vertexStart = attrs[0]._faceStart = 0;
|
||||
attrs[0]._vertexCount = _blendedMesh->getNumVertices();
|
||||
attrs[0]._faceCount = _blendedMesh->getNumFaces();
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < numAttrs; i++) {
|
||||
Material *mat = _materials[attrs[i]._attribId];
|
||||
bool textureEnable = false;
|
||||
if (mat->getSurface()) {
|
||||
textureEnable = true;
|
||||
tglEnable(TGL_TEXTURE_2D);
|
||||
static_cast<BaseSurfaceTinyGL *>(mat->getSurface())->setTexture();
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_LINEAR);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR_MIPMAP_LINEAR);
|
||||
} else {
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
if (mat->getEffect()) {
|
||||
renderEffect(mat);
|
||||
} else {
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_DIFFUSE, mat->_material._diffuse._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_AMBIENT, mat->_material._diffuse._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_SPECULAR, mat->_material._specular._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_EMISSION, mat->_material._emissive._data);
|
||||
tglMaterialf(TGL_FRONT_AND_BACK, TGL_SHININESS, mat->_material._power);
|
||||
}
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_NORMAL_ARRAY);
|
||||
if (textureEnable)
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, vertexSize * sizeof(float), vertexData);
|
||||
tglNormalPointer(TGL_FLOAT, vertexSize * sizeof(float), vertexData + normalOffset);
|
||||
if (textureEnable)
|
||||
tglTexCoordPointer(2, TGL_FLOAT, vertexSize * sizeof(float), vertexData + textureOffset);
|
||||
|
||||
tglDrawElements(TGL_TRIANGLES, attrsTable->_ptr[i]._faceCount * 3, TGL_UNSIGNED_INT, indexData + attrsTable->_ptr[i]._faceStart * 3);
|
||||
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_NORMAL_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
|
||||
if (noAttrs) {
|
||||
delete[] attrs;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XMeshTinyGL::renderFlatShadowModel(uint32 shadowColor) {
|
||||
if (!_blendedMesh)
|
||||
return false;
|
||||
|
||||
// For WME DX, mesh model is not visible, possible it's clipped.
|
||||
// For OpenGL, mesh is visible, skip draw it here instead in core.
|
||||
if (!_game->_renderer3D->_camera)
|
||||
return false;
|
||||
|
||||
// W/A for the scene with the table in the laboratory where the engine switches to flat shadows.
|
||||
// Presumably, it's supposed to disable shadows.
|
||||
// Instead, OpenGL draws graphical glitches.
|
||||
// Original DX version does not have this issue due to rendering shadows differently.
|
||||
if (BaseEngine::instance().getGameId() == "alphapolaris")
|
||||
return false;
|
||||
|
||||
uint32 vertexSize = DXGetFVFVertexSize(_blendedMesh->getFVF()) / sizeof(float);
|
||||
float *vertexData = (float *)_blendedMesh->getVertexBuffer().ptr();
|
||||
if (vertexData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
uint32 *indexData = (uint32 *)_blendedMesh->getIndexBuffer().ptr();
|
||||
|
||||
bool noAttrs = false;
|
||||
auto attrsTable = _blendedMesh->getAttributeTable();
|
||||
uint32 numAttrs = attrsTable->_size;
|
||||
DXAttributeRange *attrs;
|
||||
if (numAttrs == 0) {
|
||||
noAttrs = true;
|
||||
numAttrs = 1;
|
||||
attrs = new DXAttributeRange[numAttrs];
|
||||
} else {
|
||||
attrs = attrsTable->_ptr;
|
||||
}
|
||||
|
||||
if (noAttrs) {
|
||||
attrs[0]._attribId = 0;
|
||||
attrs[0]._vertexStart = attrs[0]._faceStart = 0;
|
||||
attrs[0]._vertexCount = _blendedMesh->getNumVertices();
|
||||
attrs[0]._faceCount = _blendedMesh->getNumFaces();
|
||||
}
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
|
||||
tglDisable(TGL_LIGHTING);
|
||||
tglShadeModel(TGL_FLAT);
|
||||
|
||||
tglColorMask(TGL_FALSE, TGL_FALSE, TGL_FALSE, TGL_FALSE);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
tglEnable(TGL_STENCIL_TEST);
|
||||
tglStencilFunc(TGL_ALWAYS, 1, 0xff);
|
||||
tglStencilOp(TGL_REPLACE, TGL_REPLACE, TGL_REPLACE);
|
||||
|
||||
for (uint32 i = 0; i < numAttrs; i++) {
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, vertexSize * sizeof(float), vertexData);
|
||||
|
||||
tglDrawElements(TGL_TRIANGLES, attrsTable->_ptr[i]._faceCount * 3, TGL_UNSIGNED_INT, indexData + attrsTable->_ptr[i]._faceStart * 3);
|
||||
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
|
||||
tglStencilFunc(TGL_EQUAL, 1, 0xff);
|
||||
tglStencilOp(TGL_ZERO, TGL_ZERO, TGL_ZERO);
|
||||
|
||||
tglColor4ub(RGBCOLGetR(shadowColor), RGBCOLGetG(shadowColor), RGBCOLGetB(shadowColor), RGBCOLGetA(shadowColor));
|
||||
tglColorMask(TGL_TRUE, TGL_TRUE, TGL_TRUE, TGL_TRUE);
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
tglDepthMask(TGL_TRUE);
|
||||
|
||||
for (uint32 i = 0; i < numAttrs; i++) {
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, vertexSize * sizeof(float), vertexData);
|
||||
|
||||
tglDrawElements(TGL_TRIANGLES, attrsTable->_ptr[i]._faceCount * 3, TGL_UNSIGNED_INT, indexData + attrsTable->_ptr[i]._faceStart * 3);
|
||||
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
if (noAttrs) {
|
||||
delete[] attrs;
|
||||
}
|
||||
|
||||
tglDisable(TGL_BLEND);
|
||||
tglDisable(TGL_STENCIL_TEST);
|
||||
tglShadeModel(TGL_SMOOTH);
|
||||
tglEnable(TGL_LIGHTING);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void XMeshTinyGL::renderEffect(Material *material) {
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_DIFFUSE, material->_material._diffuse._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_AMBIENT, material->_material._diffuse._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_SPECULAR, material->_material._specular._data);
|
||||
tglMaterialfv(TGL_FRONT_AND_BACK, TGL_EMISSION, material->_material._emissive._data);
|
||||
tglMaterialf(TGL_FRONT_AND_BACK, TGL_SHININESS, material->_material._power);
|
||||
}
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
58
engines/wintermute/base/gfx/tinygl/meshx_tinygl.h
Normal file
58
engines/wintermute/base/gfx/tinygl/meshx_tinygl.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is based on WME.
|
||||
* http://dead-code.org/redir.php?target=wme
|
||||
* Copyright (c) 2003-2013 Jan Nedoma and contributors
|
||||
*/
|
||||
|
||||
#ifndef WINTERMUTE_XMESH_TINYGL_H
|
||||
#define WINTERMUTE_XMESH_TINYGL_H
|
||||
|
||||
#include "engines/wintermute/base/gfx/xmesh.h"
|
||||
|
||||
class Effect3D;
|
||||
class Effect3DParams;
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class XMeshTinyGL : public XMesh {
|
||||
public:
|
||||
XMeshTinyGL(BaseGame *inGame);
|
||||
~XMeshTinyGL() override;
|
||||
|
||||
bool render(XModel *model) override;
|
||||
bool renderFlatShadowModel(uint32 shadowColor) override;
|
||||
|
||||
private:
|
||||
void renderEffect(Material *material);
|
||||
};
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
|
||||
#endif
|
||||
195
engines/wintermute/base/gfx/tinygl/shadow_volume_tinygl.cpp
Normal file
195
engines/wintermute/base/gfx/tinygl/shadow_volume_tinygl.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is based on WME.
|
||||
* http://dead-code.org/redir.php?target=wme
|
||||
* Copyright (c) 2003-2013 Jan Nedoma and contributors
|
||||
*/
|
||||
|
||||
#include "engines/wintermute/base/base_game.h"
|
||||
#include "engines/wintermute/dcgf.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "engines/wintermute/base/gfx/tinygl/base_render_tinygl.h"
|
||||
#include "engines/wintermute/base/gfx/tinygl/shadow_volume_tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
ShadowVolumeTinyGL::ShadowVolumeTinyGL(BaseGame *inGame) : ShadowVolume(inGame) {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
ShadowVolumeTinyGL::~ShadowVolumeTinyGL() {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool ShadowVolumeTinyGL::render() {
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
_game->_renderer3D->_lastTexture = nullptr;
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _vertices.getData());
|
||||
tglDrawArrays(TGL_TRIANGLES, 0, _vertices.getSize());
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool ShadowVolumeTinyGL::renderToStencilBuffer() {
|
||||
// Disable z-buffer/color writes (note: z-testing still occurs), and enable the
|
||||
// stencil-buffer
|
||||
tglDepthMask(TGL_FALSE);
|
||||
tglColorMask(TGL_FALSE, TGL_FALSE, TGL_FALSE, TGL_FALSE);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
tglDisable(TGL_LIGHTING);
|
||||
tglEnable(TGL_STENCIL_TEST);
|
||||
tglEnable(TGL_CULL_FACE);
|
||||
|
||||
// Set up stencil compare fuction, reference value, and masks.
|
||||
// Stencil test passes if ((ref & mask) cmpfn (stencil & mask)) is true.
|
||||
// Note: since we set up the stencil-test to always pass, the STENCILFAIL
|
||||
// renderstate is really not needed.
|
||||
tglStencilFunc(TGL_ALWAYS, 0x1, 0xff);
|
||||
|
||||
tglShadeModel(TGL_FLAT);
|
||||
|
||||
tglStencilOp(TGL_KEEP, TGL_KEEP, TGL_INCR);
|
||||
|
||||
// Draw back-side of shadow volume in stencil/z only
|
||||
tglFrontFace(TGL_CCW);
|
||||
render();
|
||||
|
||||
// Decrement stencil buffer value
|
||||
tglStencilOp(TGL_KEEP, TGL_KEEP, TGL_DECR);
|
||||
|
||||
// Draw front-side of shadow volume in stencil/z only
|
||||
tglFrontFace(TGL_CW);
|
||||
render();
|
||||
|
||||
// Restore render states
|
||||
tglEnable(TGL_LIGHTING);
|
||||
tglFrontFace(TGL_CCW);
|
||||
tglShadeModel(TGL_SMOOTH);
|
||||
tglDepthMask(TGL_TRUE);
|
||||
tglColorMask(TGL_TRUE, TGL_TRUE, TGL_TRUE, TGL_TRUE);
|
||||
tglDisable(TGL_STENCIL_TEST);
|
||||
tglDisable(TGL_BLEND);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool ShadowVolumeTinyGL::renderToScene() {
|
||||
initMask();
|
||||
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglEnable(TGL_STENCIL_TEST);
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Only write where stencil val >= 1 (count indicates # of shadows that overlap that pixel)
|
||||
tglStencilFunc(TGL_LEQUAL, 0x1, 0xff);
|
||||
tglStencilOp(TGL_KEEP, TGL_KEEP, TGL_KEEP);
|
||||
|
||||
tglDisable(TGL_FOG);
|
||||
tglDisable(TGL_LIGHTING);
|
||||
tglDisable(TGL_ALPHA_TEST);
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
|
||||
BaseRenderTinyGL *renderer = (BaseRenderTinyGL *)_game->_renderer3D;
|
||||
renderer->setProjection2D();
|
||||
|
||||
// FIXME: CW->CCW Why it differ from OpenGL?
|
||||
tglFrontFace(TGL_CCW);
|
||||
|
||||
tglEnableClientState(TGL_COLOR_ARRAY);
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
// Draw a big, gray square
|
||||
tglVertexPointer(3, TGL_FLOAT, sizeof(ShadowVertex), &_shadowMask[0].x);
|
||||
tglColorPointer(4, TGL_UNSIGNED_BYTE, sizeof(ShadowVertex), &_shadowMask[0].r);
|
||||
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
tglDisableClientState(TGL_COLOR_ARRAY);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
// Restore render states
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglDisable(TGL_STENCIL_TEST);
|
||||
|
||||
_game->_renderer3D->setup3D(nullptr, true);
|
||||
|
||||
// clear stencil buffer
|
||||
tglClearStencil(0);
|
||||
tglClear(TGL_STENCIL_BUFFER_BIT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool ShadowVolumeTinyGL::initMask() {
|
||||
auto *rend = _game->_renderer3D;
|
||||
|
||||
// bottom left
|
||||
_shadowMask[0].x = 0.0f;
|
||||
_shadowMask[0].y = rend->getHeight();
|
||||
_shadowMask[0].z = 1.0f;
|
||||
|
||||
// top left
|
||||
_shadowMask[1].x = 0.0f;
|
||||
_shadowMask[1].y = 0.0f;
|
||||
_shadowMask[1].z = 1.0f;
|
||||
|
||||
// bottom right
|
||||
_shadowMask[2].x = rend->getWidth();
|
||||
_shadowMask[2].y = rend->getHeight();
|
||||
_shadowMask[2].z = 1.0f;
|
||||
|
||||
// top right
|
||||
_shadowMask[3].x = rend->getWidth();
|
||||
_shadowMask[3].y = 0.0f;
|
||||
_shadowMask[3].z = 1.0f;
|
||||
|
||||
byte a = RGBCOLGetA(_color);
|
||||
byte r = RGBCOLGetR(_color);
|
||||
byte g = RGBCOLGetG(_color);
|
||||
byte b = RGBCOLGetB(_color);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_shadowMask[i].r = r;
|
||||
_shadowMask[i].g = g;
|
||||
_shadowMask[i].b = b;
|
||||
_shadowMask[i].a = a;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
57
engines/wintermute/base/gfx/tinygl/shadow_volume_tinygl.h
Normal file
57
engines/wintermute/base/gfx/tinygl/shadow_volume_tinygl.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is based on WME.
|
||||
* http://dead-code.org/redir.php?target=wme
|
||||
* Copyright (c) 2003-2013 Jan Nedoma and contributors
|
||||
*/
|
||||
|
||||
#ifndef WINTERMUTE_SHADOW_VOLUME_TINYGL_H
|
||||
#define WINTERMUTE_SHADOW_VOLUME_TINYGL_H
|
||||
|
||||
#include "engines/wintermute/base/gfx/3dshadow_volume.h"
|
||||
|
||||
#if defined(USE_TINYGL)
|
||||
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class ShadowVolumeTinyGL : public ShadowVolume {
|
||||
public:
|
||||
ShadowVolumeTinyGL(BaseGame *inGame);
|
||||
virtual ~ShadowVolumeTinyGL();
|
||||
|
||||
bool renderToStencilBuffer() override;
|
||||
bool renderToScene() override;
|
||||
|
||||
private:
|
||||
bool render();
|
||||
ShadowVertex _shadowMask[4]{};
|
||||
bool initMask() override;
|
||||
};
|
||||
|
||||
} // namespace Wintermute
|
||||
|
||||
#endif // defined(USE_TINYGL)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user