Removed gl14 and gl21 devices
parent
37f82acff0
commit
ec21faf15c
|
@ -144,10 +144,6 @@ add_library(colobotbase STATIC
|
|||
graphics/model/model_output.h
|
||||
graphics/model/model_shadow_spot.h
|
||||
graphics/model/model_triangle.h
|
||||
graphics/opengl/gl14device.cpp
|
||||
graphics/opengl/gl14device.h
|
||||
graphics/opengl/gl21device.cpp
|
||||
graphics/opengl/gl21device.h
|
||||
graphics/opengl/gl33device.cpp
|
||||
graphics/opengl/gl33device.h
|
||||
graphics/opengl/glframebuffer.cpp
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file graphics/opengl/gl14device.h
|
||||
* \brief OpenGL implementation - CGL14Device class
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "graphics/core/device.h"
|
||||
|
||||
#include "graphics/core/material.h"
|
||||
|
||||
#include "graphics/opengl/glframebuffer.h"
|
||||
#include "graphics/opengl/glutil.h"
|
||||
|
||||
#include "math/matrix.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
// Graphics module namespace
|
||||
namespace Gfx
|
||||
{
|
||||
|
||||
enum ShadowMappingSupport
|
||||
{
|
||||
SMS_NONE, //! No support for depth textures
|
||||
SMS_ARB, //! ARB extension
|
||||
SMS_CORE //! Core support
|
||||
};
|
||||
|
||||
/**
|
||||
\class CGL14Device
|
||||
\brief Implementation of CDevice interface in OpenGL
|
||||
|
||||
Provides the concrete implementation of 3D device in OpenGL.
|
||||
|
||||
This class should be initialized (by calling Initialize() ) only after
|
||||
setting the video mode by CApplication, once the OpenGL context is defined.
|
||||
Because of that, CGL14DeviceConfig is outside the CDevice class and must be set
|
||||
in CApplication.
|
||||
*/
|
||||
class CGL14Device : public CDevice
|
||||
{
|
||||
public:
|
||||
CGL14Device(const DeviceConfig &config);
|
||||
virtual ~CGL14Device();
|
||||
|
||||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
||||
void ConfigChanged(const DeviceConfig &newConfig) override;
|
||||
|
||||
void BeginScene() override;
|
||||
void EndScene() override;
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void SetRenderMode(RenderMode mode) override;
|
||||
|
||||
void SetTransform(TransformType type, const Math::Matrix &matrix) override;
|
||||
|
||||
void SetMaterial(const Material &material) override;
|
||||
|
||||
int GetMaxLightCount() override;
|
||||
void SetLight(int index, const Light &light) override;
|
||||
void SetLightEnabled(int index, bool enabled) override;
|
||||
|
||||
Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override;
|
||||
Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms) override;
|
||||
Texture CreateDepthTexture(int width, int height, int depth) override;
|
||||
void UpdateTexture(const Texture& texture, Math::IntPoint offset, ImageData* data, TexImgFormat format) override;
|
||||
void DestroyTexture(const Texture &texture) override;
|
||||
void DestroyAllTextures() override;
|
||||
|
||||
int GetMaxTextureStageCount() override;
|
||||
void SetTexture(int index, const Texture &texture) override;
|
||||
void SetTexture(int index, unsigned int textureId) override;
|
||||
void SetTextureEnabled(int index, bool enabled) override;
|
||||
|
||||
void SetTextureStageParams(int index, const TextureStageParams ¶ms) override;
|
||||
|
||||
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override;
|
||||
|
||||
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) override;
|
||||
|
||||
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices,
|
||||
int first[], int count[], int drawCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices,
|
||||
int first[], int count[], int drawCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
|
||||
int first[], int count[], int drawCount) override;
|
||||
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
|
||||
void DrawStaticBuffer(unsigned int bufferId) override;
|
||||
void DestroyStaticBuffer(unsigned int bufferId) override;
|
||||
|
||||
int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override;
|
||||
|
||||
void SetViewport(int x, int y, int width, int height) override;
|
||||
|
||||
void SetRenderState(RenderState state, bool enabled) override;
|
||||
|
||||
void SetColorMask(bool red, bool green, bool blue, bool alpha) override;
|
||||
|
||||
void SetDepthTestFunc(CompFunc func) override;
|
||||
|
||||
void SetDepthBias(float factor, float units) override;
|
||||
|
||||
void SetAlphaTestFunc(CompFunc func, float refValue) override;
|
||||
|
||||
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override;
|
||||
|
||||
void SetClearColor(const Color &color) override;
|
||||
|
||||
void SetGlobalAmbient(const Color &color) override;
|
||||
|
||||
void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override;
|
||||
|
||||
void SetCullMode(CullMode mode) override;
|
||||
|
||||
void SetShadeModel(ShadeModel model) override;
|
||||
|
||||
void SetShadowColor(float value) override;
|
||||
|
||||
void SetFillMode(FillMode mode) override;
|
||||
|
||||
void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override;
|
||||
|
||||
std::unique_ptr<CFrameBufferPixels> GetFrameBufferPixels() const override;
|
||||
|
||||
CFramebuffer* GetFramebuffer(std::string name) override;
|
||||
|
||||
CFramebuffer* CreateFramebuffer(std::string name, const FramebufferParams& params) override;
|
||||
|
||||
void DeleteFramebuffer(std::string name) override;
|
||||
|
||||
bool IsAnisotropySupported() override;
|
||||
int GetMaxAnisotropyLevel() override;
|
||||
|
||||
int GetMaxSamples() override;
|
||||
|
||||
bool IsShadowMappingSupported() override;
|
||||
|
||||
int GetMaxTextureSize() override;
|
||||
|
||||
bool IsFramebufferSupported() override;
|
||||
|
||||
private:
|
||||
//! Updates internal modelview matrix
|
||||
void UpdateModelviewMatrix();
|
||||
//! Updates position for given light based on transformation matrices
|
||||
void UpdateLightPosition(int index);
|
||||
//! Updates position for all lights based on transformation matrices
|
||||
void UpdateLightPositions();
|
||||
//! Updates the texture params for given texture stage
|
||||
void UpdateTextureParams(int index);
|
||||
|
||||
//! Enables shadows
|
||||
void EnableShadows();
|
||||
//! Disables shadows
|
||||
void DisableShadows();
|
||||
|
||||
template <typename Vertex>
|
||||
unsigned int CreateStaticBufferImpl(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
|
||||
template <typename Vertex>
|
||||
void UpdateStaticBufferImpl(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
|
||||
|
||||
private:
|
||||
//! Current config
|
||||
DeviceConfig m_config;
|
||||
|
||||
//! Current world matrix
|
||||
Math::Matrix m_worldMat;
|
||||
//! Current view matrix
|
||||
Math::Matrix m_viewMat;
|
||||
//! OpenGL modelview matrix = world matrix * view matrix
|
||||
Math::Matrix m_modelviewMat;
|
||||
//! Current projection matrix
|
||||
Math::Matrix m_projectionMat;
|
||||
//! Combined world-view-projection matrix
|
||||
Math::Matrix m_combinedMatrix;
|
||||
//! Current shadow matrix
|
||||
Math::Matrix m_shadowMatrix;
|
||||
//! true means that combined matrix is outdated
|
||||
bool m_combinedMatrixOutdated = true;
|
||||
|
||||
//! The current material
|
||||
Material m_material;
|
||||
|
||||
//! Whether lighting is enabled
|
||||
bool m_lighting = false;
|
||||
//! Current lights
|
||||
std::vector<Light> m_lights;
|
||||
//! Current lights enable status
|
||||
std::vector<bool> m_lightsEnabled;
|
||||
|
||||
//! Current textures; \c nullptr value means unassigned
|
||||
std::vector<Texture> m_currentTextures;
|
||||
//! Current texture stages enable status
|
||||
std::vector<bool> m_texturesEnabled;
|
||||
//! Current texture params
|
||||
std::vector<TextureStageParams> m_textureStageParams;
|
||||
//! Texture unit remap
|
||||
std::vector<int> m_remap;
|
||||
|
||||
//! Set of all created textures
|
||||
std::set<Texture> m_allTextures;
|
||||
//! White texture
|
||||
GLuint m_whiteTexture = 0;
|
||||
|
||||
//! Map of framebuffers
|
||||
std::map<std::string, std::unique_ptr<CFramebuffer>> m_framebuffers;
|
||||
|
||||
//! Info about static VBO buffers
|
||||
struct VboObjectInfo
|
||||
{
|
||||
PrimitiveType primitiveType = {};
|
||||
unsigned int bufferId = 0;
|
||||
VertexType vertexType = {};
|
||||
int vertexCount = 0;
|
||||
};
|
||||
|
||||
//! Detected capabilities
|
||||
//! Depth texture support
|
||||
ShadowMappingSupport m_shadowMappingSupport = SMS_NONE;
|
||||
//! glMultiDrawArrays() available
|
||||
bool m_multiDrawArrays = false;
|
||||
//! Framebuffer support
|
||||
FramebufferSupport m_framebufferSupport = FBS_NONE;
|
||||
//! Map of saved VBO objects
|
||||
std::map<unsigned int, VboObjectInfo> m_vboObjects;
|
||||
//! Last ID of VBO object
|
||||
unsigned int m_lastVboId = 0;
|
||||
|
||||
//! true means shadow mapping is enabled
|
||||
bool m_shadowMapping = false;
|
||||
//! true means that quality shadows are enabled
|
||||
bool m_shadowQuality = true;
|
||||
|
||||
|
||||
//! Pointers to OpenGL functions
|
||||
PFNGLGENBUFFERSPROC m_glGenBuffers = nullptr;
|
||||
PFNGLDELETEBUFFERSPROC m_glDeleteBuffers = nullptr;
|
||||
PFNGLBINDBUFFERPROC m_glBindBuffer = nullptr;
|
||||
PFNGLBUFFERDATAPROC m_glBufferData = nullptr;
|
||||
PFNGLBUFFERSUBDATAPROC m_glBufferSubData = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Gfx
|
File diff suppressed because it is too large
Load Diff
|
@ -1,287 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file graphics/opengl/gl21device.h
|
||||
* \brief OpenGL implementation - CGL21Device class
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "graphics/core/device.h"
|
||||
|
||||
#include "graphics/core/material.h"
|
||||
|
||||
#include "graphics/opengl/glutil.h"
|
||||
|
||||
#include "math/matrix.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
// Graphics module namespace
|
||||
namespace Gfx
|
||||
{
|
||||
|
||||
/**
|
||||
\class CGL21Device
|
||||
\brief Implementation of CDevice interface in OpenGL
|
||||
|
||||
Provides the concrete implementation of 3D device in OpenGL.
|
||||
|
||||
This class should be initialized (by calling Initialize() ) only after
|
||||
setting the video mode by CApplication, once the OpenGL context is defined.
|
||||
Because of that, CGL21DeviceConfig is outside the CDevice class and must be set
|
||||
in CApplication.
|
||||
*/
|
||||
class CGL21Device : public CDevice
|
||||
{
|
||||
public:
|
||||
CGL21Device(const DeviceConfig &config);
|
||||
virtual ~CGL21Device();
|
||||
|
||||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
||||
void ConfigChanged(const DeviceConfig &newConfig) override;
|
||||
|
||||
void BeginScene() override;
|
||||
void EndScene() override;
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void SetRenderMode(RenderMode mode) override;
|
||||
|
||||
void SetTransform(TransformType type, const Math::Matrix &matrix) override;
|
||||
|
||||
void SetMaterial(const Material &material) override;
|
||||
|
||||
int GetMaxLightCount() override;
|
||||
void SetLight(int index, const Light &light) override;
|
||||
void SetLightEnabled(int index, bool enabled) override;
|
||||
|
||||
Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override;
|
||||
Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms) override;
|
||||
Texture CreateDepthTexture(int width, int height, int depth) override;
|
||||
void UpdateTexture(const Texture& texture, Math::IntPoint offset, ImageData* data, TexImgFormat format) override;
|
||||
void DestroyTexture(const Texture &texture) override;
|
||||
void DestroyAllTextures() override;
|
||||
|
||||
int GetMaxTextureStageCount() override;
|
||||
void SetTexture(int index, const Texture &texture) override;
|
||||
void SetTexture(int index, unsigned int textureId) override;
|
||||
void SetTextureEnabled(int index, bool enabled) override;
|
||||
|
||||
void SetTextureStageParams(int index, const TextureStageParams ¶ms) override;
|
||||
|
||||
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override;
|
||||
|
||||
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) override;
|
||||
|
||||
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices,
|
||||
int first[], int count[], int drawCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices,
|
||||
int first[], int count[], int drawCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
|
||||
virtual void DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
|
||||
int first[], int count[], int drawCount) override;
|
||||
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override
|
||||
{
|
||||
return CreateStaticBufferImpl(primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override
|
||||
{
|
||||
UpdateStaticBufferImpl(bufferId, primitiveType, vertices, vertexCount);
|
||||
}
|
||||
void DrawStaticBuffer(unsigned int bufferId) override;
|
||||
void DestroyStaticBuffer(unsigned int bufferId) override;
|
||||
|
||||
int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override;
|
||||
|
||||
void SetViewport(int x, int y, int width, int height) override;
|
||||
|
||||
void SetRenderState(RenderState state, bool enabled) override;
|
||||
|
||||
void SetColorMask(bool red, bool green, bool blue, bool alpha) override;
|
||||
|
||||
void SetDepthTestFunc(CompFunc func) override;
|
||||
|
||||
void SetDepthBias(float factor, float units) override;
|
||||
|
||||
void SetAlphaTestFunc(CompFunc func, float refValue) override;
|
||||
|
||||
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override;
|
||||
|
||||
void SetClearColor(const Color &color) override;
|
||||
|
||||
void SetGlobalAmbient(const Color &color) override;
|
||||
|
||||
void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override;
|
||||
|
||||
void SetCullMode(CullMode mode) override;
|
||||
|
||||
void SetShadeModel(ShadeModel model) override;
|
||||
|
||||
void SetShadowColor(float value) override;
|
||||
|
||||
void SetFillMode(FillMode mode) override;
|
||||
|
||||
void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override;
|
||||
|
||||
std::unique_ptr<CFrameBufferPixels> GetFrameBufferPixels() const override;
|
||||
|
||||
CFramebuffer* GetFramebuffer(std::string name) override;
|
||||
|
||||
CFramebuffer* CreateFramebuffer(std::string name, const FramebufferParams& params) override;
|
||||
|
||||
void DeleteFramebuffer(std::string name) override;
|
||||
|
||||
bool IsAnisotropySupported() override;
|
||||
int GetMaxAnisotropyLevel() override;
|
||||
|
||||
int GetMaxSamples() override;
|
||||
|
||||
bool IsShadowMappingSupported() override;
|
||||
|
||||
int GetMaxTextureSize() override;
|
||||
|
||||
bool IsFramebufferSupported() override;
|
||||
|
||||
private:
|
||||
//! Updates the texture params for given texture stage
|
||||
void UpdateTextureParams(int index);
|
||||
//! Updates texture state
|
||||
void UpdateTextureState(int index);
|
||||
//! Update light parameters
|
||||
void UpdateLights();
|
||||
//! Binds VBO
|
||||
inline void BindVBO(GLuint vbo);
|
||||
//! Binds texture
|
||||
inline void BindTexture(int index, GLuint texture);
|
||||
|
||||
template <typename Vertex>
|
||||
unsigned int CreateStaticBufferImpl(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
|
||||
template <typename Vertex>
|
||||
void UpdateStaticBufferImpl(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
|
||||
|
||||
private:
|
||||
//! Current config
|
||||
DeviceConfig m_config;
|
||||
|
||||
//! Current world matrix
|
||||
Math::Matrix m_worldMat;
|
||||
//! Current view matrix
|
||||
Math::Matrix m_viewMat;
|
||||
//! OpenGL modelview matrix = world matrix * view matrix
|
||||
Math::Matrix m_modelviewMat;
|
||||
//! Current projection matrix
|
||||
Math::Matrix m_projectionMat;
|
||||
//! Combined world-view-projection matrix
|
||||
Math::Matrix m_combinedMatrix;
|
||||
|
||||
//! The current material
|
||||
Material m_material;
|
||||
|
||||
//! Whether lighting is enabled
|
||||
bool m_lighting = false;
|
||||
//! true means that lights need to be updated
|
||||
bool m_updateLights = false;
|
||||
//! Current lights
|
||||
std::vector<Light> m_lights;
|
||||
//! Current lights enable status
|
||||
std::vector<bool> m_lightsEnabled;
|
||||
|
||||
//! Current textures; \c nullptr value means unassigned
|
||||
std::vector<Texture> m_currentTextures;
|
||||
//! Current texture stages enable status
|
||||
std::vector<bool> m_texturesEnabled;
|
||||
//! Current texture params
|
||||
std::vector<TextureStageParams> m_textureStageParams;
|
||||
|
||||
//! Set of all created textures
|
||||
std::set<Texture> m_allTextures;
|
||||
|
||||
//! Map of framebuffers
|
||||
std::map<std::string, std::unique_ptr<CFramebuffer>> m_framebuffers;
|
||||
|
||||
//! Info about static VBO buffers
|
||||
struct VboObjectInfo
|
||||
{
|
||||
PrimitiveType primitiveType = {};
|
||||
unsigned int bufferId = 0;
|
||||
VertexType vertexType = {};
|
||||
int vertexCount = 0;
|
||||
int size = 0;
|
||||
};
|
||||
|
||||
//! Detected capabilities
|
||||
//! Framebuffer support
|
||||
FramebufferSupport m_framebufferSupport = FBS_NONE;
|
||||
//! Map of saved VBO objects
|
||||
std::map<unsigned int, VboObjectInfo> m_vboObjects;
|
||||
//! Last ID of VBO object
|
||||
unsigned int m_lastVboId = 0;
|
||||
//! Currently bound VBO
|
||||
GLuint m_currentVBO = 0;
|
||||
|
||||
//! Shader program for normal rendering
|
||||
GLuint m_normalProgram = 0;
|
||||
//! Shader program for interface rendering
|
||||
GLuint m_interfaceProgram = 0;
|
||||
//! Shader program for shadow rendering
|
||||
GLuint m_shadowProgram = 0;
|
||||
|
||||
//! Uniform locations
|
||||
UniformLocations m_uniforms[3];
|
||||
//! Current mode
|
||||
int m_mode = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Gfx
|
|
@ -23,8 +23,6 @@
|
|||
#include "common/logger.h"
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include "graphics/opengl/gl14device.h"
|
||||
#include "graphics/opengl/gl21device.h"
|
||||
#include "graphics/opengl/gl33device.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
@ -71,18 +69,14 @@ FramebufferSupport DetectFramebufferSupport()
|
|||
|
||||
std::unique_ptr<CDevice> CreateDevice(const DeviceConfig &config, const std::string& name)
|
||||
{
|
||||
if (name == "default") return MakeUnique<CGL14Device>(config);
|
||||
else if (name == "opengl") return MakeUnique<CGL14Device>(config);
|
||||
else if (name == "gl14") return MakeUnique<CGL14Device>(config);
|
||||
else if (name == "gl21") return MakeUnique<CGL21Device>(config);
|
||||
if (name == "default") return MakeUnique<CGL33Device>(config);
|
||||
else if (name == "opengl") return MakeUnique<CGL33Device>(config);
|
||||
else if (name == "gl33") return MakeUnique<CGL33Device>(config);
|
||||
else if (name == "auto")
|
||||
{
|
||||
int version = GetOpenGLVersion();
|
||||
|
||||
if (version >= 33) return MakeUnique<CGL33Device>(config);
|
||||
else if (version >= 21) return MakeUnique<CGL21Device>(config);
|
||||
else return MakeUnique<CGL14Device>(config);
|
||||
if (version >= 33) return MakeUnique<CGL33Device>(config);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
install(DIRECTORY gl21 DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/shaders)
|
||||
install(DIRECTORY gl33 DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/shaders)
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// FRAGMENT SHADER - INTERFACE MODE
|
||||
#version 120
|
||||
|
||||
uniform sampler2D uni_PrimaryTexture;
|
||||
|
||||
uniform bool uni_TextureEnabled;
|
||||
|
||||
varying vec4 pass_Color;
|
||||
varying vec2 pass_TexCoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (uni_TextureEnabled)
|
||||
{
|
||||
gl_FragColor = pass_Color * texture2D(uni_PrimaryTexture, pass_TexCoord0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = pass_Color;
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// FRAGMENT SHADER - NORMAL MODE
|
||||
#version 120
|
||||
|
||||
#define CONFIG_QUALITY_SHADOWS 1
|
||||
|
||||
uniform sampler2D uni_PrimaryTexture;
|
||||
uniform sampler2D uni_SecondaryTexture;
|
||||
uniform sampler2DShadow uni_ShadowTexture;
|
||||
|
||||
uniform bool uni_TextureEnabled[3];
|
||||
|
||||
uniform bool uni_AlphaTestEnabled;
|
||||
uniform float uni_AlphaReference;
|
||||
|
||||
uniform bool uni_FogEnabled;
|
||||
uniform vec2 uni_FogRange;
|
||||
uniform vec4 uni_FogColor;
|
||||
|
||||
uniform float uni_ShadowColor;
|
||||
uniform float uni_ShadowTexelSize;
|
||||
|
||||
struct LightParams
|
||||
{
|
||||
vec4 Position;
|
||||
vec4 Ambient;
|
||||
vec4 Diffuse;
|
||||
vec4 Specular;
|
||||
};
|
||||
|
||||
struct Material
|
||||
{
|
||||
vec4 ambient;
|
||||
vec4 diffuse;
|
||||
vec4 specular;
|
||||
};
|
||||
|
||||
uniform Material uni_Material;
|
||||
|
||||
uniform int uni_LightCount;
|
||||
uniform LightParams uni_Light[4];
|
||||
|
||||
varying vec3 pass_CameraDirection;
|
||||
varying float pass_Distance;
|
||||
varying vec4 pass_Color;
|
||||
varying vec3 pass_Normal;
|
||||
varying vec2 pass_TexCoord0;
|
||||
varying vec2 pass_TexCoord1;
|
||||
varying vec3 pass_TexCoord2;
|
||||
|
||||
const vec3 const_LightDirection = vec3(1.0f, 2.0f, -1.0f);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = pass_Color;
|
||||
|
||||
if (uni_LightCount > 0)
|
||||
{
|
||||
vec4 ambient = vec4(0.0f);
|
||||
vec4 diffuse = vec4(0.0f);
|
||||
vec4 specular = vec4(0.0f);
|
||||
|
||||
vec3 normal = normalize(pass_Normal);
|
||||
vec3 camera = normalize(pass_CameraDirection);
|
||||
|
||||
for (int i = 0; i < uni_LightCount; i++)
|
||||
{
|
||||
LightParams light = uni_Light[i];
|
||||
|
||||
vec3 lightDirection = light.Position.xyz;
|
||||
vec3 reflectAxis = normalize(normalize(lightDirection) + camera);
|
||||
|
||||
float diffuseComponent = clamp(dot(normal, lightDirection), 0.0f, 1.0f);
|
||||
float specularComponent = pow(clamp(dot(normal, reflectAxis), 0.0f, 1.0f), 10.0f);
|
||||
|
||||
ambient += light.Ambient;
|
||||
diffuse += diffuseComponent * light.Diffuse;
|
||||
specular += specularComponent * light.Specular;
|
||||
}
|
||||
|
||||
float shadow = 1.0f;
|
||||
|
||||
if (uni_TextureEnabled[2])
|
||||
{
|
||||
#ifdef CONFIG_QUALITY_SHADOWS
|
||||
float value = (1.0f / 5.0f) * (shadow2D(uni_ShadowTexture, pass_TexCoord2).x
|
||||
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( uni_ShadowTexelSize, 0.0f, 0.0f)).x
|
||||
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3(-uni_ShadowTexelSize, 0.0f, 0.0f)).x
|
||||
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, uni_ShadowTexelSize, 0.0f)).x
|
||||
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, -uni_ShadowTexelSize, 0.0f)).x);
|
||||
|
||||
shadow = mix(uni_ShadowColor, 1.0f, value);
|
||||
#else
|
||||
shadow = mix(uni_ShadowColor, 1.0f, shadow2D(uni_ShadowTexture, pass_TexCoord2).x);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec4 result = ambient * uni_Material.ambient
|
||||
+ diffuse * uni_Material.diffuse * shadow
|
||||
+ specular * uni_Material.specular * shadow;
|
||||
|
||||
color = clamp(vec4(result.rgb, 1.0f), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
if (uni_TextureEnabled[0])
|
||||
{
|
||||
color = color * texture2D(uni_PrimaryTexture, pass_TexCoord0);
|
||||
}
|
||||
|
||||
if (uni_TextureEnabled[1])
|
||||
{
|
||||
color = color * texture2D(uni_SecondaryTexture, pass_TexCoord1);
|
||||
}
|
||||
|
||||
if (uni_FogEnabled)
|
||||
{
|
||||
float interpolate = (pass_Distance - uni_FogRange.x) / (uni_FogRange.y - uni_FogRange.x);
|
||||
|
||||
color = mix(color, uni_FogColor, clamp(interpolate, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (uni_AlphaTestEnabled)
|
||||
{
|
||||
if(color.a < uni_AlphaReference)
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// FRAGMENT SHADER - SHADOW MODE
|
||||
#version 120
|
||||
|
||||
uniform sampler2D uni_PrimaryTexture;
|
||||
|
||||
uniform bool uni_TextureEnabled;
|
||||
|
||||
uniform bool uni_AlphaTestEnabled;
|
||||
uniform float uni_AlphaReference;
|
||||
|
||||
varying vec2 pass_TexCoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0f);
|
||||
|
||||
if (uni_TextureEnabled)
|
||||
{
|
||||
color = color * texture2D(uni_PrimaryTexture, pass_TexCoord0);
|
||||
}
|
||||
|
||||
if (uni_AlphaTestEnabled)
|
||||
{
|
||||
if(color.a < uni_AlphaReference)
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(1.0f);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// VERTEX SHADER - INTERFACE MODE
|
||||
#version 120
|
||||
|
||||
uniform mat4 uni_ProjectionMatrix;
|
||||
uniform mat4 uni_ViewMatrix;
|
||||
uniform mat4 uni_ModelMatrix;
|
||||
|
||||
varying vec4 pass_Color;
|
||||
varying vec2 pass_TexCoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uni_ProjectionMatrix * uni_ViewMatrix * uni_ModelMatrix * gl_Vertex;
|
||||
|
||||
pass_Color = gl_Color;
|
||||
pass_TexCoord0 = gl_MultiTexCoord0.st;
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// VERTEX SHADER - NORMAL MODE
|
||||
#version 120
|
||||
|
||||
uniform mat4 uni_ProjectionMatrix;
|
||||
uniform mat4 uni_ViewMatrix;
|
||||
uniform mat4 uni_ModelMatrix;
|
||||
uniform mat4 uni_ShadowMatrix;
|
||||
uniform mat4 uni_NormalMatrix;
|
||||
uniform vec3 uni_CameraPosition;
|
||||
|
||||
varying vec3 pass_CameraDirection;
|
||||
varying float pass_Distance;
|
||||
varying vec4 pass_Color;
|
||||
varying vec3 pass_Normal;
|
||||
varying vec2 pass_TexCoord0;
|
||||
varying vec2 pass_TexCoord1;
|
||||
varying vec3 pass_TexCoord2;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = uni_ModelMatrix * gl_Vertex;
|
||||
vec4 eyeSpace = uni_ViewMatrix * position;
|
||||
vec4 shadowCoord = uni_ShadowMatrix * position;
|
||||
|
||||
gl_Position = uni_ProjectionMatrix * eyeSpace;
|
||||
|
||||
pass_CameraDirection = uni_CameraPosition - position.xyz;
|
||||
pass_Color = gl_Color;
|
||||
pass_Normal = normalize((uni_NormalMatrix * vec4(gl_Normal, 0.0f)).xyz);
|
||||
pass_Distance = abs(eyeSpace.z / eyeSpace.w);
|
||||
pass_TexCoord0 = gl_MultiTexCoord0.st;
|
||||
pass_TexCoord1 = gl_MultiTexCoord1.st;
|
||||
pass_TexCoord2 = shadowCoord.xyz / shadowCoord.w;
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
// VERTEX SHADER - SHADOW MODE
|
||||
#version 120
|
||||
|
||||
uniform mat4 uni_ProjectionMatrix;
|
||||
uniform mat4 uni_ViewMatrix;
|
||||
uniform mat4 uni_ModelMatrix;
|
||||
|
||||
varying vec2 pass_TexCoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uni_ProjectionMatrix * uni_ViewMatrix * uni_ModelMatrix * gl_Vertex;
|
||||
|
||||
pass_TexCoord0 = gl_MultiTexCoord0.st;
|
||||
}
|
Loading…
Reference in New Issue