openspades/Sources/Draw/GLMapChunk.h

97 lines
2.2 KiB
C
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
2013-08-29 11:45:22 +09:00
This file is part of OpenSpades.
2013-08-29 11:45:22 +09:00
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2013-08-29 11:45:22 +09:00
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2013-08-29 11:45:22 +09:00
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
2013-08-29 11:45:22 +09:00
*/
2013-08-18 16:18:06 +09:00
#pragma once
#include <vector>
#include <Client/GameMap.h>
#include <Client/IRenderer.h>
#include <Core/Math.h>
2013-08-18 16:18:06 +09:00
#include "GLDynamicLight.h"
#include "IGLDevice.h"
2013-08-18 16:18:06 +09:00
namespace spades {
namespace draw {
class GLMapRenderer;
class IGLDevice;
class GLMapChunk {
struct Vertex {
uint8_t x, y, z;
uint8_t pad;
2013-08-18 16:18:06 +09:00
uint16_t aoX, aoY;
2013-08-18 16:18:06 +09:00
uint8_t colorRed;
uint8_t colorGreen;
uint8_t colorBlue;
uint8_t shading;
2013-08-18 16:18:06 +09:00
int8_t nx, ny, nz;
uint8_t pad2;
2014-04-10 18:02:12 +09:00
int8_t sx, sy, sz;
uint8_t pad3;
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
GLMapRenderer *renderer;
IGLDevice *device;
client::GameMap *map;
int chunkX, chunkY, chunkZ;
AABB3 aabb;
2013-08-18 16:18:06 +09:00
Vector3 centerPos;
float radius;
2013-08-18 16:18:06 +09:00
std::vector<Vertex> vertices;
std::vector<uint16_t> indices;
IGLDevice::UInteger buffer;
IGLDevice::UInteger iBuffer;
2013-08-18 16:18:06 +09:00
bool needsUpdate;
bool realized;
uint8_t calcAOID(int x, int y, int z, int ux, int uy, int uz, int vx, int vy, int vz);
void EmitVertex(int aoX, int aoY, int aoZ, int x, int y, int z, int ux, int uy, int vx,
int vy, uint32_t color, int nx, int ny, int nz);
2013-08-18 16:18:06 +09:00
bool IsSolid(int x, int y, int z);
2013-08-18 16:18:06 +09:00
void Update();
2013-08-18 16:18:06 +09:00
public:
enum { Size = 16, SizeBits = 4 };
GLMapChunk(GLMapRenderer *, client::GameMap *mp, int cx, int cy, int cz);
2013-08-18 16:18:06 +09:00
~GLMapChunk();
void SetNeedsUpdate() { needsUpdate = true; }
2013-08-18 16:18:06 +09:00
void SetRealized(bool);
float DistanceFromEye(const Vector3 &eye);
2013-08-18 16:18:06 +09:00
void RenderSunlightPass();
void RenderDepthPass();
2013-08-18 16:18:06 +09:00
void RenderDLightPass(std::vector<GLDynamicLight> lights);
};
}
}