aboutsummaryrefslogtreecommitdiffstats
path: root/yage
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-31 18:00:01 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-31 18:00:01 +0000
commit34908f108ad7c2ee6cff96491a0bc40381477424 (patch)
treef58c6bdde485d07a7136f78055240bab923bd4a6 /yage
parent943e3a5bc98ebcc2aa1b1d576700f7c4010c143c (diff)
downloadYAGE-34908f108ad7c2ee6cff96491a0bc40381477424.tar.gz
YAGE-34908f108ad7c2ee6cff96491a0bc40381477424.zip
[Test] Benchmarking the engine and trying to optimize.
Diffstat (limited to 'yage')
-rw-r--r--yage/core/imageloader.cpp2
-rw-r--r--yage/core/logger.h8
-rw-r--r--yage/core/resourcemanager.cpp4
-rw-r--r--yage/core/resourcemanager.h5
-rw-r--r--yage/core/texturecache.cpp6
-rw-r--r--yage/core/texturecache.h2
-rw-r--r--yage/render/spritebatch.cpp49
7 files changed, 39 insertions, 37 deletions
diff --git a/yage/core/imageloader.cpp b/yage/core/imageloader.cpp
index 60290058..7b34312d 100644
--- a/yage/core/imageloader.cpp
+++ b/yage/core/imageloader.cpp
@@ -48,7 +48,7 @@ Texture ImageLoader::loadPng(const std::string &file_path)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
diff --git a/yage/core/logger.h b/yage/core/logger.h
index 98c64b88..d1f75aec 100644
--- a/yage/core/logger.h
+++ b/yage/core/logger.h
@@ -13,13 +13,13 @@
#include <string>
#include <vector>
+#include "../util/active.h"
+#include "logmessage.h"
+#include "logsink.h"
+
namespace yage
{
-class Active;
-class LogMessage;
-class LogSink;
-
class Logger
{
public:
diff --git a/yage/core/resourcemanager.cpp b/yage/core/resourcemanager.cpp
index eac09305..ec3761b8 100644
--- a/yage/core/resourcemanager.cpp
+++ b/yage/core/resourcemanager.cpp
@@ -14,9 +14,9 @@ namespace yage
TextureCache ResourceManager::texture_cache_;
-Texture ResourceManager::getTexture(const std::string &texture_path)
+Texture ResourceManager::getTexture(const std::string &texture_path, int x, int y)
{
- return texture_cache_.getTexture(texture_path);
+ return texture_cache_.getTexture(texture_path, x, y);
}
} // namespace yage
diff --git a/yage/core/resourcemanager.h b/yage/core/resourcemanager.h
index a0249436..11a16f63 100644
--- a/yage/core/resourcemanager.h
+++ b/yage/core/resourcemanager.h
@@ -24,7 +24,7 @@
namespace yage
{
-class Texture;
+struct Texture;
class ResourceManager
{
@@ -32,7 +32,8 @@ private:
static TextureCache texture_cache_;
public:
- static Texture getTexture(const std::string &texture_path);
+ static Texture getTexture(const std::string &texture_path, int x = 1,
+ int y = 1);
};
} // namespace yage
diff --git a/yage/core/texturecache.cpp b/yage/core/texturecache.cpp
index 447051b7..66251de5 100644
--- a/yage/core/texturecache.cpp
+++ b/yage/core/texturecache.cpp
@@ -7,19 +7,21 @@
*/
#include "texturecache.h"
-#include "imageloader.h"
#include "../data/texture.h"
+#include "imageloader.h"
namespace yage
{
-Texture TextureCache::getTexture(const std::string &texture_path)
+Texture TextureCache::getTexture(const std::string &texture_path, int x, int y)
{
auto itr = texture_map_.find(texture_path);
if (itr == texture_map_.end()) {
Texture new_texture = ImageLoader::loadPng(texture_path);
texture_map_.insert(make_pair(texture_path, new_texture));
+ new_texture.x = x;
+ new_texture.y = y;
return new_texture;
}
diff --git a/yage/core/texturecache.h b/yage/core/texturecache.h
index ac57aaba..fbedab9d 100644
--- a/yage/core/texturecache.h
+++ b/yage/core/texturecache.h
@@ -24,7 +24,7 @@ private:
public:
TextureCache() = default;
- Texture getTexture(const std::string &texture_path);
+ Texture getTexture(const std::string &texture_path, int x = 1, int y = 1);
Texture getTextureFromSpriteSheet();
};
diff --git a/yage/render/spritebatch.cpp b/yage/render/spritebatch.cpp
index bce5986f..09df5b9f 100644
--- a/yage/render/spritebatch.cpp
+++ b/yage/render/spritebatch.cpp
@@ -9,8 +9,10 @@
#include "spritebatch.h"
#include <algorithm>
-#include <iostream>
#include <stdexcept>
+#include "../core/logger.h"
+
+#include <GLFW/glfw3.h>
namespace yage
{
@@ -61,13 +63,12 @@ SpriteBatch::SpriteBatch() : vao_(0), vbo_(0)
SpriteBatch::~SpriteBatch()
{
- if (vao_ != 0) {
- glDeleteVertexArrays(1, &vao_);
- }
-
if (vbo_ != 0) {
glDeleteBuffers(1, &vbo_);
}
+ if (vao_ != 0) {
+ glDeleteVertexArrays(1, &vao_);
+ }
}
void SpriteBatch::begin()
@@ -118,10 +119,10 @@ void SpriteBatch::render()
{
glBindVertexArray(vao_);
// sort and create render batches
- createRenderBatches();
sortGlyphs();
+ createRenderBatches();
+ glActiveTexture(GL_TEXTURE0);
for (auto &&batch : render_batches_) {
- glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, batch.texture);
glDrawArrays(GL_TRIANGLES, batch.offset, batch.num_vertices);
}
@@ -134,13 +135,13 @@ void SpriteBatch::render()
void SpriteBatch::createRenderBatches()
{
- std::vector<Vertex> vertices;
+ std::vector<Vertex> vertices(glyph_ptrs_.size() * NUM_VERTICES);
if (glyph_ptrs_.empty()) {
return;
}
- render_batches_.reserve(glyph_ptrs_.size() * NUM_VERTICES);
-
+ int cv = 0;
+
for (int i = 0; i < (int)glyph_ptrs_.size(); ++i) {
if (i == 0 || (i > 0 && (glyph_ptrs_[i]->texture() !=
glyph_ptrs_[i - 1]->texture()))) {
@@ -151,22 +152,20 @@ void SpriteBatch::createRenderBatches()
render_batches_.back().num_vertices += NUM_VERTICES;
}
- vertices.push_back(glyph_ptrs_[i]->bottom_left());
- vertices.push_back(glyph_ptrs_[i]->top_left());
- vertices.push_back(glyph_ptrs_[i]->top_right());
-
- vertices.push_back(glyph_ptrs_[i]->top_right());
- vertices.push_back(glyph_ptrs_[i]->bottom_right());
- vertices.push_back(glyph_ptrs_[i]->bottom_left());
-
- // orphan the buffer
- glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), nullptr,
- GL_DYNAMIC_DRAW);
- // upload the data
- glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(Vertex),
- vertices.data());
- // unbind buffer
+ vertices[cv++] = glyph_ptrs_[i]->bottom_left();
+ vertices[cv++] = glyph_ptrs_[i]->top_left();
+ vertices[cv++] = glyph_ptrs_[i]->top_right();
+
+ vertices[cv++] = glyph_ptrs_[i]->top_right();
+ vertices[cv++] = glyph_ptrs_[i]->bottom_right();
+ vertices[cv++] = glyph_ptrs_[i]->bottom_left();
}
+
+ // orphan the buffer
+ glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), nullptr,
+ GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(Vertex),
+ vertices.data());
}
void SpriteBatch::sortGlyphs()