[external/gamekit] Vertex attr layout is now handled by VertexBuffer.
This commit is contained in:
parent
c001308ae9
commit
677992d93c
2
external/gamekit
vendored
2
external/gamekit
vendored
@ -1 +1 @@
|
||||
Subproject commit 388f8d9de2868b3bd6ad3657093fdf00420e5dcf
|
||||
Subproject commit a047a6b003234e53b7251793f97236b36151a8cb
|
@ -64,13 +64,6 @@ bool ClientApplication::init() {
|
||||
|
||||
gk::CoreApplication::init();
|
||||
|
||||
m_window.addVertexAttribute(VertexAttribute::Coord3d, 0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
m_window.addVertexAttribute(VertexAttribute::TexCoord, 1, "texCoord", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, texCoord)));
|
||||
m_window.addVertexAttribute(VertexAttribute::Color, 2, "color", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, color)));
|
||||
m_window.addVertexAttribute(VertexAttribute::Normal, 3, "normal", 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, normal)));
|
||||
m_window.addVertexAttribute(VertexAttribute::LightValue, 4, "lightValue", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, lightValue)));
|
||||
m_window.addVertexAttribute(VertexAttribute::AmbientOcclusion, 5, "ambientOcclusion", 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, ambientOcclusion)));
|
||||
|
||||
if (m_argumentParser.getArgument("help").isFound)
|
||||
return true;
|
||||
|
||||
|
@ -38,18 +38,4 @@ struct Vertex {
|
||||
GLfloat ambientOcclusion = 5;
|
||||
};
|
||||
|
||||
namespace VertexAttribute {
|
||||
enum {
|
||||
Coord3d = 8,
|
||||
TexCoord = 16,
|
||||
Color = 32,
|
||||
Normal = 64,
|
||||
LightValue = 128,
|
||||
AmbientOcclusion = 256,
|
||||
|
||||
Basic = Coord3d | TexCoord | Color,
|
||||
All = Basic | Normal | LightValue | AmbientOcclusion
|
||||
};
|
||||
}
|
||||
|
||||
#endif // VERTEX_HPP_
|
||||
|
@ -34,6 +34,10 @@
|
||||
#include "GameTime.hpp"
|
||||
#include "Vertex.hpp"
|
||||
|
||||
CelestialObject::CelestialObject() {
|
||||
m_vbo.layout().setupDefaultLayout();
|
||||
}
|
||||
|
||||
void CelestialObject::setTexture(const std::string &textureName) {
|
||||
if (textureName.empty()) return;
|
||||
|
||||
@ -161,8 +165,6 @@ void CelestialObject::draw(gk::RenderTarget &target, gk::RenderStates states) co
|
||||
states.transform.rotateY(-GameTime::getCurrentTime(m_rotationOffset, m_rotationSpeed) * 360.f);
|
||||
states.transform *= getTransform();
|
||||
|
||||
states.vertexAttributes = gk::VertexAttribute::All;
|
||||
|
||||
if (m_texture)
|
||||
states.texture = m_texture;
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
class CelestialObject : public gk::Drawable, public gk::Transformable {
|
||||
public:
|
||||
CelestialObject() = default;
|
||||
CelestialObject();
|
||||
|
||||
float width() const { return m_width; }
|
||||
float height() const { return m_height; }
|
||||
|
@ -126,7 +126,8 @@ void ChunkRenderer::drawChunks(gk::RenderTarget &target, gk::RenderStates states
|
||||
glCheck(glEnable(GL_DEPTH_TEST));
|
||||
|
||||
states.texture = &m_textureAtlas.texture();
|
||||
target.beginSceneDraw(states);
|
||||
|
||||
target.beginDrawing(states);
|
||||
|
||||
states.shader->setUniform("u_renderDistance", Config::renderDistance * CHUNK_WIDTH);
|
||||
|
||||
@ -149,14 +150,12 @@ void ChunkRenderer::drawChunks(gk::RenderTarget &target, gk::RenderStates states
|
||||
|
||||
states.shader->setUniform("u_modelMatrix", it.second);
|
||||
|
||||
target.drawVertexBuffer(it.first->getVBO(layer), GL_TRIANGLES, 0, (GLsizei)verticesCount, states);
|
||||
target.drawVertexBuffer(it.first->getVBO(layer), GL_TRIANGLES, 0, (GLsizei)verticesCount);
|
||||
|
||||
it.first->setHasBeenDrawn(true);
|
||||
}
|
||||
}
|
||||
|
||||
target.endSceneDraw(states);
|
||||
|
||||
if(Config::isWireframeModeEnabled) glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,8 @@ void Framebuffer::loadShader(const std::string &name) {
|
||||
|
||||
void Framebuffer::begin() const {
|
||||
bind(this);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glCheck(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||
glCheck(glEnable(GL_DEPTH_TEST));
|
||||
}
|
||||
|
||||
void Framebuffer::end() const {
|
||||
@ -157,23 +157,23 @@ void Framebuffer::end() const {
|
||||
|
||||
gk::VertexBuffer::bind(&m_vbo);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glCheck(glEnableVertexAttribArray(0));
|
||||
glCheck(glEnableVertexAttribArray(1));
|
||||
|
||||
m_vbo.setAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(0 * sizeof(float)));
|
||||
m_vbo.setAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
glCheck(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(0 * sizeof(float))));
|
||||
glCheck(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float))));
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glCheck(glDrawArrays(GL_TRIANGLES, 0, 6));
|
||||
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(0);
|
||||
glCheck(glDisableVertexAttribArray(1));
|
||||
glCheck(glDisableVertexAttribArray(0));
|
||||
|
||||
gk::VertexBuffer::bind(nullptr);
|
||||
gk::Shader::bind(nullptr);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glCheck(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glCheck(glEnable(GL_DEPTH_TEST));
|
||||
}
|
||||
|
||||
void Framebuffer::bind(const Framebuffer *framebuffer) {
|
||||
|
@ -250,6 +250,13 @@ PlayerBox::PlayerBox(const gk::Camera &camera)
|
||||
: m_camera(camera),
|
||||
m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("texture-player"))
|
||||
{
|
||||
m_vbo.layout().addAttribute(0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
m_vbo.layout().addAttribute(1, "texCoord", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, texCoord)));
|
||||
m_vbo.layout().addAttribute(2, "color", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, color)));
|
||||
m_vbo.layout().addAttribute(3, "normal", 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, normal)));
|
||||
m_vbo.layout().addAttribute(4, "lightValue", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, lightValue)));
|
||||
m_vbo.layout().addAttribute(5, "ambientOcclusion", 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, ambientOcclusion)));
|
||||
|
||||
updateVertexBuffer();
|
||||
}
|
||||
|
||||
@ -282,7 +289,6 @@ void PlayerBox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
|
||||
states.transform *= getTransform();
|
||||
states.texture = &m_texture;
|
||||
states.vertexAttributes = VertexAttribute::All;
|
||||
|
||||
glCheck(glEnable(GL_CULL_FACE));
|
||||
|
||||
|
@ -42,6 +42,16 @@
|
||||
InventoryCube::InventoryCube(float size, bool isEntity)
|
||||
: m_textureAtlas(&gk::ResourceHandler::getInstance().get<TextureAtlas>("atlas-blocks"))
|
||||
{
|
||||
m_vbo.layout().addAttribute(0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
m_vbo.layout().addAttribute(1, "texCoord", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, texCoord)));
|
||||
m_vbo.layout().addAttribute(2, "color", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, color)));
|
||||
|
||||
if (isEntity) {
|
||||
m_vbo.layout().addAttribute(3, "normal", 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, normal)));
|
||||
m_vbo.layout().addAttribute(4, "lightValue", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, lightValue)));
|
||||
m_vbo.layout().addAttribute(5, "ambientOcclusion", 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, ambientOcclusion)));
|
||||
}
|
||||
|
||||
m_size = size;
|
||||
m_isEntity = isEntity;
|
||||
|
||||
@ -158,7 +168,6 @@ void InventoryCube::draw(gk::RenderTarget &target, gk::RenderStates states) cons
|
||||
states.projectionMatrix = glm::ortho(0.0f, (float)Config::screenWidth, (float)Config::screenHeight, 0.0f, DIST_2D_FAR, DIST_2D_NEAR);
|
||||
|
||||
states.texture = &m_textureAtlas->texture();
|
||||
states.vertexAttributes = VertexAttribute::All;
|
||||
|
||||
glCheck(glEnable(GL_CULL_FACE));
|
||||
glCheck(glEnable(GL_DEPTH_TEST));
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "Text.hpp"
|
||||
|
||||
Text::Text() : m_font(gk::ResourceHandler::getInstance().get<Font>("font-ascii")) {
|
||||
m_vbo.layout().setupDefaultLayout();
|
||||
|
||||
m_background.setFillColor(gk::Color::Transparent);
|
||||
}
|
||||
|
||||
@ -78,7 +80,6 @@ void Text::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
|
||||
states.transform.translate((float)m_padding.x, (float)m_padding.y);
|
||||
states.texture = &m_font.texture();
|
||||
states.vertexAttributes = gk::VertexAttribute::All;
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
@ -45,6 +45,15 @@ BlockCursor::BlockCursor(ClientPlayer &player, ClientWorld &world, ClientCommand
|
||||
: m_player(player), m_world(world), m_client(client)
|
||||
{
|
||||
m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get<gk::Texture>("texture-block_destroy");
|
||||
|
||||
m_vbo.layout().addAttribute(0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
|
||||
m_animationVBO.layout().addAttribute(0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
m_animationVBO.layout().addAttribute(1, "texCoord", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, texCoord)));
|
||||
m_animationVBO.layout().addAttribute(2, "color", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, color)));
|
||||
m_animationVBO.layout().addAttribute(3, "normal", 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, normal)));
|
||||
m_animationVBO.layout().addAttribute(4, "lightValue", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, lightValue)));
|
||||
m_animationVBO.layout().addAttribute(5, "ambientOcclusion", 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, ambientOcclusion)));
|
||||
}
|
||||
|
||||
void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
|
||||
@ -302,8 +311,6 @@ void BlockCursor::updateAnimationVertexBuffer(const BlockState &blockState, u8f
|
||||
void BlockCursor::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
if (m_selectedBlock.w == -1) return;
|
||||
|
||||
states.vertexAttributes = VertexAttribute::All;
|
||||
|
||||
glCheck(glDisable(GL_POLYGON_OFFSET_FILL));
|
||||
glCheck(glDisable(GL_CULL_FACE));
|
||||
glCheck(glEnable(GL_DEPTH_TEST));
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "Minimap.hpp"
|
||||
|
||||
Minimap::Minimap() {
|
||||
m_vbo.layout().setupDefaultLayout();
|
||||
|
||||
m_border.setFillColor(gk::Color::Transparent);
|
||||
m_border.setOutlineColor(gk::Color::fromRGBA32(224, 224, 224));
|
||||
m_border.setOutlineThickness(1);
|
||||
@ -147,7 +149,6 @@ void Minimap::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
|
||||
{
|
||||
gk::RenderStates states2 = states;
|
||||
states2.vertexAttributes = gk::VertexAttribute::All;
|
||||
states2.transform.translate(minimapSize / 2 + chunkSize / 2, minimapSize / 2 + chunkSize / 2);
|
||||
states2.transform *= m_playerFovRotationTransform;
|
||||
|
||||
|
@ -35,6 +35,19 @@ u32 ClientChunk::chunkUpdatesPerSec = 0;
|
||||
u32 ClientChunk::chunkUpdateCounter = 0;
|
||||
u64 ClientChunk::chunkUpdateTime = 0;
|
||||
|
||||
ClientChunk::ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world)
|
||||
: Chunk(x, y, z, (World &)world), m_world(world), m_dimension(dimension)
|
||||
{
|
||||
for (auto &vbo : m_vbo) {
|
||||
vbo.layout().addAttribute(0, "coord3d", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, coord3d)));
|
||||
vbo.layout().addAttribute(1, "texCoord", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, texCoord)));
|
||||
vbo.layout().addAttribute(2, "color", 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, color)));
|
||||
vbo.layout().addAttribute(3, "normal", 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, normal)));
|
||||
vbo.layout().addAttribute(4, "lightValue", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, lightValue)));
|
||||
vbo.layout().addAttribute(5, "ambientOcclusion", 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid *>(offsetof(Vertex, ambientOcclusion)));
|
||||
}
|
||||
}
|
||||
|
||||
void ClientChunk::update() {
|
||||
m_lightmap.updateLights();
|
||||
|
||||
|
@ -39,8 +39,7 @@ class TextureAtlas;
|
||||
|
||||
class ClientChunk : public Chunk {
|
||||
public:
|
||||
ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world)
|
||||
: Chunk(x, y, z, (World &)world), m_world(world), m_dimension(dimension) {}
|
||||
ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world);
|
||||
|
||||
void update() final;
|
||||
void process() final;
|
||||
|
@ -266,11 +266,8 @@ void ClientWorld::draw(gk::RenderTarget &target, gk::RenderStates states) const
|
||||
|
||||
OM_PROFILE_START("ClientWorld::draw");
|
||||
|
||||
states.vertexAttributes = VertexAttribute::All;
|
||||
|
||||
m_chunkRenderer.draw(target, states, m_chunks, *m_camera, m_sky);
|
||||
|
||||
states.transform = gk::Transform::Identity;
|
||||
target.draw(m_scene, states);
|
||||
|
||||
OM_PROFILE_END("ClientWorld::draw");
|
||||
|
Loading…
x
Reference in New Issue
Block a user