openspades/Sources/Draw/GLSoftLitSpriteRenderer.h

113 lines
2.6 KiB
C
Raw Normal View History

2013-09-16 13:29:55 +09:00
/*
Copyright (c) 2013 yvt
2013-09-16 13:29:55 +09:00
This file is part of OpenSpades.
2013-09-16 13:29:55 +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-09-16 13:29:55 +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-09-16 13:29:55 +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-09-16 13:29:55 +09:00
*/
#pragma once
#include <cstdint>
2013-09-16 13:29:55 +09:00
#include <vector>
#include "../Core/Math.h"
2013-09-16 13:29:55 +09:00
#include "GLProgramAttribute.h"
#include "GLProgramUniform.h"
#include "IGLSpriteRenderer.h"
namespace spades {
namespace draw {
class GLRenderer;
class IGLDevice;
class GLImage;
class GLSettings;
class GLSoftLitSpriteRenderer : public IGLSpriteRenderer {
2013-09-16 13:29:55 +09:00
struct Sprite {
GLImage *image;
Vector3 center;
float radius;
float angle;
Vector4 color;
Vector3 emission;
float area;
Vector4 dlR, dlG, dlB;
};
2013-09-16 13:29:55 +09:00
struct Vertex {
// center position
float x, y, z;
float radius;
2013-09-16 13:29:55 +09:00
// point coord
float sx, sy;
float angle;
2013-09-16 13:29:55 +09:00
// color
Vector4 color;
Vector3 emission;
2013-09-16 13:29:55 +09:00
// dynamic lights
Vector4 dlR, dlG, dlB;
};
2013-09-16 13:29:55 +09:00
GLRenderer *renderer;
GLSettings &settings;
2013-09-16 13:29:55 +09:00
IGLDevice *device;
std::vector<Sprite> sprites;
2013-09-16 13:29:55 +09:00
GLImage *lastImage;
2013-09-16 13:29:55 +09:00
std::vector<Vertex> vertices;
std::vector<uint32_t> indices;
2013-09-16 13:29:55 +09:00
GLProgram *program;
GLProgramUniform projectionViewMatrix;
GLProgramUniform rightVector;
GLProgramUniform upVector;
GLProgramUniform frontVector;
GLProgramUniform viewOriginVector;
GLProgramUniform texture;
GLProgramUniform depthTexture;
GLProgramUniform viewMatrix;
GLProgramUniform fogDistance;
GLProgramUniform fogColor;
GLProgramUniform zNearFar;
GLProgramUniform cameraPosition;
2013-09-16 13:29:55 +09:00
GLProgramAttribute positionAttribute;
GLProgramAttribute spritePosAttribute;
GLProgramAttribute colorAttribute;
GLProgramAttribute emissionAttribute;
GLProgramAttribute dlRAttribute;
GLProgramAttribute dlGAttribute;
GLProgramAttribute dlBAttribute;
2013-09-16 13:29:55 +09:00
float thresLow, thresRange;
2013-09-16 13:29:55 +09:00
void Flush();
float LayerForSprite(const Sprite &);
2013-09-16 13:29:55 +09:00
public:
GLSoftLitSpriteRenderer(GLRenderer *);
virtual ~GLSoftLitSpriteRenderer();
virtual void Add(GLImage *img, Vector3 center, float rad, float ang, Vector4 color);
2013-09-16 13:29:55 +09:00
virtual void Clear();
virtual void Render();
};
}
}