mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
Convert Renderer to unique_ptr
This commit is contained in:
parent
c49b4bbd50
commit
9e4e97a58e
@ -57,12 +57,12 @@ void DebugDraw::drawContactPoint(const btVector3 &pointOnB,
|
|||||||
RW_UNUSED(color);
|
RW_UNUSED(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDraw::flush(GameRenderer *renderer) {
|
void DebugDraw::flush(GameRenderer &renderer) {
|
||||||
if (lines.empty()) {
|
if (lines.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer->getRenderer()->useProgram(shaderProgram);
|
renderer.getRenderer().useProgram(shaderProgram);
|
||||||
|
|
||||||
lineBuff->uploadVertices(lines);
|
lineBuff->uploadVertices(lines);
|
||||||
dbuff->addGeometry(lineBuff.get());
|
dbuff->addGeometry(lineBuff.get());
|
||||||
@ -75,9 +75,9 @@ void DebugDraw::flush(GameRenderer *renderer) {
|
|||||||
dp.count = lines.size();
|
dp.count = lines.size();
|
||||||
dp.diffuse = 1.f;
|
dp.diffuse = 1.f;
|
||||||
|
|
||||||
renderer->getRenderer()->drawArrays(glm::mat4(1.f), dbuff.get(), dp);
|
renderer.getRenderer().drawArrays(glm::mat4(1.f), dbuff.get(), dp);
|
||||||
|
|
||||||
renderer->getRenderer()->invalidate();
|
renderer.getRenderer().invalidate();
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
void setDebugMode(int debugMode) override;
|
void setDebugMode(int debugMode) override;
|
||||||
int getDebugMode() const override;
|
int getDebugMode() const override;
|
||||||
|
|
||||||
void flush(GameRenderer *renderer);
|
void flush(GameRenderer &renderer);
|
||||||
|
|
||||||
void setShaderProgram(Renderer::ShaderProgram *shaderProgram) {
|
void setShaderProgram(Renderer::ShaderProgram *shaderProgram) {
|
||||||
this->shaderProgram = shaderProgram;
|
this->shaderProgram = shaderProgram;
|
||||||
|
@ -43,9 +43,9 @@ struct ParticleVert {
|
|||||||
GameRenderer::GameRenderer(Logger* log, GameData* _data)
|
GameRenderer::GameRenderer(Logger* log, GameData* _data)
|
||||||
: data(_data)
|
: data(_data)
|
||||||
, logger(log)
|
, logger(log)
|
||||||
, map(renderer, _data)
|
, map(*renderer, _data)
|
||||||
, water(this)
|
, water(*this)
|
||||||
, text(this) {
|
, text(*this) {
|
||||||
logger->info("Renderer", renderer->getIDString());
|
logger->info("Renderer", renderer->getIDString());
|
||||||
|
|
||||||
worldProg =
|
worldProg =
|
||||||
@ -171,7 +171,7 @@ GameRenderer::~GameRenderer() {
|
|||||||
|
|
||||||
void GameRenderer::setupRender() {
|
void GameRenderer::setupRender() {
|
||||||
// Set the viewport
|
// Set the viewport
|
||||||
const glm::ivec2& vp = getRenderer()->getViewport();
|
const glm::ivec2& vp = getRenderer().getViewport();
|
||||||
glViewport(0, 0, vp.x, vp.y);
|
glViewport(0, 0, vp.x, vp.y);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);
|
glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
@ -239,7 +239,7 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
|||||||
|
|
||||||
renderer->pushDebugGroup("Water");
|
renderer->pushDebugGroup("Water");
|
||||||
|
|
||||||
water.render(this, world);
|
water.render(*this, world);
|
||||||
|
|
||||||
profWater = renderer->popDebugGroup();
|
profWater = renderer->popDebugGroup();
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class GameRenderer {
|
|||||||
Logger* logger;
|
Logger* logger;
|
||||||
|
|
||||||
/** The low-level drawing interface to use */
|
/** The low-level drawing interface to use */
|
||||||
std::shared_ptr<Renderer> renderer = std::make_shared<OpenGLRenderer>();
|
std::unique_ptr<Renderer> renderer = std::make_unique<OpenGLRenderer>();
|
||||||
|
|
||||||
// Temporary variables used during rendering
|
// Temporary variables used during rendering
|
||||||
float _renderAlpha{0.f};
|
float _renderAlpha{0.f};
|
||||||
@ -80,8 +80,8 @@ public:
|
|||||||
DrawBuffer skyDbuff;
|
DrawBuffer skyDbuff;
|
||||||
GeometryBuffer skyGbuff;
|
GeometryBuffer skyGbuff;
|
||||||
|
|
||||||
GameData* getData() const {
|
const GameData& getData() const {
|
||||||
return data;
|
return *data;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getCulledCount() {
|
size_t getCulledCount() {
|
||||||
@ -119,8 +119,8 @@ public:
|
|||||||
void setupRender();
|
void setupRender();
|
||||||
void renderPostProcess();
|
void renderPostProcess();
|
||||||
|
|
||||||
std::shared_ptr<Renderer> getRenderer() {
|
Renderer& getRenderer() {
|
||||||
return renderer;
|
return *renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setViewport(int w, int h);
|
void setViewport(int w, int h);
|
||||||
|
@ -46,7 +46,7 @@ void main()
|
|||||||
outColour = vec4(colour.rgb + c.rgb, colour.a * c.a);
|
outColour = vec4(colour.rgb + c.rgb, colour.a * c.a);
|
||||||
})";
|
})";
|
||||||
|
|
||||||
MapRenderer::MapRenderer(std::shared_ptr<Renderer> renderer, GameData* _data)
|
MapRenderer::MapRenderer(Renderer &renderer, GameData* _data)
|
||||||
: data(_data), renderer(renderer) {
|
: data(_data), renderer(renderer) {
|
||||||
rectGeom.uploadVertices<VertexP2>(
|
rectGeom.uploadVertices<VertexP2>(
|
||||||
{{-.5f, -.5f}, {.5f, -.5f}, {.5f, .5f}, {-.5f, .5f}});
|
{{-.5f, -.5f}, {.5f, -.5f}, {.5f, .5f}, {-.5f, .5f}});
|
||||||
@ -64,16 +64,16 @@ MapRenderer::MapRenderer(std::shared_ptr<Renderer> renderer, GameData* _data)
|
|||||||
circle.addGeometry(&circleGeom);
|
circle.addGeometry(&circleGeom);
|
||||||
circle.setFaceType(GL_TRIANGLE_FAN);
|
circle.setFaceType(GL_TRIANGLE_FAN);
|
||||||
|
|
||||||
rectProg = renderer->createShader(MapVertexShader, MapFragmentShader);
|
rectProg = renderer.createShader(MapVertexShader, MapFragmentShader);
|
||||||
|
|
||||||
renderer->setUniform(rectProg.get(), "colour", glm::vec4(1.f));
|
renderer.setUniform(rectProg.get(), "colour", glm::vec4(1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GAME_MAP_SIZE 4000
|
#define GAME_MAP_SIZE 4000
|
||||||
|
|
||||||
void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
||||||
renderer->pushDebugGroup("Map");
|
renderer.pushDebugGroup("Map");
|
||||||
renderer->useProgram(rectProg.get());
|
renderer.useProgram(rectProg.get());
|
||||||
|
|
||||||
Renderer::DrawParameters dp { };
|
Renderer::DrawParameters dp { };
|
||||||
dp.start = 0;
|
dp.start = 0;
|
||||||
@ -87,24 +87,24 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
|||||||
// Determine the scale to show the right number of world units on the screen
|
// Determine the scale to show the right number of world units on the screen
|
||||||
float worldScale = mi.screenSize / mi.worldSize;
|
float worldScale = mi.screenSize / mi.worldSize;
|
||||||
|
|
||||||
auto proj = renderer->get2DProjection();
|
auto proj = renderer.get2DProjection();
|
||||||
glm::mat4 view{1.0f}, model{1.0f};
|
glm::mat4 view{1.0f}, model{1.0f};
|
||||||
renderer->setUniform(rectProg.get(), "proj", proj);
|
renderer.setUniform(rectProg.get(), "proj", proj);
|
||||||
renderer->setUniform(rectProg.get(), "model", glm::mat4(1.0f));
|
renderer.setUniform(rectProg.get(), "model", glm::mat4(1.0f));
|
||||||
renderer->setUniform(rectProg.get(), "colour", glm::vec4(0.f, 0.f, 0.f, 1.f));
|
renderer.setUniform(rectProg.get(), "colour", glm::vec4(0.f, 0.f, 0.f, 1.f));
|
||||||
|
|
||||||
view = glm::translate(view, glm::vec3(mi.screenPosition, 0.f));
|
view = glm::translate(view, glm::vec3(mi.screenPosition, 0.f));
|
||||||
|
|
||||||
if (mi.clipToSize) {
|
if (mi.clipToSize) {
|
||||||
glm::mat4 circleView = glm::scale(view, glm::vec3(mi.screenSize));
|
glm::mat4 circleView = glm::scale(view, glm::vec3(mi.screenSize));
|
||||||
renderer->setUniform(rectProg.get(), "view", circleView);
|
renderer.setUniform(rectProg.get(), "view", circleView);
|
||||||
dp.count = 182;
|
dp.count = 182;
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
glStencilMask(0xFF);
|
glStencilMask(0xFF);
|
||||||
glColorMask(0x00, 0x00, 0x00, 0x00);
|
glColorMask(0x00, 0x00, 0x00, 0x00);
|
||||||
renderer->drawArrays(glm::mat4(1.0f), &circle, dp);
|
renderer.drawArrays(glm::mat4(1.0f), &circle, dp);
|
||||||
glColorMask(0xFF, 0xFF, 0xFF, 0xFF);
|
glColorMask(0xFF, 0xFF, 0xFF, 0xFF);
|
||||||
glStencilFunc(GL_EQUAL, 1, 0xFF);
|
glStencilFunc(GL_EQUAL, 1, 0xFF);
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
|||||||
view = glm::rotate(view, mi.rotation, glm::vec3(0.f, 0.f, 1.f));
|
view = glm::rotate(view, mi.rotation, glm::vec3(0.f, 0.f, 1.f));
|
||||||
view = glm::translate(
|
view = glm::translate(
|
||||||
view, glm::vec3(glm::vec2(-1.f, 1.f) * mi.worldCenter, 0.f));
|
view, glm::vec3(glm::vec2(-1.f, 1.f) * mi.worldCenter, 0.f));
|
||||||
renderer->setUniform(rectProg.get(), "view", view);
|
renderer.setUniform(rectProg.get(), "view", view);
|
||||||
|
|
||||||
// radar00 = -x, +y
|
// radar00 = -x, +y
|
||||||
// incrementing in X, then Y
|
// incrementing in X, then Y
|
||||||
@ -138,13 +138,13 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
|||||||
tilemodel = glm::translate(tilemodel, glm::vec3(tc, 0.f));
|
tilemodel = glm::translate(tilemodel, glm::vec3(tc, 0.f));
|
||||||
tilemodel = glm::scale(tilemodel, glm::vec3(tileSize, 1.f));
|
tilemodel = glm::scale(tilemodel, glm::vec3(tileSize, 1.f));
|
||||||
|
|
||||||
renderer->setUniform(rectProg.get(), "model", tilemodel);
|
renderer.setUniform(rectProg.get(), "model", tilemodel);
|
||||||
|
|
||||||
renderer->drawArrays(glm::mat4(1.0f), &rect, dp);
|
renderer.drawArrays(glm::mat4(1.0f), &rect, dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// From here on out we will work in screenspace
|
// From here on out we will work in screenspace
|
||||||
renderer->setUniform(rectProg.get(), "view", glm::mat4(1.0f));
|
renderer.setUniform(rectProg.get(), "view", glm::mat4(1.0f));
|
||||||
|
|
||||||
if (mi.clipToSize) {
|
if (mi.clipToSize) {
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
@ -157,8 +157,8 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
|||||||
glm::mat4 model{1.0f};
|
glm::mat4 model{1.0f};
|
||||||
model = glm::translate(model, glm::vec3(mi.screenPosition, 0.0f));
|
model = glm::translate(model, glm::vec3(mi.screenPosition, 0.0f));
|
||||||
model = glm::scale(model, glm::vec3(mi.screenSize * 1.07f));
|
model = glm::scale(model, glm::vec3(mi.screenSize * 1.07f));
|
||||||
renderer->setUniform(rectProg.get(), "model", model);
|
renderer.setUniform(rectProg.get(), "model", model);
|
||||||
renderer->drawArrays(glm::mat4(1.0f), &rect, dp);
|
renderer.drawArrays(glm::mat4(1.0f), &rect, dp);
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE,
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE,
|
||||||
GL_ZERO);
|
GL_ZERO);
|
||||||
}
|
}
|
||||||
@ -237,8 +237,8 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @TODO migrate to using the renderer
|
/// @TODO migrate to using the renderer
|
||||||
renderer->invalidate();
|
renderer.invalidate();
|
||||||
renderer->popDebugGroup();
|
renderer.popDebugGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapRenderer::prepareBlip(const glm::vec2& coord, const glm::mat4& view,
|
void MapRenderer::prepareBlip(const glm::vec2& coord, const glm::mat4& view,
|
||||||
@ -260,14 +260,14 @@ void MapRenderer::prepareBlip(const glm::vec2& coord, const glm::mat4& view,
|
|||||||
model = glm::translate(model, viewPos);
|
model = glm::translate(model, viewPos);
|
||||||
model = glm::scale(model, glm::vec3(size));
|
model = glm::scale(model, glm::vec3(size));
|
||||||
model = glm::rotate(model, heading, glm::vec3(0.f, 0.f, 1.f));
|
model = glm::rotate(model, heading, glm::vec3(0.f, 0.f, 1.f));
|
||||||
renderer->setUniform(rectProg.get(), "model", model);
|
renderer.setUniform(rectProg.get(), "model", model);
|
||||||
|
|
||||||
GLuint tex = 0;
|
GLuint tex = 0;
|
||||||
if (!texture.empty()) {
|
if (!texture.empty()) {
|
||||||
auto sprite = data->findSlotTexture("hud", texture);
|
auto sprite = data->findSlotTexture("hud", texture);
|
||||||
tex = sprite->getName();
|
tex = sprite->getName();
|
||||||
}
|
}
|
||||||
renderer->setUniform(rectProg.get(), "colour", colour);
|
renderer.setUniform(rectProg.get(), "colour", colour);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ void MapRenderer::drawBlip(const glm::vec2& coord, const glm::mat4& view,
|
|||||||
const MapInfo& mi, glm::vec4 colour, float size) {
|
const MapInfo& mi, glm::vec4 colour, float size) {
|
||||||
drawBlip(coord, view, mi, "", colour, size);
|
drawBlip(coord, view, mi, "", colour, size);
|
||||||
// Draw outline
|
// Draw outline
|
||||||
renderer->setUniform(rectProg.get(), "colour", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
renderer.setUniform(rectProg.get(), "colour", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ public:
|
|||||||
bool clipToSize = true;
|
bool clipToSize = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
MapRenderer(std::shared_ptr<Renderer> renderer, GameData* data);
|
MapRenderer(Renderer& renderer, GameData* data);
|
||||||
|
|
||||||
void draw(GameWorld* world, const MapInfo& mi);
|
void draw(GameWorld* world, const MapInfo& mi);
|
||||||
void scaleHUD(const float scale);
|
void scaleHUD(const float scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameData* data;
|
GameData* data;
|
||||||
std::shared_ptr<Renderer> renderer;
|
Renderer& renderer;
|
||||||
|
|
||||||
GeometryBuffer rectGeom;
|
GeometryBuffer rectGeom;
|
||||||
DrawBuffer rect;
|
DrawBuffer rect;
|
||||||
|
@ -308,8 +308,8 @@ public:
|
|||||||
float f) override;
|
float f) override;
|
||||||
void useProgram(ShaderProgram* p) override;
|
void useProgram(ShaderProgram* p) override;
|
||||||
|
|
||||||
void clear(const glm::vec4& colour, bool clearColour,
|
void clear(const glm::vec4& colour, bool clearColour = true,
|
||||||
bool clearDepth) override;
|
bool clearDepth = true) override;
|
||||||
|
|
||||||
void setSceneParameters(const SceneUniformData& data) override;
|
void setSceneParameters(const SceneUniformData& data) override;
|
||||||
|
|
||||||
|
@ -142,13 +142,13 @@ struct TextVertex {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TextRenderer::TextRenderer(GameRenderer* renderer) : renderer(renderer) {
|
TextRenderer::TextRenderer(GameRenderer &renderer) : renderer(renderer) {
|
||||||
textShader = renderer->getRenderer()->createShader(TextVertexShader,
|
textShader = renderer.getRenderer().createShader(TextVertexShader,
|
||||||
TextFragmentShader);
|
TextFragmentShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::setFontTexture(font_t font, const std::string& textureName) {
|
void TextRenderer::setFontTexture(font_t font, const std::string& textureName) {
|
||||||
auto ftexture = renderer->getData()->findSlotTexture("fonts", textureName);
|
auto ftexture = renderer.getData().findSlotTexture("fonts", textureName);
|
||||||
const glm::u32vec2 textureSize = ftexture->getSize();
|
const glm::u32vec2 textureSize = ftexture->getSize();
|
||||||
glm::u8vec2 glyphOffset{textureSize.x / 16, textureSize.x / 16};
|
glm::u8vec2 glyphOffset{textureSize.x / 16, textureSize.x / 16};
|
||||||
if (font != FONT_PAGER) {
|
if (font != FONT_PAGER) {
|
||||||
@ -187,8 +187,8 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
|
|||||||
if (ti.text.empty() || ti.text[0] == '*')
|
if (ti.text.empty() || ti.text[0] == '*')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
renderer->getRenderer()->pushDebugGroup("Text");
|
renderer.getRenderer().pushDebugGroup("Text");
|
||||||
renderer->getRenderer()->useProgram(textShader.get());
|
renderer.getRenderer().useProgram(textShader.get());
|
||||||
|
|
||||||
glm::vec2 coord(0.f, 0.f);
|
glm::vec2 coord(0.f, 0.f);
|
||||||
glm::vec2 alignment = ti.screenPosition;
|
glm::vec2 alignment = ti.screenPosition;
|
||||||
@ -331,15 +331,15 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
|
|||||||
|
|
||||||
// If we need to, draw the background.
|
// If we need to, draw the background.
|
||||||
if (colourBG.a > 0.f) {
|
if (colourBG.a > 0.f) {
|
||||||
renderer->drawColour(
|
renderer.drawColour(
|
||||||
colourBG, glm::vec4(ti.screenPosition - (ss / 3.f),
|
colourBG, glm::vec4(ti.screenPosition - (ss / 3.f),
|
||||||
glm::vec2(maxWidth, maxHeight) + (ss / 2.f)));
|
glm::vec2(maxWidth, maxHeight) + (ss / 2.f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer->getRenderer()->setUniform(
|
renderer.getRenderer().setUniform(
|
||||||
textShader.get(), "proj", renderer->getRenderer()->get2DProjection());
|
textShader.get(), "proj", renderer.getRenderer().get2DProjection());
|
||||||
renderer->getRenderer()->setUniformTexture(textShader.get(), "fontTexture", 0);
|
renderer.getRenderer().setUniformTexture(textShader.get(), "fontTexture", 0);
|
||||||
renderer->getRenderer()->setUniform(textShader.get(), "alignment", alignment);
|
renderer.getRenderer().setUniform(textShader.get(), "alignment", alignment);
|
||||||
|
|
||||||
gb.uploadVertices(geo);
|
gb.uploadVertices(geo);
|
||||||
db.addGeometry(&gb);
|
db.addGeometry(&gb);
|
||||||
@ -349,11 +349,11 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
|
|||||||
dp.start = 0;
|
dp.start = 0;
|
||||||
dp.blendMode = BlendMode::BLEND_ALPHA;
|
dp.blendMode = BlendMode::BLEND_ALPHA;
|
||||||
dp.count = gb.getCount();
|
dp.count = gb.getCount();
|
||||||
auto ftexture = renderer->getData()->findSlotTexture("fonts", fontMetaData.textureName);
|
auto ftexture = renderer.getData().findSlotTexture("fonts", fontMetaData.textureName);
|
||||||
dp.textures = {{ftexture->getName()}};
|
dp.textures = {{ftexture->getName()}};
|
||||||
dp.depthMode = DepthMode::OFF;
|
dp.depthMode = DepthMode::OFF;
|
||||||
|
|
||||||
renderer->getRenderer()->drawArrays(glm::mat4(1.0f), &db, dp);
|
renderer.getRenderer().drawArrays(glm::mat4(1.0f), &db, dp);
|
||||||
|
|
||||||
renderer->getRenderer()->popDebugGroup();
|
renderer.getRenderer().popDebugGroup();
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
float widthFrac;
|
float widthFrac;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextRenderer(GameRenderer* renderer);
|
TextRenderer(GameRenderer& renderer);
|
||||||
~TextRenderer() = default;
|
~TextRenderer() = default;
|
||||||
|
|
||||||
void setFontTexture(font_t font, const std::string& textureName);
|
void setFontTexture(font_t font, const std::string& textureName);
|
||||||
@ -89,7 +89,7 @@ private:
|
|||||||
|
|
||||||
std::array<FontMetaData, FONTS_COUNT> fonts;
|
std::array<FontMetaData, FONTS_COUNT> fonts;
|
||||||
|
|
||||||
GameRenderer* renderer;
|
GameRenderer& renderer;
|
||||||
std::unique_ptr<Renderer::ShaderProgram> textShader;
|
std::unique_ptr<Renderer::ShaderProgram> textShader;
|
||||||
|
|
||||||
GeometryBuffer gb;
|
GeometryBuffer gb;
|
||||||
|
@ -13,20 +13,20 @@
|
|||||||
#include "render/GameShaders.hpp"
|
#include "render/GameShaders.hpp"
|
||||||
#include "render/OpenGLRenderer.hpp"
|
#include "render/OpenGLRenderer.hpp"
|
||||||
|
|
||||||
WaterRenderer::WaterRenderer(GameRenderer* renderer) {
|
WaterRenderer::WaterRenderer(GameRenderer &renderer) {
|
||||||
maskDraw.setFaceType(GL_TRIANGLES);
|
maskDraw.setFaceType(GL_TRIANGLES);
|
||||||
gridDraw.setFaceType(GL_TRIANGLES);
|
gridDraw.setFaceType(GL_TRIANGLES);
|
||||||
|
|
||||||
waterProg = renderer->getRenderer()->createShader(
|
waterProg = renderer.getRenderer().createShader(
|
||||||
GameShaders::WaterHQ::VertexShader,
|
GameShaders::WaterHQ::VertexShader,
|
||||||
GameShaders::WaterHQ::FragmentShader);
|
GameShaders::WaterHQ::FragmentShader);
|
||||||
maskProg = renderer->getRenderer()->createShader(
|
maskProg = renderer.getRenderer().createShader(
|
||||||
GameShaders::Mask3D::VertexShader, GameShaders::Mask3D::FragmentShader);
|
GameShaders::Mask3D::VertexShader, GameShaders::Mask3D::FragmentShader);
|
||||||
|
|
||||||
renderer->getRenderer()->setProgramBlockBinding(waterProg.get(), "SceneData", 1);
|
renderer.getRenderer().setProgramBlockBinding(waterProg.get(), "SceneData", 1);
|
||||||
renderer->getRenderer()->setProgramBlockBinding(maskProg.get(), "SceneData", 1);
|
renderer.getRenderer().setProgramBlockBinding(maskProg.get(), "SceneData", 1);
|
||||||
|
|
||||||
renderer->getRenderer()->setUniformTexture(waterProg.get(), "data", 1);
|
renderer.getRenderer().setUniformTexture(waterProg.get(), "data", 1);
|
||||||
|
|
||||||
// Generate grid mesh
|
// Generate grid mesh
|
||||||
int gridres = 60;
|
int gridres = 60;
|
||||||
@ -99,8 +99,8 @@ void WaterRenderer::setDataTexture(GLuint fbBinding, GLuint dataTex) {
|
|||||||
dataTexture = dataTex;
|
dataTexture = dataTex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterRenderer::render(GameRenderer* renderer, GameWorld* world) {
|
void WaterRenderer::render(GameRenderer &renderer, GameWorld* world) {
|
||||||
auto r = renderer->getRenderer();
|
auto& r = renderer.getRenderer();
|
||||||
|
|
||||||
auto waterTex = world->data->findSlotTexture("particle", "water_old");
|
auto waterTex = world->data->findSlotTexture("particle", "water_old");
|
||||||
RW_CHECK(waterTex != nullptr, "Water texture is null");
|
RW_CHECK(waterTex != nullptr, "Water texture is null");
|
||||||
@ -126,30 +126,30 @@ void WaterRenderer::render(GameRenderer* renderer, GameWorld* world) {
|
|||||||
glDrawBuffers(1, buffers);
|
glDrawBuffers(1, buffers);
|
||||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
r->useProgram(maskProg.get());
|
r.useProgram(maskProg.get());
|
||||||
|
|
||||||
r->drawArrays(m, &maskDraw, wdp);
|
r.drawArrays(m, &maskDraw, wdp);
|
||||||
|
|
||||||
glStencilFunc(GL_EQUAL, 1, 0xFF);
|
glStencilFunc(GL_EQUAL, 1, 0xFF);
|
||||||
glStencilMask(0x00);
|
glStencilMask(0x00);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
r->useProgram(waterProg.get());
|
r.useProgram(waterProg.get());
|
||||||
|
|
||||||
buffers[0] = GL_COLOR_ATTACHMENT0;
|
buffers[0] = GL_COLOR_ATTACHMENT0;
|
||||||
glDrawBuffers(1, buffers);
|
glDrawBuffers(1, buffers);
|
||||||
|
|
||||||
r->setUniform(waterProg.get(), "time", world->getGameTime());
|
r.setUniform(waterProg.get(), "time", world->getGameTime());
|
||||||
r->setUniform(waterProg.get(), "waveParams",
|
r.setUniform(waterProg.get(), "waveParams",
|
||||||
glm::vec2(WATER_SCALE, WATER_HEIGHT));
|
glm::vec2(WATER_SCALE, WATER_HEIGHT));
|
||||||
auto ivp =
|
auto ivp =
|
||||||
glm::inverse(r->getSceneData().projection * r->getSceneData().view);
|
glm::inverse(r.getSceneData().projection * r.getSceneData().view);
|
||||||
r->setUniform(waterProg.get(), "inverseVP", ivp);
|
r.setUniform(waterProg.get(), "inverseVP", ivp);
|
||||||
|
|
||||||
wdp.count = gridGeom.getCount();
|
wdp.count = gridGeom.getCount();
|
||||||
wdp.textures = {{waterTex->getName(), dataTexture}};
|
wdp.textures = {{waterTex->getName(), dataTexture}};
|
||||||
|
|
||||||
r->drawArrays(m, &gridDraw, wdp);
|
r.drawArrays(m, &gridDraw, wdp);
|
||||||
|
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class GameWorld;
|
|||||||
*/
|
*/
|
||||||
class WaterRenderer {
|
class WaterRenderer {
|
||||||
public:
|
public:
|
||||||
WaterRenderer(GameRenderer* renderer);
|
WaterRenderer(GameRenderer& renderer);
|
||||||
~WaterRenderer() = default;
|
~WaterRenderer() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +38,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Render the water using the currently active render state
|
* Render the water using the currently active render state
|
||||||
*/
|
*/
|
||||||
void render(GameRenderer* renderer, GameWorld* world);
|
void render(GameRenderer& renderer, GameWorld* world);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Renderer::ShaderProgram> waterProg = nullptr;
|
std::unique_ptr<Renderer::ShaderProgram> waterProg = nullptr;
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
void HUDDrawer::drawScriptTimer(GameWorld* world, GameRenderer* render) {
|
void HUDDrawer::drawScriptTimer(GameWorld* world, GameRenderer& render) {
|
||||||
if (world->state->scriptTimerVariable) {
|
if (world->state->scriptTimerVariable) {
|
||||||
float scriptTimerTextX = static_cast<float>(
|
float scriptTimerTextX = static_cast<float>(
|
||||||
render->getRenderer()->getViewport().x - hudParameters.uiOuterMargin);
|
render.getRenderer().getViewport().x - hudParameters.uiOuterMargin);
|
||||||
float scriptTimerTextY = hudParameters.uiScriptTimerHeight;
|
float scriptTimerTextY = hudParameters.uiScriptTimerHeight;
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
@ -33,16 +33,16 @@ void HUDDrawer::drawScriptTimer(GameWorld* world, GameRenderer* render) {
|
|||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition =
|
ti.screenPosition =
|
||||||
glm::vec2(scriptTimerTextX + 1.f, scriptTimerTextY + 1.f);
|
glm::vec2(scriptTimerTextX + 1.f, scriptTimerTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = hudParameters.uiScriptTimerColour;
|
ti.baseColour = hudParameters.uiScriptTimerColour;
|
||||||
ti.screenPosition = glm::vec2(scriptTimerTextX, scriptTimerTextY);
|
ti.screenPosition = glm::vec2(scriptTimerTextX, scriptTimerTextY);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUDDrawer::drawMap(ViewCamera& currentView, PlayerController* player,
|
void HUDDrawer::drawMap(ViewCamera& currentView, PlayerController* player,
|
||||||
GameWorld* world, GameRenderer* render) {
|
GameWorld* world, GameRenderer& render) {
|
||||||
MapRenderer::MapInfo map;
|
MapRenderer::MapInfo map;
|
||||||
|
|
||||||
if (world->state->hudFlash != HudFlash::FlashRadar ||
|
if (world->state->hudFlash != HudFlash::FlashRadar ||
|
||||||
@ -56,7 +56,7 @@ void HUDDrawer::drawMap(ViewCamera& currentView, PlayerController* player,
|
|||||||
map.worldCenter = glm::vec2(player->getCharacter()->getPosition());
|
map.worldCenter = glm::vec2(player->getCharacter()->getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::ivec2& vp = render->getRenderer()->getViewport();
|
const glm::ivec2& vp = render.getRenderer().getViewport();
|
||||||
|
|
||||||
glm::vec2 mapTop =
|
glm::vec2 mapTop =
|
||||||
glm::vec2(hudParameters.uiOuterMargin, vp.y - (hudParameters.uiOuterMargin + hudParameters.uiMapSize));
|
glm::vec2(hudParameters.uiOuterMargin, vp.y - (hudParameters.uiOuterMargin + hudParameters.uiMapSize));
|
||||||
@ -66,19 +66,19 @@ void HUDDrawer::drawMap(ViewCamera& currentView, PlayerController* player,
|
|||||||
map.screenPosition = (mapTop + mapBottom) / 2.f;
|
map.screenPosition = (mapTop + mapBottom) / 2.f;
|
||||||
map.screenSize = hudParameters.uiMapSize * 0.95f;
|
map.screenSize = hudParameters.uiMapSize * 0.95f;
|
||||||
|
|
||||||
render->map.draw(world, map);
|
render.map.draw(world, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
||||||
GameRenderer* render) {
|
GameRenderer& render) {
|
||||||
float infoTextX = static_cast<float>(render->getRenderer()->getViewport().x -
|
float infoTextX = static_cast<float>(render.getRenderer().getViewport().x -
|
||||||
(hudParameters.uiOuterMargin + hudParameters.uiWeaponSize + hudParameters.uiInfoMargin));
|
(hudParameters.uiOuterMargin + hudParameters.uiWeaponSize + hudParameters.uiInfoMargin));
|
||||||
float infoTextY = 0.f + hudParameters.uiOuterMargin;
|
float infoTextY = 0.f + hudParameters.uiOuterMargin;
|
||||||
float iconX = static_cast<float>(render->getRenderer()->getViewport().x -
|
float iconX = static_cast<float>(render.getRenderer().getViewport().x -
|
||||||
(hudParameters.uiOuterMargin + hudParameters.uiWeaponSize));
|
(hudParameters.uiOuterMargin + hudParameters.uiWeaponSize));
|
||||||
float iconY = hudParameters.uiOuterMargin;
|
float iconY = hudParameters.uiOuterMargin;
|
||||||
float wantedX = static_cast<float>(render->getRenderer()->getViewport().x - hudParameters.uiOuterMargin);
|
float wantedX = static_cast<float>(render.getRenderer().getViewport().x - hudParameters.uiOuterMargin);
|
||||||
float wantedY = hudParameters.uiWantedLevelHeight;
|
float wantedY = hudParameters.uiWantedLevelHeight;
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
@ -96,12 +96,12 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
|
|
||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = hudParameters.uiTimeColour;
|
ti.baseColour = hudParameters.uiTimeColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
|
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
infoTextY += hudParameters.uiTextHeight;
|
infoTextY += hudParameters.uiTextHeight;
|
||||||
|
|
||||||
@ -115,12 +115,12 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
|
|
||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = hudParameters.uiMoneyColour;
|
ti.baseColour = hudParameters.uiMoneyColour;
|
||||||
|
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
infoTextY += hudParameters.uiTextHeight;
|
infoTextY += hudParameters.uiTextHeight;
|
||||||
|
|
||||||
@ -137,11 +137,11 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
|
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = hudParameters.uiHealthColour;
|
ti.baseColour = hudParameters.uiHealthColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->getCharacter()->getCurrentState().armour > 0) {
|
if (player->getCharacter()->getCurrentState().armour > 0) {
|
||||||
@ -154,11 +154,11 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition =
|
ti.screenPosition =
|
||||||
glm::vec2(infoTextX + 1.f - hudParameters.uiArmourOffset, infoTextY + 1.f);
|
glm::vec2(infoTextX + 1.f - hudParameters.uiArmourOffset, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = hudParameters.uiArmourColour;
|
ti.baseColour = hudParameters.uiArmourColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX - hudParameters.uiArmourOffset, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX - hudParameters.uiArmourOffset, infoTextY);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameString s;
|
GameString s;
|
||||||
@ -168,7 +168,7 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
ti.text = s;
|
ti.text = s;
|
||||||
ti.baseColour = hudParameters.uiShadowColour;
|
ti.baseColour = hudParameters.uiShadowColour;
|
||||||
ti.screenPosition = glm::vec2(wantedX + 1.f, wantedY + 1.f);
|
ti.screenPosition = glm::vec2(wantedX + 1.f, wantedY + 1.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
|
|
||||||
#if 0 // Useful for debugging
|
#if 0 // Useful for debugging
|
||||||
ti.text = "ABCDEFGHIJKLMANOQRTSWXYZ\nM0123456789";
|
ti.text = "ABCDEFGHIJKLMANOQRTSWXYZ\nM0123456789";
|
||||||
@ -176,10 +176,10 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
ti.align = TextRenderer::TextInfo::Left;
|
ti.align = TextRenderer::TextInfo::Left;
|
||||||
ti.baseColour = glm::vec3(0.f, 0.f, 0.f);
|
ti.baseColour = glm::vec3(0.f, 0.f, 0.f);
|
||||||
ti.screenPosition = glm::vec2(101.f, 202.f);
|
ti.screenPosition = glm::vec2(101.f, 202.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
ti.baseColour = glm::vec3(1.f, 1.f, 1.f);
|
ti.baseColour = glm::vec3(1.f, 1.f, 1.f);
|
||||||
ti.screenPosition = glm::vec2(100.f, 200.f);
|
ti.screenPosition = glm::vec2(100.f, 200.f);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto item = player->getCharacter()->getActiveItem();
|
auto item = player->getCharacter()->getActiveItem();
|
||||||
@ -200,13 +200,13 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextureData::Handle itemTexture =
|
TextureData::Handle itemTexture =
|
||||||
render->getData()->findSlotTexture("hud", itemTextureName);
|
render.getData().findSlotTexture("hud", itemTextureName);
|
||||||
RW_CHECK(itemTexture != nullptr, "Item has 0 texture");
|
RW_CHECK(itemTexture != nullptr, "Item has 0 texture");
|
||||||
if (itemTexture != nullptr) {
|
if (itemTexture != nullptr) {
|
||||||
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
|
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
|
||||||
render->drawTexture(
|
render.drawTexture(itemTexture.get(),
|
||||||
itemTexture.get(),
|
glm::vec4(iconX, iconY, hudParameters.uiWeaponSize,
|
||||||
glm::vec4(iconX, iconY, hudParameters.uiWeaponSize, hudParameters.uiWeaponSize));
|
hudParameters.uiWeaponSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weapon.fireType != WeaponData::MELEE) {
|
if (weapon.fireType != WeaponData::MELEE) {
|
||||||
@ -242,12 +242,12 @@ void HUDDrawer::drawPlayerInfo(PlayerController* player, GameWorld* world,
|
|||||||
ti.align = TextRenderer::TextInfo::TextAlignment::Center;
|
ti.align = TextRenderer::TextInfo::TextAlignment::Center;
|
||||||
ti.screenPosition = glm::vec2(iconX + hudParameters.uiWeaponSize / 2.f,
|
ti.screenPosition = glm::vec2(iconX + hudParameters.uiWeaponSize / 2.f,
|
||||||
iconY + hudParameters.uiWeaponSize - hudParameters.uiAmmoHeight);
|
iconY + hudParameters.uiWeaponSize - hudParameters.uiAmmoHeight);
|
||||||
render->text.renderText(ti);
|
render.text.renderText(ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUDDrawer::drawHUD(ViewCamera& currentView, PlayerController* player,
|
void HUDDrawer::drawHUD(ViewCamera& currentView, PlayerController* player,
|
||||||
GameWorld* world, GameRenderer* render) {
|
GameWorld* world, GameRenderer& render) {
|
||||||
if (player && player->getCharacter()) {
|
if (player && player->getCharacter()) {
|
||||||
drawMap(currentView, player, world, render);
|
drawMap(currentView, player, world, render);
|
||||||
drawPlayerInfo(player, world, render);
|
drawPlayerInfo(player, world, render);
|
||||||
@ -255,8 +255,8 @@ void HUDDrawer::drawHUD(ViewCamera& currentView, PlayerController* player,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUDDrawer::drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
|
void HUDDrawer::drawOnScreenText(GameWorld* world, GameRenderer& renderer) {
|
||||||
const auto vp = glm::vec2(renderer->getRenderer()->getViewport());
|
const auto vp = glm::vec2(renderer.getRenderer().getViewport());
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
ti.font = FONT_ARIAL;
|
ti.font = FONT_ARIAL;
|
||||||
@ -293,7 +293,7 @@ void HUDDrawer::drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
|
|||||||
ti.screenPosition += shadowPosition;
|
ti.screenPosition += shadowPosition;
|
||||||
ti.backgroundColour = {0, 0, 0, 0};
|
ti.backgroundColour = {0, 0, 0, 0};
|
||||||
|
|
||||||
renderer->text.renderText(ti, true);
|
renderer.text.renderText(ti, true);
|
||||||
|
|
||||||
ti.screenPosition -= shadowPosition;
|
ti.screenPosition -= shadowPosition;
|
||||||
} else if (t.colourBG.a > 0) {
|
} else if (t.colourBG.a > 0) {
|
||||||
@ -301,7 +301,7 @@ void HUDDrawer::drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ti.baseColour = t.colourFG;
|
ti.baseColour = t.colourFG;
|
||||||
renderer->text.renderText(ti);
|
renderer.text.renderText(ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,17 +41,17 @@ public:
|
|||||||
void applyHUDScale(float scale);
|
void applyHUDScale(float scale);
|
||||||
HUDParameters getHUDParameters();
|
HUDParameters getHUDParameters();
|
||||||
void drawHUD(ViewCamera& currentView, PlayerController* player,
|
void drawHUD(ViewCamera& currentView, PlayerController* player,
|
||||||
GameWorld* world, GameRenderer* render);
|
GameWorld* world, GameRenderer& render);
|
||||||
void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
|
void drawOnScreenText(GameWorld* world, GameRenderer& renderer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HUDParameters hudParameters;
|
HUDParameters hudParameters;
|
||||||
|
|
||||||
void drawScriptTimer(GameWorld* world, GameRenderer* render);
|
void drawScriptTimer(GameWorld* world, GameRenderer& render);
|
||||||
void drawMap(ViewCamera& currentView, PlayerController* player,
|
void drawMap(ViewCamera& currentView, PlayerController* player,
|
||||||
GameWorld* world, GameRenderer* render);
|
GameWorld* world, GameRenderer& render);
|
||||||
void drawPlayerInfo(PlayerController* player, GameWorld* world,
|
void drawPlayerInfo(PlayerController* player, GameWorld* world,
|
||||||
GameRenderer* render);
|
GameRenderer& render);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
: text(n), callback(cb) {
|
: text(n), callback(cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(font_t font, float size, bool active, GameRenderer* r,
|
void draw(font_t font, float size, bool active, GameRenderer& r,
|
||||||
glm::vec2& basis) {
|
glm::vec2& basis) {
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
ti.font = font;
|
ti.font = font;
|
||||||
@ -61,7 +61,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
ti.baseColour = glm::u8vec3(255, 255, 0);
|
ti.baseColour = glm::u8vec3(255, 255, 0);
|
||||||
}
|
}
|
||||||
r->text.renderText(ti);
|
r.text.renderText(ti);
|
||||||
basis.y += size;
|
basis.y += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
int activeEntry;
|
int activeEntry;
|
||||||
|
|
||||||
void draw(GameRenderer* r) {
|
void draw(GameRenderer& r) {
|
||||||
glm::vec2 basis(offset);
|
glm::vec2 basis(offset);
|
||||||
for (size_t i = 0; i < entries.size(); ++i) {
|
for (size_t i = 0; i < entries.size(); ++i) {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
@ -585,9 +585,9 @@ void RWGame::tickObjects(float dt) const {
|
|||||||
void RWGame::render(float alpha, float time) {
|
void RWGame::render(float alpha, float time) {
|
||||||
RW_PROFILE_SCOPEC(__func__, MP_CORNFLOWERBLUE);
|
RW_PROFILE_SCOPEC(__func__, MP_CORNFLOWERBLUE);
|
||||||
|
|
||||||
lastDraws = getRenderer().getRenderer()->getDrawCount();
|
lastDraws = getRenderer().getRenderer().getDrawCount();
|
||||||
|
|
||||||
getRenderer().getRenderer()->swap();
|
getRenderer().getRenderer().swap();
|
||||||
|
|
||||||
// Update the camera
|
// Update the camera
|
||||||
if (!StateManager::get().states.empty()) {
|
if (!StateManager::get().states.empty()) {
|
||||||
@ -611,19 +611,19 @@ void RWGame::render(float alpha, float time) {
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
renderer.getRenderer()->pushDebugGroup("World");
|
renderer.getRenderer().pushDebugGroup("World");
|
||||||
|
|
||||||
renderer.renderWorld(world.get(), viewCam, alpha);
|
renderer.renderWorld(world.get(), viewCam, alpha);
|
||||||
|
|
||||||
renderer.getRenderer()->popDebugGroup();
|
renderer.getRenderer().popDebugGroup();
|
||||||
|
|
||||||
renderDebugView(time, viewCam);
|
renderDebugView(time, viewCam);
|
||||||
|
|
||||||
if (!world->isPaused()) hudDrawer.drawOnScreenText(world.get(), &renderer);
|
if (!world->isPaused()) hudDrawer.drawOnScreenText(world.get(), renderer);
|
||||||
|
|
||||||
if (StateManager::currentState()) {
|
if (StateManager::currentState()) {
|
||||||
RW_PROFILE_SCOPE("state");
|
RW_PROFILE_SCOPE("state");
|
||||||
StateManager::get().draw(&renderer);
|
StateManager::get().draw(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ void RWGame::renderDebugView(float time, ViewCamera &viewCam) {
|
|||||||
break;
|
break;
|
||||||
case DebugViewMode::Physics:
|
case DebugViewMode::Physics:
|
||||||
world->dynamicsWorld->debugDrawWorld();
|
world->dynamicsWorld->debugDrawWorld();
|
||||||
debug.flush(&renderer);
|
debug.flush(renderer);
|
||||||
break;
|
break;
|
||||||
case DebugViewMode::Navigation:
|
case DebugViewMode::Navigation:
|
||||||
renderDebugPaths(time);
|
renderDebugPaths(time);
|
||||||
@ -671,8 +671,8 @@ void RWGame::renderDebugStats(float time) {
|
|||||||
<< "Frame: " << time_ms << "ms\n"
|
<< "Frame: " << time_ms << "ms\n"
|
||||||
<< "Draws/Culls/Textures/Buffers: " << lastDraws << "/"
|
<< "Draws/Culls/Textures/Buffers: " << lastDraws << "/"
|
||||||
<< renderer.getCulledCount() << "/"
|
<< renderer.getCulledCount() << "/"
|
||||||
<< renderer.getRenderer()->getTextureCount() << "/"
|
<< renderer.getRenderer().getTextureCount() << "/"
|
||||||
<< renderer.getRenderer()->getBufferCount() << "\n"
|
<< renderer.getRenderer().getBufferCount() << "\n"
|
||||||
<< "Timescale: " << world->state->basic.timeScale;
|
<< "Timescale: " << world->state->basic.timeScale;
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
@ -785,7 +785,7 @@ void RWGame::renderDebugPaths(float time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.flush(&renderer);
|
debug.flush(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWGame::renderDebugObjects(float time, ViewCamera& camera) {
|
void RWGame::renderDebugObjects(float time, ViewCamera& camera) {
|
||||||
|
@ -9,7 +9,7 @@ const ViewCamera defaultView{{-250.f, -550.f, 75.f},
|
|||||||
State::State(RWGame *game) : game(game) {
|
State::State(RWGame *game) : game(game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::draw(GameRenderer *r) {
|
void State::draw(GameRenderer& r) {
|
||||||
auto& menu = getCurrentMenu();
|
auto& menu = getCurrentMenu();
|
||||||
if (menu) {
|
if (menu) {
|
||||||
menu->draw(r);
|
menu->draw(r);
|
||||||
|
@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
virtual void tick(float dt) = 0;
|
virtual void tick(float dt) = 0;
|
||||||
|
|
||||||
virtual void draw(GameRenderer* r);
|
virtual void draw(GameRenderer& r);
|
||||||
|
|
||||||
virtual ~State() = default;
|
virtual ~State() = default;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public:
|
|||||||
states.back()->tick(dt);
|
states.back()->tick(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(GameRenderer* r) {
|
void draw(GameRenderer& r) {
|
||||||
states.back()->draw(r);
|
states.back()->draw(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ void BenchmarkState::tick(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BenchmarkState::draw(GameRenderer* r) {
|
void BenchmarkState::draw(GameRenderer& r) {
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
State::draw(r);
|
State::draw(r);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
|
|
||||||
void tick(float dt) override;
|
void tick(float dt) override;
|
||||||
|
|
||||||
void draw(GameRenderer* r) override;
|
void draw(GameRenderer &r) override;
|
||||||
|
|
||||||
void handleEvent(const SDL_Event& event) override;
|
void handleEvent(const SDL_Event& event) override;
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ void DebugState::tick(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugState::draw(GameRenderer* r) {
|
void DebugState::draw(GameRenderer& r) {
|
||||||
// Draw useful information like camera position.
|
// Draw useful information like camera position.
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Camera Position: " << glm::to_string(_debugCam.position) << "\n";
|
ss << "Camera Position: " << glm::to_string(_debugCam.position) << "\n";
|
||||||
@ -403,7 +403,7 @@ void DebugState::draw(GameRenderer* r) {
|
|||||||
ti.screenPosition = glm::vec2(10.f, 10.f);
|
ti.screenPosition = glm::vec2(10.f, 10.f);
|
||||||
ti.size = 15.f;
|
ti.size = 15.f;
|
||||||
ti.baseColour = glm::u8vec3(255);
|
ti.baseColour = glm::u8vec3(255);
|
||||||
r->text.renderText(ti);
|
r.text.renderText(ti);
|
||||||
|
|
||||||
State::draw(r);
|
State::draw(r);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
|
|
||||||
void tick(float dt) override;
|
void tick(float dt) override;
|
||||||
|
|
||||||
void draw(GameRenderer* r) override;
|
void draw(GameRenderer &r) override;
|
||||||
|
|
||||||
void handleEvent(const SDL_Event& event) override;
|
void handleEvent(const SDL_Event& event) override;
|
||||||
|
|
||||||
|
@ -281,9 +281,10 @@ void IngameState::tick(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IngameState::draw(GameRenderer* r) {
|
void IngameState::draw(GameRenderer& r) {
|
||||||
if (!getWorld()->state->isCinematic && getWorld()->isCutsceneDone()) {
|
if (!getWorld()->state->isCinematic && getWorld()->isCutsceneDone()) {
|
||||||
game->getHUDDrawer().drawHUD(_look, game->getWorld()->getPlayer(), getWorld(), r);
|
game->getHUDDrawer().drawHUD(_look, game->getWorld()->getPlayer(),
|
||||||
|
getWorld(), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
State::draw(r);
|
State::draw(r);
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
|
|
||||||
void tick(float dt) override;
|
void tick(float dt) override;
|
||||||
|
|
||||||
void draw(GameRenderer* r) override;
|
void draw(GameRenderer &r) override;
|
||||||
|
|
||||||
void handleEvent(const SDL_Event& event) override;
|
void handleEvent(const SDL_Event& event) override;
|
||||||
virtual void handlePlayerInput(const SDL_Event& event);
|
virtual void handlePlayerInput(const SDL_Event& event);
|
||||||
|
@ -27,15 +27,16 @@ void LoadingState::handleEvent(const SDL_Event& e) {
|
|||||||
State::handleEvent(e);
|
State::handleEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadingState::draw(GameRenderer* r) {
|
void LoadingState::draw(GameRenderer& r) {
|
||||||
static auto kLoadingString = GameStringUtil::fromString("Loading...", FONT_ARIAL);
|
static auto kLoadingString =
|
||||||
|
GameStringUtil::fromString("Loading...", FONT_ARIAL);
|
||||||
// Display some manner of loading screen.
|
// Display some manner of loading screen.
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
ti.text = kLoadingString;
|
ti.text = kLoadingString;
|
||||||
auto size = r->getRenderer()->getViewport();
|
auto size = r.getRenderer().getViewport();
|
||||||
ti.size = 25.f;
|
ti.size = 25.f;
|
||||||
ti.screenPosition = glm::vec2(50.f, size.y - ti.size - 50.f);
|
ti.screenPosition = glm::vec2(50.f, size.y - ti.size - 50.f);
|
||||||
ti.font = FONT_PRICEDOWN;
|
ti.font = FONT_PRICEDOWN;
|
||||||
ti.baseColour = glm::u8vec3(255);
|
ti.baseColour = glm::u8vec3(255);
|
||||||
r->text.renderText(ti);
|
r.text.renderText(ti);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
void tick(float dt) override;
|
void tick(float dt) override;
|
||||||
|
|
||||||
void draw(GameRenderer* r) override;
|
void draw(GameRenderer& r) override;
|
||||||
|
|
||||||
bool shouldWorldUpdate() override;
|
bool shouldWorldUpdate() override;
|
||||||
|
|
||||||
|
@ -29,10 +29,10 @@ void PauseState::tick(float dt) {
|
|||||||
RW_UNUSED(dt);
|
RW_UNUSED(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PauseState::draw(GameRenderer* r) {
|
void PauseState::draw(GameRenderer& r) {
|
||||||
MapRenderer::MapInfo map;
|
MapRenderer::MapInfo map;
|
||||||
|
|
||||||
auto& vp = r->getRenderer()->getViewport();
|
auto& vp = r.getRenderer().getViewport();
|
||||||
|
|
||||||
map.worldSize = 4000.f;
|
map.worldSize = 4000.f;
|
||||||
map.clipToSize = false;
|
map.clipToSize = false;
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
|
|
||||||
void tick(float dt) override;
|
void tick(float dt) override;
|
||||||
|
|
||||||
void draw(GameRenderer* r) override;
|
void draw(GameRenderer &r) override;
|
||||||
|
|
||||||
void handleEvent(const SDL_Event& event) override;
|
void handleEvent(const SDL_Event& event) override;
|
||||||
};
|
};
|
||||||
|
@ -76,8 +76,8 @@ void ViewerWidget::drawModel(GameRenderer& r, ClumpPtr& model) {
|
|||||||
viewDistance,
|
viewDistance,
|
||||||
view, proj);
|
view, proj);
|
||||||
|
|
||||||
r.getRenderer()->useProgram(r.worldProg.get());
|
r.getRenderer().useProgram(r.worldProg.get());
|
||||||
r.getRenderer()->setSceneParameters(
|
r.getRenderer().setSceneParameters(
|
||||||
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
||||||
glm::vec4(0.f), 90.f, vc.frustum.far});
|
glm::vec4(0.f), 90.f, vc.frustum.far});
|
||||||
model->getFrame()->updateHierarchyTransform();
|
model->getFrame()->updateHierarchyTransform();
|
||||||
@ -85,7 +85,7 @@ void ViewerWidget::drawModel(GameRenderer& r, ClumpPtr& model) {
|
|||||||
ObjectRenderer _renderer(world(), vc, 1.f);
|
ObjectRenderer _renderer(world(), vc, 1.f);
|
||||||
RenderList renders;
|
RenderList renders;
|
||||||
_renderer.renderClump(model.get(), glm::mat4(1.0f), nullptr, renders);
|
_renderer.renderClump(model.get(), glm::mat4(1.0f), nullptr, renders);
|
||||||
r.getRenderer()->drawBatched(renders);
|
r.getRenderer().drawBatched(renders);
|
||||||
|
|
||||||
drawFrameWidget(model->getFrame().get());
|
drawFrameWidget(model->getFrame().get());
|
||||||
r.renderPostProcess();
|
r.renderPostProcess();
|
||||||
@ -98,8 +98,8 @@ void ViewerWidget::drawObject(GameRenderer &r, GameObject *object) {
|
|||||||
viewDistance,
|
viewDistance,
|
||||||
view, proj);
|
view, proj);
|
||||||
|
|
||||||
r.getRenderer()->useProgram(r.worldProg.get());
|
r.getRenderer().useProgram(r.worldProg.get());
|
||||||
r.getRenderer()->setSceneParameters(
|
r.getRenderer().setSceneParameters(
|
||||||
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
||||||
glm::vec4(0.f), 90.f, vc.frustum.far});
|
glm::vec4(0.f), 90.f, vc.frustum.far});
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ void ViewerWidget::drawObject(GameRenderer &r, GameObject *object) {
|
|||||||
const Renderer::RenderInstruction& b) {
|
const Renderer::RenderInstruction& b) {
|
||||||
return a.sortKey < b.sortKey;
|
return a.sortKey < b.sortKey;
|
||||||
});
|
});
|
||||||
r.getRenderer()->drawBatched(renders);
|
r.getRenderer().drawBatched(renders);
|
||||||
r.renderPostProcess();
|
r.renderPostProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,12 +144,12 @@ void ViewerWidget::paintGL() {
|
|||||||
|
|
||||||
RW_CHECK(_renderer != nullptr, "GameRenderer is null");
|
RW_CHECK(_renderer != nullptr, "GameRenderer is null");
|
||||||
auto& r = *_renderer;
|
auto& r = *_renderer;
|
||||||
r.getRenderer()->invalidate();
|
r.getRenderer().invalidate();
|
||||||
r.setViewport(width() * devicePixelRatio(), height() * devicePixelRatio());
|
r.setViewport(width() * devicePixelRatio(), height() * devicePixelRatio());
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
r.getRenderer()->invalidate();
|
r.getRenderer().invalidate();
|
||||||
r.setupRender();
|
r.setupRender();
|
||||||
|
|
||||||
switch (_viewMode) {
|
switch (_viewMode) {
|
||||||
@ -187,7 +187,7 @@ void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
|
|||||||
|
|
||||||
RW_CHECK(_renderer != nullptr, "GameRenderer is null");
|
RW_CHECK(_renderer != nullptr, "GameRenderer is null");
|
||||||
if(_renderer != nullptr) {
|
if(_renderer != nullptr) {
|
||||||
_renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
|
_renderer->getRenderer().drawArrays(thisM, _frameWidgetDraw, dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto c : f->getChildren()) {
|
for (auto c : f->getChildren()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user