Convert stateutil to Context

Fits better into the new DI architecture.
This commit is contained in:
Vsevolod Kremianskii 2021-05-22 13:24:42 +07:00
parent 0619449409
commit abe9aabc96
39 changed files with 215 additions and 307 deletions

View file

@ -162,6 +162,7 @@ set(GRAPHICS_HEADERS
src/engine/graphics/aabb.h
src/engine/graphics/baryutil.h
src/engine/graphics/beziercurve.h
src/engine/graphics/context.h
src/engine/graphics/cursor.h
src/engine/graphics/eventhandler.h
src/engine/graphics/featureutil.h
@ -189,7 +190,6 @@ set(GRAPHICS_HEADERS
src/engine/graphics/renderbuffer.h
src/engine/graphics/services.h
src/engine/graphics/shader/shaders.h
src/engine/graphics/stateutil.h
src/engine/graphics/texture/curreader.h
src/engine/graphics/texture/texture.h
src/engine/graphics/texture/textures.h
@ -207,6 +207,7 @@ set(GRAPHICS_HEADERS
set(GRAPHICS_SOURCES
src/engine/graphics/aabb.cpp
src/engine/graphics/context.cpp
src/engine/graphics/cursor.cpp
src/engine/graphics/featureutil.cpp
src/engine/graphics/font.cpp
@ -233,7 +234,6 @@ set(GRAPHICS_SOURCES
src/engine/graphics/shader/shaders_common.cpp
src/engine/graphics/shader/shaders_pbr.cpp
src/engine/graphics/shader/shaders_phong.cpp
src/engine/graphics/stateutil.cpp
src/engine/graphics/texture/curreader.cpp
src/engine/graphics/texture/texture.cpp
src/engine/graphics/texture/textures.cpp

View file

@ -205,7 +205,7 @@ void Console::trimOutput() {
}
}
void Console::load() {
void Console::init() {
_font = _game->services().graphics().fonts().get("fnt_console");
}

View file

@ -44,7 +44,7 @@ class Console : boost::noncopyable {
public:
Console(Game *game);
void load();
void init();
bool handle(const SDL_Event &event);
void draw();

View file

@ -19,10 +19,8 @@
#include <stdexcept>
#include "../common/guardutil.h"
#include "../common/streamutil.h"
#include "../graphics/texture/curreader.h"
#include "../resource/resources.h"
using namespace std;
@ -53,17 +51,10 @@ static unordered_map<CursorType, pair<uint32_t, uint32_t>> g_namesByResRefSteamT
{ CursorType::Attack, { 53, 54 } }
};
Cursors::Cursors(GameID gameId, Window *window, Shaders *shaders, Meshes *meshes, Resources *resources) :
Cursors::Cursors(GameID gameId, GraphicsServices &graphics, ResourceServices &resource) :
_gameId(gameId),
_window(window),
_shaders(shaders),
_meshes(meshes),
_resources(resources) {
ensureNotNull(window, "window");
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
ensureNotNull(resources, "resources");
_graphics(graphics),
_resource(resource) {
}
Cursors::~Cursors() {
@ -83,7 +74,7 @@ shared_ptr<Cursor> Cursors::get(CursorType type) {
shared_ptr<Texture> up(newTexture(names.first));
shared_ptr<Texture> down(newTexture(names.second));
auto cursor = make_shared<Cursor>(up, down, _window, _shaders, _meshes);
auto cursor = make_shared<Cursor>(up, down, _graphics);
auto inserted = _cache.insert(make_pair(type, cursor));
return inserted.first->second;
@ -103,7 +94,7 @@ const pair<uint32_t, uint32_t> &Cursors::getCursorNames(CursorType type, const u
}
shared_ptr<Texture> Cursors::newTexture(uint32_t name) {
shared_ptr<ByteArray> data(_resources->getFromExe(name, PEResourceType::Cursor));
shared_ptr<ByteArray> data(_resource.resources().getFromExe(name, PEResourceType::Cursor));
CurReader curFile;
curFile.load(wrap(data));

View file

@ -23,10 +23,8 @@
#include <boost/noncopyable.hpp>
#include "../graphics/cursor.h"
#include "../graphics/texture/texture.h"
#include "../graphics/window.h"
#include "../resource/types.h"
#include "../graphics/services.h"
#include "../resource/services.h"
#include "types.h"
@ -36,7 +34,7 @@ namespace game {
class Cursors : boost::noncopyable {
public:
Cursors(GameID gameId, graphics::Window *window, graphics::Shaders *shaders, graphics::Meshes *meshes, resource::Resources *resources);
Cursors(GameID gameId, graphics::GraphicsServices &graphics, resource::ResourceServices &resources);
~Cursors();
void deinit();
@ -45,10 +43,8 @@ public:
private:
GameID _gameId;
graphics::Window *_window;
graphics::Shaders *_shaders;
graphics::Meshes *_meshes;
resource::Resources *_resources;
graphics::GraphicsServices &_graphics;
resource::ResourceServices &_resource;
std::unordered_map<CursorType, std::shared_ptr<graphics::Cursor>> _cache;

View file

@ -95,7 +95,10 @@ void Game::init() {
_graphics.walkmeshes().setWalkableSurfaces(_game->surfaces().getWalkableSurfaceIndices());
_console = make_unique<Console>(this);
_console->init();
_profileOverlay = make_unique<ProfileOverlay>(_graphics);
_profileOverlay->init();
loadModuleNames();
setCursorType(CursorType::Default);
@ -137,7 +140,7 @@ void Game::playVideo(const string &name) {
fs::path path(getPathIgnoreCase(_path, "movies/" + name + ".bik"));
if (path.empty()) return;
BikReader bik(path, &_graphics.shaders(), &_graphics.meshes());
BikReader bik(path, _graphics);
bik.load();
_video = bik.video();

View file

@ -20,11 +20,11 @@
#include <unordered_map>
#include "../../common/guardutil.h"
#include "../../graphics/context.h"
#include "../../graphics/font.h"
#include "../../graphics/fonts.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/texture.h"
#include "../../graphics/texture/textures.h"
#include "../../graphics/window.h"
@ -269,7 +269,7 @@ void SelectionOverlay::draw() {
}
void SelectionOverlay::drawReticle(Texture &texture, const glm::vec3 &screenCoords) {
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
texture.bind();
const GraphicsOptions &opts = _game->options().graphics;
@ -364,7 +364,7 @@ void SelectionOverlay::drawActionFrame(int index) {
} else {
frameTexture = _friendlyScroll;
}
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
frameTexture->bind();
float frameX, frameY;
@ -400,7 +400,7 @@ void SelectionOverlay::drawActionIcon(int index) {
shared_ptr<Texture> texture(_textureByAction.find(action)->second);
if (!texture) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
texture->bind();
float frameX, frameY;

View file

@ -27,8 +27,8 @@
#include "../common/log.h"
#include "../common/guardutil.h"
#include "../graphics/context.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/stateutil.h"
#include "../graphics/texture/textures.h"
#include "../graphics/window.h"
#include "../resource/types.h"
@ -98,7 +98,7 @@ void Map::drawArea(Mode mode, const glm::vec4 &bounds) {
shared_ptr<Creature> partyLeader(_game->services().party().getLeader());
if (!partyLeader) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_areaTexture->bind();
glm::vec2 worldPos(partyLeader->position());
@ -119,10 +119,10 @@ void Map::drawArea(Mode mode, const glm::vec4 &bounds) {
int height = _game->options().graphics.height;
glm::ivec4 scissorBounds(bounds[0], height - (bounds[1] + bounds[3]), bounds[2], bounds[3]);
withScissorTest(scissorBounds, [&]() { _game->services().graphics().meshes().quad().draw(); });
_game->services().graphics().context().withScissorTest(scissorBounds, [&]() { _game->services().graphics().meshes().quad().draw(); });
} else {
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_areaTexture->bind();
glm::mat4 transform(1.0f);
@ -141,7 +141,7 @@ void Map::drawArea(Mode mode, const glm::vec4 &bounds) {
void Map::drawNotes(Mode mode, const glm::vec4 &bounds) {
if (mode != Mode::Default) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_noteTexture->bind();
for (auto &object : _game->module()->area()->getObjectsByType(ObjectType::Waypoint)) {
@ -204,7 +204,7 @@ void Map::drawPartyLeader(Mode mode, const glm::vec4 &bounds) {
shared_ptr<Creature> partyLeader(_game->services().party().getLeader());
if (!partyLeader) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_game->services().graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_arrowTexture->bind();
glm::vec3 arrowPos(0.0f);

View file

@ -55,7 +55,7 @@ void GameServices::init() {
_surfaces = make_unique<Surfaces>(&_resource.resources());
_surfaces->init();
_cursors = make_unique<Cursors>(_game->gameId(), &_graphics.window(), &_graphics.shaders(), &_graphics.meshes(), &_resource.resources());
_cursors = make_unique<Cursors>(_game->gameId(), _graphics, _resource);
_soundSets = make_unique<SoundSets>(&_audio.files(), &_resource.resources(), &_resource.strings());
_footstepSounds = make_unique<FootstepSounds>(&_audio.files(), &_resource.resources());

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "stateutil.h"
#include "context.h"
#include "GL/glew.h"
#include "SDL2/SDL_opengl.h"
@ -26,18 +26,13 @@ namespace reone {
namespace graphics {
static bool g_depthTest { false };
static bool g_backFaceCulling { false };
static int g_textureUnit { 0 };
static uint32_t g_polygonMode { 0 };
void withWireframes(const function<void()> &block) {
void Context::withWireframes(const function<void()> &block) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
block();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
void withViewport(const glm::ivec4 &viewport, const function<void()> &block) {
void Context::withViewport(const glm::ivec4 &viewport, const function<void()> &block) {
int oldViewport[4];
glGetIntegerv(GL_VIEWPORT, &oldViewport[0]);
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
@ -47,7 +42,7 @@ void withViewport(const glm::ivec4 &viewport, const function<void()> &block) {
glViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
}
void withScissorTest(const glm::ivec4 &bounds, const function<void()> &block) {
void Context::withScissorTest(const glm::ivec4 &bounds, const function<void()> &block) {
glEnable(GL_SCISSOR_TEST);
glScissor(bounds[0], bounds[1], bounds[2], bounds[3]);
glClear(GL_COLOR_BUFFER_BIT);
@ -57,20 +52,20 @@ void withScissorTest(const glm::ivec4 &bounds, const function<void()> &block) {
glDisable(GL_SCISSOR_TEST);
}
void withDepthTest(const function<void()> &block) {
void Context::withDepthTest(const function<void()> &block) {
setDepthTestEnabled(true);
block();
setDepthTestEnabled(false);
}
void setDepthTestEnabled(bool enabled) {
if (g_depthTest != enabled) {
void Context::setDepthTestEnabled(bool enabled) {
if (_depthTest != enabled) {
if (enabled) {
glEnable(GL_DEPTH_TEST);
} else {
glDisable(GL_DEPTH_TEST);
}
g_depthTest = enabled;
_depthTest = enabled;
}
}
@ -87,7 +82,7 @@ static void withBlendFunc(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAl
glBlendFuncSeparate(blendSrcRgb, blendDstRgb, blendSrcAlpha, blendDstAlpha);
}
void withAdditiveBlending(const function<void()> &block) {
void Context::withAdditiveBlending(const function<void()> &block) {
withBlendFunc(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE, block);
}
@ -102,31 +97,31 @@ static void withBlendEquation(GLenum modeRGB, GLenum modeAlpha, const function<v
glBlendEquationSeparate(startModeRGB, startModeAlpha);
}
void withLightenBlending(const function<void()> &block) {
void Context::withLightenBlending(const function<void()> &block) {
withBlendEquation(GL_MAX, GL_FUNC_ADD, block);
}
void withBackFaceCulling(const function<void()> &block) {
void Context::withBackFaceCulling(const function<void()> &block) {
setBackFaceCullingEnabled(true);
block();
setBackFaceCullingEnabled(false);
}
void setBackFaceCullingEnabled(bool enabled) {
if (g_backFaceCulling != enabled) {
void Context::setBackFaceCullingEnabled(bool enabled) {
if (_backFaceCulling != enabled) {
if (enabled) {
glEnable(GL_CULL_FACE);
} else {
glDisable(GL_CULL_FACE);
}
g_backFaceCulling = enabled;
_backFaceCulling = enabled;
}
}
void setActiveTextureUnit(int n) {
if (g_textureUnit != n) {
void Context::setActiveTextureUnit(int n) {
if (_textureUnit != n) {
glActiveTexture(GL_TEXTURE0 + n);
g_textureUnit = n;
_textureUnit = n;
}
}

View file

@ -17,25 +17,37 @@
#pragma once
#include <cstdint>
#include <functional>
#include <boost/noncopyable.hpp>
#include "glm/vec4.hpp"
namespace reone {
namespace graphics {
void withWireframes(const std::function<void()> &block);
void withViewport(const glm::ivec4 &viewport, const std::function<void()> &block);
void withScissorTest(const glm::ivec4 &bounds, const std::function<void()> &block);
void withDepthTest(const std::function<void()> &block);
void withAdditiveBlending(const std::function<void()> &block);
void withLightenBlending(const std::function<void()> &block);
void withBackFaceCulling(const std::function<void()> &block);
class Context : boost::noncopyable {
public:
void withWireframes(const std::function<void()> &block);
void withViewport(const glm::ivec4 &viewport, const std::function<void()> &block);
void withScissorTest(const glm::ivec4 &bounds, const std::function<void()> &block);
void withDepthTest(const std::function<void()> &block);
void withAdditiveBlending(const std::function<void()> &block);
void withLightenBlending(const std::function<void()> &block);
void withBackFaceCulling(const std::function<void()> &block);
void setDepthTestEnabled(bool enabled);
void setBackFaceCullingEnabled(bool enabled);
void setActiveTextureUnit(int n);
void setDepthTestEnabled(bool enabled);
void setBackFaceCullingEnabled(bool enabled);
void setActiveTextureUnit(int n);
private:
bool _depthTest { false };
bool _backFaceCulling { false };
int _textureUnit { 0 };
uint32_t _polygonMode { 0 };
};
} // namespace graphics

View file

@ -24,8 +24,7 @@
#include "../common/guardutil.h"
#include "stateutil.h"
#include "window.h"
#include "services.h"
using namespace std;
@ -33,17 +32,18 @@ namespace reone {
namespace graphics {
Cursor::Cursor(shared_ptr<Texture> up, shared_ptr<Texture> down, Window *window, Shaders *shaders, Meshes *meshes) :
_up(up), _down(down), _window(window), _shaders(shaders), _meshes(meshes) {
Cursor::Cursor(shared_ptr<Texture> up, shared_ptr<Texture> down, GraphicsServices &graphics) :
_up(up),
_down(down),
_graphics(graphics) {
ensureNotNull(window, "window");
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
ensureNotNull(up, "up");
ensureNotNull(down, "down");
}
void Cursor::draw() {
shared_ptr<Texture> texture(_pressed ? _down : _up);
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
texture->bind();
glm::mat4 transform(1.0f);
@ -51,19 +51,11 @@ void Cursor::draw() {
transform = glm::scale(transform, glm::vec3(texture->width(), texture->height(), 1.0f));
ShaderUniforms uniforms;
uniforms.combined.general.projection = _window->getOrthoProjection();
uniforms.combined.general.projection = _graphics.window().getOrthoProjection();
uniforms.combined.general.model = move(transform);
_shaders->activate(ShaderProgram::SimpleGUI, uniforms);
_meshes->quad().draw();
}
void Cursor::setPosition(const glm::ivec2 &position) {
_position = position;
}
void Cursor::setPressed(bool pressed) {
_pressed = pressed;
_graphics.shaders().activate(ShaderProgram::SimpleGUI, uniforms);
_graphics.meshes().quad().draw();
}
} // namespace graphics

View file

@ -23,36 +23,30 @@
#include "glm/vec2.hpp"
#include "mesh/meshes.h"
#include "shader/shaders.h"
#include "texture/textures.h"
#include "texture/texture.h"
namespace reone {
namespace graphics {
class Window;
class GraphicsServices;
class Cursor : boost::noncopyable {
public:
Cursor(
std::shared_ptr<Texture> up,
std::shared_ptr<Texture> down,
Window *window,
Shaders *shaders,
Meshes *meshes);
GraphicsServices &graphics);
void draw();
void setPosition(const glm::ivec2 &position);
void setPressed(bool pressed);
void setPosition(glm::ivec2 position) { _position = std::move(position); }
void setPressed(bool pressed) { _pressed = pressed; }
private:
std::shared_ptr<Texture> _up;
std::shared_ptr<Texture> _down;
Window *_window;
Shaders *_shaders;
Meshes *_meshes;
GraphicsServices &_graphics;
glm::ivec2 _position { 0 };
bool _pressed { false };

View file

@ -24,12 +24,7 @@
#include "glm/ext.hpp"
#include "../common/guardutil.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/window.h"
#include "shader/shaders.h"
#include "stateutil.h"
#include "services.h"
using namespace std;
@ -37,13 +32,7 @@ namespace reone {
namespace graphics {
Font::Font(Window *window, Shaders *shaders, Meshes *meshes) :
_window(window),
_shaders(shaders),
_meshes(meshes) {
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
Font::Font(GraphicsServices &graphics) : _graphics(graphics) {
}
void Font::load(shared_ptr<Texture> texture) {
@ -74,14 +63,14 @@ void Font::load(shared_ptr<Texture> texture) {
void Font::draw(const string &text, const glm::vec3 &position, const glm::vec3 &color, TextGravity gravity) {
if (text.empty()) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
_texture->bind();
glm::vec3 textOffset(getTextOffset(text, gravity), 0.0f);
ShaderUniforms uniforms(_shaders->defaultUniforms());
ShaderUniforms uniforms(_graphics.shaders().defaultUniforms());
uniforms.combined.featureMask |= UniformFeatureFlags::text;
uniforms.combined.general.projection = _window->getOrthoProjection();
uniforms.combined.general.projection = _graphics.window().getOrthoProjection();
uniforms.combined.general.color = glm::vec4(color, 1.0f);
int numBlocks = static_cast<int>(text.size()) / kMaxCharacters;
@ -104,8 +93,8 @@ void Font::draw(const string &text, const glm::vec3 &position, const glm::vec3 &
textOffset.x += glyph.size.x;
}
_shaders->activate(ShaderProgram::TextText, uniforms);
_meshes->quad().drawInstanced(numChars);
_graphics.shaders().activate(ShaderProgram::TextText, uniforms);
_graphics.meshes().quad().drawInstanced(numChars);
}
}

View file

@ -23,8 +23,6 @@
#include "glm/vec2.hpp"
#include "glm/vec3.hpp"
#include "mesh/meshes.h"
#include "shader/shaders.h"
#include "texture/texture.h"
namespace reone {
@ -41,11 +39,11 @@ enum class TextGravity {
RightTop
};
class Window;
class GraphicsServices;
class Font {
public:
Font(Window *window, Shaders *shaders, Meshes *meshes);
Font(GraphicsServices &services);
void load(std::shared_ptr<Texture> texture);
@ -66,9 +64,7 @@ private:
glm::vec2 size { 0.0f };
};
Window *_window;
Shaders *_shaders;
Meshes *_meshes;
GraphicsServices &_graphics;
std::shared_ptr<Texture> _texture;
float _height { 0.0f };

View file

@ -17,14 +17,7 @@
#include "fonts.h"
#include <stdexcept>
#include "../common/guardutil.h"
#include "../common/streamutil.h"
#include "../resource/resources.h"
#include "font.h"
#include "texture/textures.h"
#include "services.h"
using namespace std;
using namespace std::placeholders;
@ -39,17 +32,9 @@ static unordered_map<string, string> g_fontOverride = {
{ "fnt_d16x16", "fnt_d16x16b" }
};
Fonts::Fonts(Window *window, Shaders *shaders, Meshes *meshes, Textures *textures) :
Fonts::Fonts(GraphicsServices &graphics) :
MemoryCache(bind(&Fonts::doGet, this, _1)),
_window(window),
_shaders(shaders),
_meshes(meshes),
_textures(textures) {
ensureNotNull(window, "window");
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
ensureNotNull(textures, "textures");
_graphics(graphics) {
}
shared_ptr<Font> Fonts::doGet(string resRef) {
@ -57,10 +42,10 @@ shared_ptr<Font> Fonts::doGet(string resRef) {
if (maybeOverride != g_fontOverride.end()) {
resRef = maybeOverride->second;
}
shared_ptr<Texture> texture(_textures->get(resRef, TextureUsage::GUI));
shared_ptr<Texture> texture(_graphics.textures().get(resRef, TextureUsage::GUI));
if (!texture) return nullptr;
auto font = make_shared<Font>(_window, _shaders, _meshes);
auto font = make_shared<Font>(_graphics);
font->load(texture);
return move(font);

View file

@ -20,26 +20,21 @@
#include <string>
#include "../common/cache.h"
#include "../resource/types.h"
#include "font.h"
#include "texture/textures.h"
#include "types.h"
#include "window.h"
namespace reone {
namespace graphics {
class GraphicsServices;
class Fonts : public MemoryCache<std::string, Font> {
public:
Fonts(Window *window, Shaders *shaders, Meshes *meshes, Textures *textures);
Fonts(GraphicsServices &graphics);
private:
Window *_window;
Shaders *_shaders;
Meshes *_meshes;
Textures *_textures;
GraphicsServices &_graphics;
std::shared_ptr<Font> doGet(std::string resRef);
};

View file

@ -24,12 +24,8 @@
#include "glm/ext.hpp"
#include "../common/guardutil.h"
#include "mesh/meshes.h"
#include "renderbuffer.h"
#include "shader/shaders.h"
#include "stateutil.h"
#include "services.h"
#include "texture/texture.h"
#include "texture/textureutil.h"
@ -52,9 +48,7 @@ static const glm::mat4 g_captureViews[] {
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
};
PBRIBL::PBRIBL(Shaders *shaders, Meshes *meshes) : _shaders(shaders), _meshes(meshes) {
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
PBRIBL::PBRIBL(GraphicsServices &graphics) : _graphics(graphics) {
}
void PBRIBL::init() {
@ -115,10 +109,10 @@ shared_ptr<Texture> PBRIBL::computeIrradianceMap(const Texture *envmap) {
_irradianceFB.bind();
setActiveTextureUnit(TextureUnits::environmentMap);
_graphics.context().setActiveTextureUnit(TextureUnits::environmentMap);
envmap->bind();
withViewport(viewport, [&]() {
_graphics.context().withViewport(viewport, [&]() {
for (int i = 0; i < kNumCubeFaces; ++i) {
_irradianceFB.attachCubeMapFaceAsColor(*irradianceColor, static_cast<CubeMapFace>(i));
_irradianceFB.attachDepth(*irradianceDepth);
@ -129,8 +123,8 @@ shared_ptr<Texture> PBRIBL::computeIrradianceMap(const Texture *envmap) {
uniforms.combined.general.view = g_captureViews[i];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shaders->activate(ShaderProgram::SimpleIrradiance, uniforms);
_meshes->cubemap().draw();
_graphics.shaders().activate(ShaderProgram::SimpleIrradiance, uniforms);
_graphics.meshes().cubemap().draw();
}
});
@ -152,7 +146,7 @@ shared_ptr<Texture> PBRIBL::computePrefilterMap(const Texture *envmap) {
_prefilterFB.bind();
_prefilterFB.attachDepth(*prefilterDepth);
setActiveTextureUnit(TextureUnits::environmentMap);
_graphics.context().setActiveTextureUnit(TextureUnits::environmentMap);
envmap->bind();
for (int mip = 0; mip < kNumPrefilterMipMaps; ++mip) {
@ -163,20 +157,20 @@ shared_ptr<Texture> PBRIBL::computePrefilterMap(const Texture *envmap) {
float roughness = mip / static_cast<float>(kNumPrefilterMipMaps - 1);
withViewport(viewport, [&]() {
_graphics.context().withViewport(viewport, [&]() {
for (int face = 0; face < kNumCubeFaces; ++face) {
_prefilterFB.attachCubeMapFaceAsColor(*prefilterColor, static_cast<CubeMapFace>(face), 0, mip);
_prefilterFB.checkCompleteness();
ShaderUniforms uniforms(_shaders->defaultUniforms());
ShaderUniforms uniforms(_graphics.shaders().defaultUniforms());
uniforms.combined.general.projection = g_captureProjection;
uniforms.combined.general.view = g_captureViews[face];
uniforms.combined.general.roughness = roughness;
uniforms.combined.general.envmapResolution = static_cast<float>(envmap->width());
_shaders->activate(ShaderProgram::SimplePrefilter, uniforms);
_graphics.shaders().activate(ShaderProgram::SimplePrefilter, uniforms);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_meshes->cubemap().draw();
_graphics.meshes().cubemap().draw();
}
});
}
@ -204,10 +198,10 @@ shared_ptr<Texture> PBRIBL::computeBRDFLookup(const Texture *envmap) {
_brdfLookupFB.attachDepth(*brdfLookupDepth);
_brdfLookupFB.checkCompleteness();
withViewport(viewport, [&]() {
_graphics.context().withViewport(viewport, [&]() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shaders->activate(ShaderProgram::SimpleBRDF, _shaders->defaultUniforms());
_meshes->quadNDC().draw();
_graphics.shaders().activate(ShaderProgram::SimpleBRDF, _graphics.shaders().defaultUniforms());
_graphics.meshes().quadNDC().draw();
});
_brdfLookupFB.unbind();

View file

@ -25,14 +25,14 @@
#include <boost/noncopyable.hpp>
#include "framebuffer.h"
#include "mesh/meshes.h"
#include "shader/shaders.h"
#include "texture/texture.h"
namespace reone {
namespace graphics {
class GraphicsServices;
/**
* Computes and caches PBR IBL textures, i.e. irradiance maps, prefiltered
* environment maps and BRDF lookup textures.
@ -45,7 +45,7 @@ public:
std::shared_ptr<Texture> brdfLookup;
};
PBRIBL(Shaders *shaders, Meshes *meshes);
PBRIBL(GraphicsServices &graphics);
~PBRIBL();
void init();
@ -66,8 +66,7 @@ public:
bool getDerived(const Texture *envmap, Derived &derived);
private:
Shaders *_shaders;
Meshes *_meshes;
GraphicsServices &_graphics;
bool _inited { false };
std::set<const Texture *> _envmapQueue;

View file

@ -34,10 +34,12 @@ void GraphicsServices::init() {
_window = make_unique<Window>(_options);
_window->init();
_context = make_unique<Context>();
_meshes = make_unique<Meshes>();
_meshes->init();
_textures = make_unique<Textures>(&_resource.resources());
_textures = make_unique<Textures>(*this, _resource);
_textures->init();
_materials = make_unique<Materials>(&_resource.resources());
@ -50,10 +52,10 @@ void GraphicsServices::init() {
_shaders = make_unique<Shaders>();
_shaders->init();
_pbrIbl = make_unique<PBRIBL>(_shaders.get(), _meshes.get());
_pbrIbl = make_unique<PBRIBL>(*this);
_pbrIbl->init();
_fonts = make_unique<Fonts>(_window.get(), _shaders.get(), _meshes.get(), _textures.get());
_fonts = make_unique<Fonts>(*this);
}
} // namespace graphics

View file

@ -23,6 +23,7 @@
#include "../resource/services.h"
#include "context.h"
#include "fonts.h"
#include "lip/lips.h"
#include "materials.h"
@ -45,6 +46,7 @@ public:
void init();
Context &context() { return *_context; }
Fonts &fonts() { return *_fonts; }
Lips &lips() { return *_lips; }
Materials &materials() { return *_materials; }
@ -60,6 +62,7 @@ private:
GraphicsOptions _options;
resource::ResourceServices &_resource;
std::unique_ptr<Context> _context;
std::unique_ptr<Fonts> _fonts;
std::unique_ptr<Lips> _lips;
std::unique_ptr<Materials> _materials;

View file

@ -19,12 +19,10 @@
#include <boost/algorithm/string.hpp>
#include "../../common/guardutil.h"
#include "../../common/log.h"
#include "../../common/streamutil.h"
#include "../../resource/resources.h"
#include "../stateutil.h"
#include "../services.h"
#include "../types.h"
#include "curreader.h"
@ -41,8 +39,7 @@ namespace reone {
namespace graphics {
Textures::Textures(Resources *resources) : _resources(resources) {
ensureNotNull(resources, "resources");
Textures::Textures(GraphicsServices &graphics, ResourceServices &resource) : _graphics(graphics), _resource(resource) {
}
void Textures::init() {
@ -64,34 +61,34 @@ void Textures::invalidateCache() {
}
void Textures::bindDefaults() {
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
_default->bind();
setActiveTextureUnit(TextureUnits::lightmap);
_graphics.context().setActiveTextureUnit(TextureUnits::lightmap);
_default->bind();
setActiveTextureUnit(TextureUnits::environmentMap);
_graphics.context().setActiveTextureUnit(TextureUnits::environmentMap);
_defaultCubemap->bind();
setActiveTextureUnit(TextureUnits::bumpMap);
_graphics.context().setActiveTextureUnit(TextureUnits::bumpMap);
_default->bind();
setActiveTextureUnit(TextureUnits::bloom);
_graphics.context().setActiveTextureUnit(TextureUnits::bloom);
_default->bind();
setActiveTextureUnit(TextureUnits::irradianceMap);
_graphics.context().setActiveTextureUnit(TextureUnits::irradianceMap);
_defaultCubemap->bind();
setActiveTextureUnit(TextureUnits::prefilterMap);
_graphics.context().setActiveTextureUnit(TextureUnits::prefilterMap);
_defaultCubemap->bind();
setActiveTextureUnit(TextureUnits::brdfLookup);
_graphics.context().setActiveTextureUnit(TextureUnits::brdfLookup);
_default->bind();
setActiveTextureUnit(TextureUnits::shadowMap);
_graphics.context().setActiveTextureUnit(TextureUnits::shadowMap);
_default->bind();
setActiveTextureUnit(TextureUnits::shadowMapCube);
_graphics.context().setActiveTextureUnit(TextureUnits::shadowMapCube);
_defaultCubemap->bind();
}
@ -111,14 +108,14 @@ shared_ptr<Texture> Textures::get(const string &resRef, TextureUsage usage) {
shared_ptr<Texture> Textures::doGet(const string &resRef, TextureUsage usage) {
shared_ptr<Texture> texture;
shared_ptr<ByteArray> tgaData(_resources->getRaw(resRef, ResourceType::Tga, false));
shared_ptr<ByteArray> tgaData(_resource.resources().getRaw(resRef, ResourceType::Tga, false));
if (tgaData) {
TgaReader tga(resRef, usage);
tga.load(wrap(tgaData));
texture = tga.texture();
if (texture) {
shared_ptr<ByteArray> txiData(_resources->getRaw(resRef, ResourceType::Txi, false));
shared_ptr<ByteArray> txiData(_resource.resources().getRaw(resRef, ResourceType::Txi, false));
if (txiData) {
TxiReader txi;
txi.load(wrap(txiData));
@ -128,7 +125,7 @@ shared_ptr<Texture> Textures::doGet(const string &resRef, TextureUsage usage) {
}
if (!texture) {
shared_ptr<ByteArray> tpcData(_resources->getRaw(resRef, ResourceType::Tpc, false));
shared_ptr<ByteArray> tpcData(_resource.resources().getRaw(resRef, ResourceType::Tpc, false));
if (tpcData) {
TpcReader tpc(resRef, usage);
tpc.load(wrap(tpcData));

View file

@ -23,20 +23,21 @@
#include <boost/noncopyable.hpp>
#include "../../resource/resources.h"
#include "../../resource/types.h"
#include "../../resource/services.h"
#include "../types.h"
#include "texture.h"
namespace reone {
namespace graphics {
class Texture;
class GraphicsServices;
class Textures : boost::noncopyable {
public:
Textures(resource::Resources *resources);
Textures(GraphicsServices &graphics, resource::ResourceServices &resources);
void init();
void invalidateCache();
@ -49,7 +50,8 @@ public:
std::shared_ptr<Texture> get(const std::string &resRef, TextureUsage usage = TextureUsage::Default);
private:
resource::Resources *_resources;
GraphicsServices &_graphics;
resource::ResourceServices &_resource;
std::shared_ptr<graphics::Texture> _default;
std::shared_ptr<graphics::Texture> _defaultCubemap;

View file

@ -25,7 +25,6 @@
#include "../../graphics/fonts.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/textures.h"
#include "../../graphics/textutil.h"
#include "../../graphics/window.h"
@ -264,12 +263,12 @@ void Control::drawBorder(const Border &border, const glm::ivec2 &offset, const g
_gui->graphics().shaders().activate(ShaderProgram::SimpleGUI, uniforms);
}
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
border.fill->bind();
bool additive = border.fill->isAdditive();
if (additive) {
withAdditiveBlending([&]() {
_gui->graphics().context().withAdditiveBlending([&]() {
_gui->graphics().meshes().quad().draw();
});
} else {
@ -280,7 +279,7 @@ void Control::drawBorder(const Border &border, const glm::ivec2 &offset, const g
int width = size.x - 2 * border.dimension;
int height = size.y - 2 * border.dimension;
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
border.edge->bind();
if (height > 0.0f) {
@ -357,7 +356,7 @@ void Control::drawBorder(const Border &border, const glm::ivec2 &offset, const g
int x = _extent.left + offset.x;
int y = _extent.top + offset.y;
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
border.corner->bind();
// Top left corner

View file

@ -19,7 +19,6 @@
#include "../../graphics/fonts.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/stateutil.h"
#include "../gui.h"
@ -86,7 +85,7 @@ void ImageButton::drawIcon(
}
if (iconFrame) {
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
iconFrame->bind();
glm::mat4 transform(1.0f);
@ -103,7 +102,7 @@ void ImageButton::drawIcon(
}
if (iconTexture) {
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
iconTexture->bind();
glm::mat4 transform(1.0f);

View file

@ -18,7 +18,6 @@
#include "progressbar.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/textures.h"
#include "../gui.h"
@ -48,7 +47,7 @@ void ProgressBar::load(const GffStruct &gffs) {
void ProgressBar::draw(const glm::ivec2 &offset, const vector<string> &text) {
if (_value == 0 || !_progress.fill) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_progress.fill->bind();
float w = _extent.width * _value / 100.0f;

View file

@ -19,7 +19,6 @@
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/textures.h"
#include "../../resource/resources.h"
@ -61,7 +60,7 @@ void ScrollBar::draw(const glm::ivec2 &offset, const vector<string> &text) {
void ScrollBar::drawThumb(const glm::ivec2 &offset) {
if (!_thumb.image || _state.numVisible >= _state.count) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_thumb.image->bind();
ShaderUniforms uniforms;
@ -108,7 +107,7 @@ void ScrollBar::drawArrows(const glm::ivec2 &offset) {
bool canScrollDown = _state.count - _state.offset > _state.numVisible;
if (!canScrollUp && !canScrollDown) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_gui->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_dir.image->bind();
if (canScrollUp) {

View file

@ -22,7 +22,6 @@
#include "../common/log.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/shader/shaders.h"
#include "../graphics/stateutil.h"
#include "../graphics/texture/textures.h"
#include "../resource/resources.h"
@ -259,7 +258,7 @@ void GUI::draw3D() {
}
void GUI::drawBackground() {
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
_background->bind();
glm::mat4 transform(1.0f);

View file

@ -27,7 +27,6 @@
#include "../../common/random.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../scenegraph.h"
@ -282,12 +281,12 @@ void EmitterSceneNode::drawElements(const vector<shared_ptr<SceneNodeElement>> &
_sceneGraph->graphics().shaders().activate(ShaderProgram::ParticleParticle, uniforms);
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
texture->bind();
bool lighten = emitter->blendMode == ModelNode::Emitter::BlendMode::Lighten;
if (lighten) {
withLightenBlending([&]() {
_sceneGraph->graphics().context().withLightenBlending([&]() {
_sceneGraph->graphics().meshes().billboard().drawInstanced(count);
});
} else {

View file

@ -22,7 +22,6 @@
#include "../../common/guardutil.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../scenegraph.h"
@ -57,14 +56,14 @@ void GrassSceneNode::drawElements(const vector<shared_ptr<SceneNodeElement>> &el
count = static_cast<int>(elements.size());
}
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_texture->bind();
ShaderUniforms uniforms(_sceneGraph->uniformsPrototype());
uniforms.combined.featureMask |= UniformFeatureFlags::grass;
if (_lightmap) {
setActiveTextureUnit(TextureUnits::lightmap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::lightmap);
_lightmap->bind();
uniforms.combined.featureMask |= UniformFeatureFlags::lightmap;

View file

@ -24,7 +24,6 @@
#include "../../common/guardutil.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/window.h"
#include "../scenegraph.h"
@ -56,7 +55,7 @@ void LightSceneNode::drawLensFlares(const ModelNode::LensFlare &flare) {
shared_ptr<CameraSceneNode> camera(_sceneGraph->activeCamera());
if (!camera) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
flare.texture->bind();
glm::vec4 lightPos(_absTransform[3]);
@ -85,7 +84,7 @@ void LightSceneNode::drawLensFlares(const ModelNode::LensFlare &flare) {
_sceneGraph->graphics().shaders().activate(ShaderProgram::SimpleGUI, uniforms);
withAdditiveBlending([&]() {
_sceneGraph->graphics().context().withAdditiveBlending([&]() {
_sceneGraph->graphics().meshes().billboard().draw();
});
}

View file

@ -27,7 +27,6 @@
#include "../../common/random.h"
#include "../../graphics/featureutil.h"
#include "../../graphics/pbribl.h"
#include "../../graphics/stateutil.h"
#include "../scenegraph.h"
@ -372,36 +371,36 @@ void MeshSceneNode::drawSingle(bool shadowPass) {
// Setup textures
if (_nodeTextures.diffuse) {
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_nodeTextures.diffuse->bind();
additive = _nodeTextures.diffuse->isAdditive();
}
if (_nodeTextures.lightmap) {
setActiveTextureUnit(TextureUnits::lightmap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::lightmap);
_nodeTextures.lightmap->bind();
}
if (_nodeTextures.envmap) {
setActiveTextureUnit(TextureUnits::environmentMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::environmentMap);
_nodeTextures.envmap->bind();
PBRIBL::Derived derived;
if (_sceneGraph->graphics().pbrIbl().getDerived(_nodeTextures.envmap.get(), derived)) {
setActiveTextureUnit(TextureUnits::irradianceMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::irradianceMap);
derived.irradianceMap->bind();
setActiveTextureUnit(TextureUnits::prefilterMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::prefilterMap);
derived.prefilterMap->bind();
setActiveTextureUnit(TextureUnits::brdfLookup);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::brdfLookup);
derived.brdfLookup->bind();
}
}
if (_nodeTextures.bumpmap) {
setActiveTextureUnit(TextureUnits::bumpMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::bumpMap);
_nodeTextures.bumpmap->bind();
}
if (additive) {
withAdditiveBlending([&mesh]() { mesh->mesh->draw(); });
_sceneGraph->graphics().context().withAdditiveBlending([&mesh]() { mesh->mesh->draw(); });
} else {
mesh->mesh->draw();
}

View file

@ -24,7 +24,6 @@
#include "../../common/guardutil.h"
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/textures.h"
#include "../../graphics/texture/textureutil.h"
@ -71,7 +70,7 @@ void ControlRenderPipeline::init() {
void ControlRenderPipeline::render(const glm::ivec2 &offset) {
// Render to framebuffer
withViewport(glm::ivec4(0, 0, _extent[2], _extent[3]), [this]() {
_sceneGraph->graphics().context().withViewport(glm::ivec4(0, 0, _extent[2], _extent[3]), [this]() {
_geometry.bind();
ShaderUniforms uniforms(_sceneGraph->graphics().shaders().defaultUniforms());
@ -81,7 +80,7 @@ void ControlRenderPipeline::render(const glm::ivec2 &offset) {
_sceneGraph->setUniformsPrototype(move(uniforms));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
withDepthTest([this]() { _sceneGraph->draw(); });
_sceneGraph->graphics().context().withDepthTest([this]() { _sceneGraph->draw(); });
_geometry.unbind();
});
@ -89,7 +88,7 @@ void ControlRenderPipeline::render(const glm::ivec2 &offset) {
// Render control
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_geometryColor->bind();
int viewport[4];

View file

@ -26,7 +26,6 @@
#include "../../graphics/mesh/meshes.h"
#include "../../graphics/pbribl.h"
#include "../../graphics/shader/shaders.h"
#include "../../graphics/stateutil.h"
#include "../../graphics/texture/textures.h"
#include "../../graphics/texture/textureutil.h"
#include "../../graphics/window.h"
@ -191,7 +190,7 @@ void WorldRenderPipeline::drawShadows() {
const LightSceneNode *shadowLight = _sceneGraph->shadowLight();
if (!shadowLight) return;
withViewport(glm::ivec4(0, 0, 1024 * _opts.shadowResolution, 1024 * _opts.shadowResolution), [&]() {
_sceneGraph->graphics().context().withViewport(glm::ivec4(0, 0, 1024 * _opts.shadowResolution, 1024 * _opts.shadowResolution), [&]() {
_shadows.bind();
if (shadowLight->isDirectional()) {
_shadows.attachDepth(*_shadowsDepth);
@ -215,7 +214,7 @@ void WorldRenderPipeline::drawShadows() {
_sceneGraph->setUniformsPrototype(move(uniforms));
glClear(GL_DEPTH_BUFFER_BIT);
withDepthTest([this]() { _sceneGraph->draw(true); });
_sceneGraph->graphics().context().withDepthTest([this]() { _sceneGraph->draw(true); });
});
}
@ -250,10 +249,10 @@ void WorldRenderPipeline::drawGeometry() {
if (shadowLight) {
if (shadowLight->isDirectional()) {
setActiveTextureUnit(TextureUnits::shadowMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::shadowMap);
_shadowsDepth->bind();
} else {
setActiveTextureUnit(TextureUnits::shadowMapCube);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::shadowMapCube);
_cubeShadowsDepth->bind();
}
}
@ -261,11 +260,11 @@ void WorldRenderPipeline::drawGeometry() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (g_wireframesEnabled) {
withWireframes([this]() {
withDepthTest([this]() { _sceneGraph->draw(); });
_sceneGraph->graphics().context().withWireframes([this]() {
_sceneGraph->graphics().context().withDepthTest([this]() { _sceneGraph->draw(); });
});
} else {
withDepthTest([this]() { _sceneGraph->draw(); });
_sceneGraph->graphics().context().withDepthTest([this]() { _sceneGraph->draw(); });
}
}
@ -277,7 +276,7 @@ void WorldRenderPipeline::applyHorizontalBlur() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_geometryColor2->bind();
ShaderUniforms uniforms;
@ -287,7 +286,7 @@ void WorldRenderPipeline::applyHorizontalBlur() {
_sceneGraph->graphics().shaders().activate(ShaderProgram::SimpleBlur, uniforms);
withDepthTest([&]() {
_sceneGraph->graphics().context().withDepthTest([&]() {
_sceneGraph->graphics().meshes().quadNDC().draw();
});
}
@ -300,7 +299,7 @@ void WorldRenderPipeline::applyVerticalBlur() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_horizontalBlurColor->bind();
ShaderUniforms uniforms;
@ -310,7 +309,7 @@ void WorldRenderPipeline::applyVerticalBlur() {
_sceneGraph->graphics().shaders().activate(ShaderProgram::SimpleBlur, uniforms);
withDepthTest([&]() {
_sceneGraph->graphics().context().withDepthTest([&]() {
_sceneGraph->graphics().meshes().quadNDC().draw();
});
@ -318,10 +317,10 @@ void WorldRenderPipeline::applyVerticalBlur() {
}
void WorldRenderPipeline::drawResult() {
setActiveTextureUnit(TextureUnits::diffuseMap);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::diffuseMap);
_geometryColor1->bind();
setActiveTextureUnit(TextureUnits::bloom);
_sceneGraph->graphics().context().setActiveTextureUnit(TextureUnits::bloom);
_verticalBlurColor->bind();
ShaderUniforms uniforms;

View file

@ -23,7 +23,6 @@
#include "glm/gtx/transform.hpp"
#include "../graphics/mesh/meshes.h"
#include "../graphics/stateutil.h"
#include "node/cameranode.h"
#include "node/emitternode.h"
@ -289,7 +288,7 @@ void SceneGraph::draw(bool shadowPass) {
return;
}
setBackFaceCullingEnabled(true);
_graphics.context().setBackFaceCullingEnabled(true);
// Render opaque meshes
for (auto &mesh : _opaqueMeshes) {
@ -314,7 +313,7 @@ void SceneGraph::draw(bool shadowPass) {
mesh->drawSingle(false);
}
setBackFaceCullingEnabled(false);
_graphics.context().setBackFaceCullingEnabled(false);
// Render particles and grass clusters
for (auto &nodeLeaf : _elements) {

View file

@ -52,13 +52,9 @@ static const char kSignature[] = "BIKi";
class BinkVideoDecoder : public MediaStream<Video::Frame> {
public:
BinkVideoDecoder(fs::path path, Shaders *shaders, Meshes *meshes) :
_path(std::move(path)),
_shaders(shaders),
_meshes(meshes) {
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
BinkVideoDecoder(fs::path path, GraphicsServices &graphics) :
_path(move(path)),
_graphics(graphics) {
}
~BinkVideoDecoder() {
@ -126,8 +122,7 @@ public:
private:
fs::path _path;
Shaders *_shaders;
Meshes *_meshes;
graphics::GraphicsServices &_graphics;
AVFormatContext *_formatCtx { nullptr };
int _videoStreamIdx { -1 };
@ -235,7 +230,7 @@ private:
void initVideo() {
AVRational &frameRate = _formatCtx->streams[_videoStreamIdx]->r_frame_rate;
_video = make_shared<Video>(_shaders, _meshes);
_video = make_shared<Video>(_graphics);
_video->_width = _videoCodecCtx->width;
_video->_height = _videoCodecCtx->height;
_video->_fps = frameRate.num / static_cast<float>(frameRate.den);
@ -326,13 +321,9 @@ private:
}
};
BikReader::BikReader(fs::path path, Shaders *shaders, Meshes *meshes) :
BikReader::BikReader(fs::path path, GraphicsServices &graphics) :
_path(move(path)),
_shaders(shaders),
_meshes(meshes) {
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
_graphics(graphics) {
}
void BikReader::load() {
@ -340,7 +331,7 @@ void BikReader::load() {
throw runtime_error("BIK: file not found: " + _path.string());
}
auto decoder = make_shared<BinkVideoDecoder>(_path, _shaders, _meshes);
auto decoder = make_shared<BinkVideoDecoder>(_path, _graphics);
decoder->load();
_video = decoder->video();

View file

@ -20,8 +20,7 @@
#include <boost/filesystem/path.hpp>
#include "../audio/types.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/shader/shaders.h"
#include "../graphics/services.h"
namespace reone {
@ -36,7 +35,7 @@ class Video;
*/
class BikReader {
public:
BikReader(boost::filesystem::path path, graphics::Shaders *shaders, graphics::Meshes *meshes);
BikReader(boost::filesystem::path path, graphics::GraphicsServices &graphics);
void load();
@ -44,8 +43,7 @@ public:
private:
boost::filesystem::path _path;
graphics::Shaders *_shaders;
graphics::Meshes *_meshes;
graphics::GraphicsServices &_graphics;
std::shared_ptr<Video> _video;
};

View file

@ -27,7 +27,6 @@
#include "../common/guardutil.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/shader/shaders.h"
#include "../graphics/stateutil.h"
#include "../graphics/texture/textureutil.h"
using namespace std;
@ -39,9 +38,7 @@ namespace reone {
namespace video {
Video::Video(Shaders *shaders, Meshes *meshes) : _shaders(shaders), _meshes(meshes) {
ensureNotNull(shaders, "shaders");
ensureNotNull(meshes, "meshes");
Video::Video(GraphicsServices &graphics) : _graphics(graphics) {
}
void Video::init() {
@ -80,7 +77,7 @@ void Video::updateFrame(float dt) {
void Video::updateFrameTexture() {
if (!_frame) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
_texture->bind();
_texture->setPixels(_width, _height, PixelFormat::RGB, _frame->pixels);
}
@ -88,20 +85,12 @@ void Video::updateFrameTexture() {
void Video::draw() {
if (!_inited) return;
setActiveTextureUnit(TextureUnits::diffuseMap);
_graphics.context().setActiveTextureUnit(TextureUnits::diffuseMap);
_texture->bind();
ShaderUniforms uniforms;
_shaders->activate(ShaderProgram::SimpleGUI, uniforms);
_meshes->quadNDCFlipY().draw();
}
void Video::finish() {
_finished = true;
}
void Video::setMediaStream(const shared_ptr<MediaStream<Frame>> &stream) {
_stream = stream;
_graphics.shaders().activate(ShaderProgram::SimpleGUI, uniforms);
_graphics.meshes().quadNDCFlipY().draw();
}
} // namespace video

View file

@ -23,9 +23,7 @@
#include "../audio/stream.h"
#include "../common/mediastream.h"
#include "../common/types.h"
#include "../graphics/mesh/meshes.h"
#include "../graphics/shader/shaders.h"
#include "../graphics/texture/texture.h"
#include "../graphics/services.h"
namespace reone {
@ -39,7 +37,7 @@ public:
std::shared_ptr<ByteArray> pixels;
};
Video(graphics::Shaders *shaders, graphics::Meshes *meshes);
Video(graphics::GraphicsServices &graphics);
void init();
void deinit();
@ -47,17 +45,16 @@ public:
void update(float dt);
void draw();
void finish();
void finish() { _finished = true; }
bool isFinished() const { return _finished; }
std::shared_ptr<audio::AudioStream> audio() const { return _audio; }
void setMediaStream(const std::shared_ptr<MediaStream<Frame>> &stream);
void setMediaStream(std::shared_ptr<MediaStream<Frame>> stream) { _stream = std::move(stream); }
private:
graphics::Shaders *_shaders;
graphics::Meshes *_meshes;
graphics::GraphicsServices &_graphics;
int _width { 0 };
int _height { 0 };