Removed remaining rendering code from CGL33Device and fixed some issues
parent
cbf661f69f
commit
37bdc8665f
|
@ -157,7 +157,6 @@ enum RenderState
|
|||
RENDER_STATE_BLENDING,
|
||||
RENDER_STATE_DEPTH_TEST,
|
||||
RENDER_STATE_DEPTH_WRITE,
|
||||
RENDER_STATE_ALPHA_TEST,
|
||||
RENDER_STATE_CULLING,
|
||||
};
|
||||
|
||||
|
@ -437,12 +436,6 @@ public:
|
|||
//! Returns shadow renderer
|
||||
virtual CShadowRenderer* GetShadowRenderer() = 0;
|
||||
|
||||
//! Restores device rendering mode
|
||||
virtual void Restore() = 0;
|
||||
|
||||
//! Sets the transform matrix of given type
|
||||
virtual void SetTransform(TransformType type, const glm::mat4 &matrix) = 0;
|
||||
|
||||
//! Creates a texture from image; the image can be safely removed after that
|
||||
virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) = 0;
|
||||
//! Creates a texture from raw image data; image data can be freed after that
|
||||
|
@ -456,15 +449,6 @@ public:
|
|||
//! Deletes all textures created so far
|
||||
virtual void DestroyAllTextures() = 0;
|
||||
|
||||
//! Returns the maximum number of multitexture stages
|
||||
virtual int GetMaxTextureStageCount() = 0;
|
||||
//! Sets the texture at given texture stage
|
||||
virtual void SetTexture(int index, const Texture &texture) = 0;
|
||||
//! Sets the texture image by ID at given texture stage
|
||||
virtual void SetTexture(int index, unsigned int textureId) = 0;
|
||||
//! Enables/disables the given texture stage
|
||||
virtual void SetTextureEnabled(int index, bool enabled) = 0;
|
||||
|
||||
//! Renders primitive composed of vertices with single texture
|
||||
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
|
||||
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
|
||||
|
@ -493,12 +477,6 @@ public:
|
|||
//! Sets the color mask
|
||||
virtual void SetColorMask(bool red, bool green, bool blue, bool alpha) = 0;
|
||||
|
||||
//! Sets the alpha test function and reference value
|
||||
virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0;
|
||||
|
||||
//! Sets the blending functions for source and destination operations
|
||||
virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0;
|
||||
|
||||
//! Sets the clear color
|
||||
virtual void SetClearColor(const Color &color) = 0;
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ void CCloud::Draw()
|
|||
float deep = (m_brickCount*m_brickSize)/2.0f;
|
||||
m_engine->SetDeepView(deep);
|
||||
m_engine->SetFocus(m_engine->GetFocus());
|
||||
m_engine->UpdateMatProj(); // increases the depth of view
|
||||
|
||||
float fogStart = deep*0.15f;
|
||||
float fogEnd = deep*0.24f;
|
||||
|
@ -188,7 +187,6 @@ void CCloud::Draw()
|
|||
|
||||
m_engine->SetDeepView(iDeep);
|
||||
m_engine->SetFocus(m_engine->GetFocus());
|
||||
m_engine->UpdateMatProj(); // gives depth to initial
|
||||
}
|
||||
|
||||
void CCloud::CreateLine(int x, int y, int len)
|
||||
|
|
|
@ -2285,37 +2285,6 @@ void CEngine::FlushTextureCache()
|
|||
m_firstGroundSpot = true;
|
||||
}
|
||||
|
||||
bool CEngine::SetTexture(const std::string& name, int stage)
|
||||
{
|
||||
auto it = m_texNameMap.find(name);
|
||||
if (it != m_texNameMap.end())
|
||||
{
|
||||
m_device->SetTexture(stage, (*it).second);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! LoadTexture(name).Valid())
|
||||
{
|
||||
m_device->SetTexture(stage, 0); // invalid texture
|
||||
return false;
|
||||
}
|
||||
|
||||
it = m_texNameMap.find(name);
|
||||
if (it != m_texNameMap.end())
|
||||
{
|
||||
m_device->SetTexture(stage, (*it).second);
|
||||
return true;
|
||||
}
|
||||
|
||||
m_device->SetTexture(stage, 0); // invalid texture
|
||||
return false; // should not happen normally
|
||||
}
|
||||
|
||||
void CEngine::SetTexture(const Texture& tex, int stage)
|
||||
{
|
||||
m_device->SetTexture(stage, tex);
|
||||
}
|
||||
|
||||
void CEngine::SetTerrainVision(float vision)
|
||||
{
|
||||
m_terrainVision = vision;
|
||||
|
@ -2659,7 +2628,7 @@ int CEngine::GetTextureAnisotropyLevel()
|
|||
|
||||
bool CEngine::IsShadowMappingSupported()
|
||||
{
|
||||
return m_device->IsShadowMappingSupported() && m_device->GetMaxTextureStageCount() >= 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEngine::SetShadowMapping(bool value)
|
||||
|
@ -2718,7 +2687,7 @@ int CEngine::GetShadowMappingOffscreenResolution()
|
|||
|
||||
bool CEngine::IsShadowMappingQualitySupported()
|
||||
{
|
||||
return IsShadowMappingSupported() && m_device->GetMaxTextureStageCount() >= 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEngine::SetShadowMappingQuality(bool value)
|
||||
|
@ -2860,11 +2829,6 @@ bool CEngine::IsVisiblePoint(const glm::vec3 &pos)
|
|||
return glm::distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance);
|
||||
}
|
||||
|
||||
void CEngine::UpdateMatProj()
|
||||
{
|
||||
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProj);
|
||||
}
|
||||
|
||||
void CEngine::ApplyChange()
|
||||
{
|
||||
SetFocus(m_focus);
|
||||
|
@ -2987,9 +2951,6 @@ void CEngine::Draw3DScene()
|
|||
float fogStart = m_deepView[m_rankView] * m_fogStart[m_rankView] * m_clippingDistance;
|
||||
float fogEnd = m_deepView[m_rankView] * m_clippingDistance;
|
||||
|
||||
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProj);
|
||||
m_device->SetTransform(TRANSFORM_VIEW, m_matView);
|
||||
|
||||
// TODO: This causes a rendering artifact and I can't see anything that breaks if you just comment it out
|
||||
// So I'll just leave it like that for now ~krzys_h
|
||||
//m_water->DrawBack(); // draws water background
|
||||
|
@ -3285,7 +3246,7 @@ void CEngine::Draw3DScene()
|
|||
if (m_debugGoto)
|
||||
{
|
||||
glm::mat4 worldMatrix = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
|
||||
//m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
|
||||
|
||||
//SetState(ENG_RSTATE_OPAQUE_COLOR);
|
||||
|
||||
|
@ -3560,7 +3521,7 @@ void CEngine::RenderPendingDebugDraws()
|
|||
{
|
||||
if (m_pendingDebugDraws.firsts.empty()) return;
|
||||
|
||||
m_device->SetTransform(TRANSFORM_WORLD, glm::mat4(1.0f));
|
||||
//m_device->SetTransform(TRANSFORM_WORLD, glm::mat4(1.0f));
|
||||
|
||||
//SetState(ENG_RSTATE_OPAQUE_COLOR);
|
||||
|
||||
|
@ -3740,7 +3701,6 @@ void CEngine::RenderShadowMap()
|
|||
|
||||
CProfiler::StopPerformanceCounter(PCNT_RENDER_SHADOW_MAP);
|
||||
|
||||
m_device->Restore();
|
||||
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
|
||||
}
|
||||
|
||||
|
@ -3804,8 +3764,6 @@ void CEngine::UseMSAA(bool enable)
|
|||
|
||||
void CEngine::DrawInterface()
|
||||
{
|
||||
m_device->Restore();
|
||||
|
||||
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
|
||||
|
||||
SetInterfaceCoordinates();
|
||||
|
@ -3928,8 +3886,6 @@ void CEngine::DrawInterface()
|
|||
|
||||
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
|
||||
|
||||
m_device->Restore();
|
||||
|
||||
SetInterfaceCoordinates();
|
||||
}
|
||||
|
||||
|
@ -3946,8 +3902,6 @@ void CEngine::DrawInterface()
|
|||
|
||||
if (m_renderInterface)
|
||||
DrawMouse();
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CEngine::UpdateGroundSpotTextures()
|
||||
|
@ -4262,10 +4216,10 @@ void CEngine::DrawShadowSpots()
|
|||
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
|
||||
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
//m_device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
// TODO: create a separate texture
|
||||
SetTexture("textures/effect03.png");
|
||||
//SetTexture("textures/effect03.png");
|
||||
|
||||
glm::vec2 ts, ti;
|
||||
|
||||
|
@ -4451,8 +4405,6 @@ void CEngine::DrawShadowSpots()
|
|||
|
||||
void CEngine::DrawBackground()
|
||||
{
|
||||
m_device->Restore();
|
||||
|
||||
if (m_cloud->GetLevel() != 0.0f) // clouds ?
|
||||
{
|
||||
if (m_backgroundCloudUp != m_backgroundCloudDown) // degraded?
|
||||
|
@ -4468,8 +4420,6 @@ void CEngine::DrawBackground()
|
|||
{
|
||||
DrawBackgroundImage(); // image
|
||||
}
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
|
||||
|
@ -4626,24 +4576,18 @@ void CEngine::DrawForegroundImage()
|
|||
float v2 = 1.0f;
|
||||
|
||||
|
||||
Vertex vertex[4] =
|
||||
Vertex2D vertex[4] =
|
||||
{
|
||||
{ glm::vec3(p1.x, p1.y, 0.0f), n, { u1, v2 } },
|
||||
{ glm::vec3(p1.x, p2.y, 0.0f), n, { u1, v1 } },
|
||||
{ glm::vec3(p2.x, p1.y, 0.0f), n, { u2, v2 } },
|
||||
{ glm::vec3(p2.x, p2.y, 0.0f), n, { u2, v1 } }
|
||||
{ { p1.x, p1.y }, { u1, v2 } },
|
||||
{ { p1.x, p2.y }, { u1, v1 } },
|
||||
{ { p2.x, p1.y }, { u2, v2 } },
|
||||
{ { p2.x, p2.y }, { u2, v1 } }
|
||||
};
|
||||
|
||||
SetTexture(m_foregroundTex);
|
||||
//SetState(ENG_RSTATE_TTEXTURE_BLACK);
|
||||
|
||||
m_device->Restore();
|
||||
|
||||
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
|
||||
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface);
|
||||
|
||||
m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4);
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetTexture(m_foregroundTex);
|
||||
renderer->SetTransparency(TransparencyMode::BLACK);
|
||||
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex);
|
||||
AddStatisticTriangle(2);
|
||||
}
|
||||
|
||||
|
@ -4680,8 +4624,6 @@ void CEngine::DrawOverColor()
|
|||
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex);
|
||||
|
||||
AddStatisticTriangle(2);
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CEngine::DrawHighlight()
|
||||
|
@ -4733,8 +4675,6 @@ void CEngine::DrawHighlight()
|
|||
if (nbOut > 2)
|
||||
return;
|
||||
|
||||
//SetState(ENG_RSTATE_OPAQUE_COLOR);
|
||||
|
||||
float d = 0.5f + sinf(m_highlightTime * 6.0f) * 0.5f;
|
||||
d *= (p2.x - p1.x) * 0.1f;
|
||||
p1.x += d;
|
||||
|
@ -4742,37 +4682,41 @@ void CEngine::DrawHighlight()
|
|||
p2.x -= d;
|
||||
p2.y -= d;
|
||||
|
||||
Color color(1.0f, 1.0f, 0.0f); // yellow
|
||||
glm::u8vec4 color(255, 255, 0, 255); // yellow
|
||||
|
||||
VertexCol line[3] =
|
||||
Vertex2D line[3] =
|
||||
{
|
||||
{ { 0, 0, 0 }, color },
|
||||
{ { 0, 0, 0 }, color},
|
||||
{ { 0, 0, 0 }, color}
|
||||
{ { 0, 0 }, {}, color },
|
||||
{ { 0, 0 }, {}, color },
|
||||
{ { 0, 0 }, {}, color }
|
||||
};
|
||||
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetTransparency(TransparencyMode::NONE);
|
||||
renderer->SetTexture(Texture{});
|
||||
|
||||
float dx = (p2.x - p1.x) / 5.0f;
|
||||
float dy = (p2.y - p1.y) / 5.0f;
|
||||
|
||||
line[0].coord = glm::vec3(p1.x, p1.y + dy, 0.0f);
|
||||
line[1].coord = glm::vec3(p1.x, p1.y, 0.0f);
|
||||
line[2].coord = glm::vec3(p1.x + dx, p1.y, 0.0f);
|
||||
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
|
||||
line[0].position = glm::vec3(p1.x, p1.y + dy, 0.0f);
|
||||
line[1].position = glm::vec3(p1.x, p1.y, 0.0f);
|
||||
line[2].position = glm::vec3(p1.x + dx, p1.y, 0.0f);
|
||||
renderer->DrawPrimitive(PrimitiveType::LINE_STRIP, 3, line);
|
||||
|
||||
line[0].coord = glm::vec3(p2.x - dx, p1.y, 0.0f);
|
||||
line[1].coord = glm::vec3(p2.x, p1.y, 0.0f);
|
||||
line[2].coord = glm::vec3(p2.x, p1.y + dy, 0.0f);
|
||||
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
|
||||
line[0].position = glm::vec3(p2.x - dx, p1.y, 0.0f);
|
||||
line[1].position = glm::vec3(p2.x, p1.y, 0.0f);
|
||||
line[2].position = glm::vec3(p2.x, p1.y + dy, 0.0f);
|
||||
renderer->DrawPrimitive(PrimitiveType::LINE_STRIP, 3, line);
|
||||
|
||||
line[0].coord = glm::vec3(p2.x, p2.y - dy, 0.0f);
|
||||
line[1].coord = glm::vec3(p2.x, p2.y, 0.0f);
|
||||
line[2].coord = glm::vec3(p2.x - dx, p2.y, 0.0f);
|
||||
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
|
||||
line[0].position = glm::vec3(p2.x, p2.y - dy, 0.0f);
|
||||
line[1].position = glm::vec3(p2.x, p2.y, 0.0f);
|
||||
line[2].position = glm::vec3(p2.x - dx, p2.y, 0.0f);
|
||||
renderer->DrawPrimitive(PrimitiveType::LINE_STRIP, 3, line);
|
||||
|
||||
line[0].coord = glm::vec3(p1.x + dx, p2.y, 0.0f);
|
||||
line[1].coord = glm::vec3(p1.x, p2.y, 0.0f);
|
||||
line[2].coord = glm::vec3(p1.x, p2.y - dy, 0.0f);
|
||||
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
|
||||
line[0].position = glm::vec3(p1.x + dx, p2.y, 0.0f);
|
||||
line[1].position = glm::vec3(p1.x, p2.y, 0.0f);
|
||||
line[2].position = glm::vec3(p1.x, p2.y - dy, 0.0f);
|
||||
renderer->DrawPrimitive(PrimitiveType::LINE_STRIP, 3, line);
|
||||
}
|
||||
|
||||
void CEngine::DrawMouse()
|
||||
|
@ -4844,7 +4788,6 @@ void CEngine::DrawStats()
|
|||
|
||||
glm::vec2 pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height);
|
||||
|
||||
//SetState(ENG_RSTATE_TCOLOR_ALPHA);
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetTransparency(TransparencyMode::ALPHA);
|
||||
renderer->SetTexture(Texture{});
|
||||
|
@ -5220,10 +5163,6 @@ void CEngine::SetDebugGotoBitmap(std::unique_ptr<CImage> debugImage)
|
|||
|
||||
void CEngine::SetInterfaceCoordinates()
|
||||
{
|
||||
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
|
||||
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface);
|
||||
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
@ -5244,17 +5183,6 @@ void CEngine::DisablePauseBlur()
|
|||
|
||||
void CEngine::SetWindowCoordinates()
|
||||
{
|
||||
glm::mat4 matWorldWindow = glm::mat4(1.0f);
|
||||
|
||||
glm::mat4 matViewWindow = glm::mat4(1.0f);
|
||||
|
||||
glm::mat4 matProjWindow;
|
||||
Math::LoadOrthoProjectionMatrix(matProjWindow, 0.0f, m_size.x, m_size.y, 0.0f, -1.0f, 1.0f);
|
||||
|
||||
m_device->SetTransform(TRANSFORM_VIEW, matViewWindow);
|
||||
m_device->SetTransform(TRANSFORM_PROJECTION, matProjWindow);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, matWorldWindow);
|
||||
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f);
|
||||
}
|
||||
|
|
|
@ -872,12 +872,6 @@ public:
|
|||
float shift = 0.0f, bool hsv = false);
|
||||
//@}
|
||||
|
||||
//! Sets texture for given stage; if not present in cache, the texture is loaded
|
||||
/** If loading fails, returns false. */
|
||||
bool SetTexture(const std::string& name, int stage = 0);
|
||||
//! Sets texture for given stage
|
||||
void SetTexture(const Texture& tex, int stage = 0);
|
||||
|
||||
//! Deletes the given texture, unloading it and removing from cache
|
||||
void DeleteTexture(const std::string& texName);
|
||||
//! Deletes the given texture, unloading it and removing from cache
|
||||
|
@ -1140,9 +1134,6 @@ public:
|
|||
//! Indicates whether a point is visible
|
||||
bool IsVisiblePoint(const glm::vec3& pos);
|
||||
|
||||
//! Resets the projection matrix after changes
|
||||
void UpdateMatProj();
|
||||
|
||||
//! Updates the scene after a change of parameters
|
||||
void ApplyChange();
|
||||
|
||||
|
|
|
@ -223,9 +223,9 @@ void CLightning::Draw()
|
|||
CDevice* device = m_engine->GetDevice();
|
||||
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
//device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
m_engine->SetTexture("textures/effect00.png");
|
||||
//m_engine->SetTexture("textures/effect00.png");
|
||||
//m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK);
|
||||
|
||||
glm::vec2 texInf;
|
||||
|
|
|
@ -156,9 +156,6 @@ public:
|
|||
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, quad.vertices);
|
||||
}
|
||||
|
||||
//const Vertex* vertices = m_quads.front().vertices;
|
||||
//m_engine.GetDevice()->DrawPrimitives(PrimitiveType::TRIANGLE_STRIP, vertices, m_firsts.data(),
|
||||
// m_counts.data(), static_cast<int>(m_quads.size()), m_color);
|
||||
m_engine.AddStatisticTriangle(static_cast<int>(m_quads.size() * 2));
|
||||
m_quads.clear();
|
||||
}
|
||||
|
@ -970,18 +967,17 @@ void CText::DrawString(const std::string &text, FontType font,
|
|||
void CText::DrawHighlight(FontMetaChar hl, const glm::ivec2& pos, const glm::ivec2& size)
|
||||
{
|
||||
// Gradient colors
|
||||
Color grad[4];
|
||||
glm::u8vec4 grad[4];
|
||||
|
||||
// TODO: switch to alpha factors
|
||||
|
||||
if ((hl & FONT_MASK_LINK) != 0)
|
||||
{
|
||||
grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f);
|
||||
grad[0] = grad[1] = grad[2] = grad[3] = { 0, 0, 255, 128 };
|
||||
}
|
||||
else if ((hl & FONT_MASK_HIGHLIGHT) == FONT_HIGHLIGHT_KEY)
|
||||
{
|
||||
grad[0] = grad[1] = grad[2] = grad[3] =
|
||||
Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f);
|
||||
grad[0] = grad[1] = grad[2] = grad[3] = { 192, 192, 192, 128 };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1008,20 +1004,19 @@ void CText::DrawHighlight(FontMetaChar hl, const glm::ivec2& pos, const glm::ive
|
|||
p1.y = pos.y - h; // just emphasized
|
||||
}
|
||||
|
||||
m_device->SetTextureEnabled(0, false);
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetTexture(Texture{});
|
||||
|
||||
VertexCol quad[] =
|
||||
Vertex2D quad[] =
|
||||
{
|
||||
{ glm::vec3(p1.x, p2.y, 0.0f), grad[3] },
|
||||
{ glm::vec3(p1.x, p1.y, 0.0f), grad[0] },
|
||||
{ glm::vec3(p2.x, p2.y, 0.0f), grad[2] },
|
||||
{ glm::vec3(p2.x, p1.y, 0.0f), grad[1] }
|
||||
{ { p1.x, p2.y }, {}, grad[3] },
|
||||
{ { p1.x, p1.y }, {}, grad[0] },
|
||||
{ { p2.x, p2.y }, {}, grad[2] },
|
||||
{ { p2.x, p1.y }, {}, grad[1] }
|
||||
};
|
||||
|
||||
m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad, 4);
|
||||
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, quad);
|
||||
m_engine->AddStatisticTriangle(2);
|
||||
|
||||
m_device->SetTextureEnabled(0, true);
|
||||
}
|
||||
|
||||
void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, glm::ivec2&pos, Color color)
|
||||
|
|
|
@ -185,101 +185,18 @@ bool CGL33Device::Create()
|
|||
m_capabilities.multitexturingSupported = true;
|
||||
m_capabilities.maxTextures = maxTextures;
|
||||
|
||||
m_currentTextures = std::vector<Texture> (maxTextures, Texture());
|
||||
m_texturesEnabled = std::vector<bool> (maxTextures, false);
|
||||
m_textureStageParams = std::vector<TextureStageParams>(maxTextures, TextureStageParams());
|
||||
|
||||
m_capabilities.shadowMappingSupported = true;
|
||||
|
||||
m_capabilities.framebufferSupported = true;
|
||||
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_capabilities.maxRenderbufferSize);
|
||||
GetLogger()->Info("Maximum renderbuffer size: %d\n", m_capabilities.maxRenderbufferSize);
|
||||
|
||||
// Create shader program for normal rendering
|
||||
GLint shaders[2];
|
||||
char filename[64];
|
||||
|
||||
strcpy(filename, "shaders/gl33/vs_normal.glsl");
|
||||
shaders[0] = LoadShader(GL_VERTEX_SHADER, filename);
|
||||
if (shaders[0] == 0)
|
||||
{
|
||||
m_errorMessage = GetLastShaderError();
|
||||
GetLogger()->Error("Cound not create vertex shader from file '%s'\n", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
strcpy(filename, "shaders/gl33/fs_normal.glsl");
|
||||
shaders[1] = LoadShader(GL_FRAGMENT_SHADER, filename);
|
||||
if (shaders[1] == 0)
|
||||
{
|
||||
m_errorMessage = GetLastShaderError();
|
||||
GetLogger()->Error("Cound not create fragment shader from file '%s'\n", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_normalProgram = LinkProgram(2, shaders);
|
||||
if (m_normalProgram == 0)
|
||||
{
|
||||
m_errorMessage = GetLastShaderError();
|
||||
GetLogger()->Error("Cound not link shader program for normal rendering\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
glDeleteShader(shaders[0]);
|
||||
glDeleteShader(shaders[1]);
|
||||
|
||||
// Obtain uniform locations
|
||||
glUseProgram(m_normalProgram);
|
||||
|
||||
{
|
||||
UniformLocations &uni = m_uniforms;
|
||||
|
||||
uni.projectionMatrix = glGetUniformLocation(m_normalProgram, "uni_ProjectionMatrix");
|
||||
uni.viewMatrix = glGetUniformLocation(m_normalProgram, "uni_ViewMatrix");
|
||||
uni.modelMatrix = glGetUniformLocation(m_normalProgram, "uni_ModelMatrix");
|
||||
uni.normalMatrix = glGetUniformLocation(m_normalProgram, "uni_NormalMatrix");
|
||||
uni.shadowMatrix = glGetUniformLocation(m_normalProgram, "uni_ShadowMatrix");
|
||||
uni.cameraPosition = glGetUniformLocation(m_normalProgram, "uni_CameraPosition");
|
||||
|
||||
uni.primaryTexture = glGetUniformLocation(m_normalProgram, "uni_PrimaryTexture");
|
||||
uni.secondaryTexture = glGetUniformLocation(m_normalProgram, "uni_SecondaryTexture");
|
||||
|
||||
uni.textureEnabled[0] = glGetUniformLocation(m_normalProgram, "uni_PrimaryTextureEnabled");
|
||||
uni.textureEnabled[1] = glGetUniformLocation(m_normalProgram, "uni_SecondaryTextureEnabled");
|
||||
uni.textureEnabled[2] = glGetUniformLocation(m_normalProgram, "uni_ShadowTextureEnabled");
|
||||
|
||||
uni.alphaTestEnabled = glGetUniformLocation(m_normalProgram, "uni_AlphaTestEnabled");
|
||||
uni.alphaReference = glGetUniformLocation(m_normalProgram, "uni_AlphaReference");
|
||||
|
||||
// Set default uniform values
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
|
||||
glUniformMatrix4fv(uni.projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.viewMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.modelMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.normalMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.shadowMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniform3f(uni.cameraPosition, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glUniform1i(uni.primaryTexture, 0);
|
||||
glUniform1i(uni.secondaryTexture, 1);
|
||||
|
||||
glUniform1i(uni.textureEnabled[0], 0);
|
||||
glUniform1i(uni.textureEnabled[1], 0);
|
||||
glUniform1i(uni.textureEnabled[2], 0);
|
||||
|
||||
glUniform1i(uni.alphaTestEnabled, 0);
|
||||
glUniform1f(uni.alphaReference, 0.5f);
|
||||
}
|
||||
|
||||
m_uiRenderer = std::make_unique<CGL33UIRenderer>(this);
|
||||
m_terrainRenderer = std::make_unique<CGL33TerrainRenderer>(this);
|
||||
m_objectRenderer = std::make_unique<CGL33ObjectRenderer>(this);
|
||||
m_particleRenderer = std::make_unique<CGL33ParticleRenderer>(this);
|
||||
m_shadowRenderer = std::make_unique<CGL33ShadowRenderer>(this);
|
||||
|
||||
glUseProgram(m_normalProgram);
|
||||
|
||||
// create default framebuffer object
|
||||
FramebufferParams framebufferParams;
|
||||
|
||||
|
@ -289,19 +206,6 @@ bool CGL33Device::Create()
|
|||
|
||||
m_framebuffers["default"] = MakeUnique<CDefaultFramebuffer>(framebufferParams);
|
||||
|
||||
// create dynamic buffer
|
||||
glGenVertexArrays(1, &m_dynamicBuffer.vao);
|
||||
|
||||
m_dynamicBuffer.size = 4 * 1024 * 1024;
|
||||
m_dynamicBuffer.offset = 0;
|
||||
|
||||
glGenBuffers(1, &m_dynamicBuffer.vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_dynamicBuffer.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, m_dynamicBuffer.size, nullptr, GL_STREAM_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
m_vboMemory += m_dynamicBuffer.size;
|
||||
|
||||
GetLogger()->Info("CDevice created successfully\n");
|
||||
|
||||
return true;
|
||||
|
@ -311,7 +215,6 @@ void CGL33Device::Destroy()
|
|||
{
|
||||
// delete shader program
|
||||
glUseProgram(0);
|
||||
glDeleteProgram(m_normalProgram);
|
||||
|
||||
// delete framebuffers
|
||||
for (auto& framebuffer : m_framebuffers)
|
||||
|
@ -323,16 +226,6 @@ void CGL33Device::Destroy()
|
|||
// Should not be strictly necessary, but just in case
|
||||
DestroyAllTextures();
|
||||
|
||||
// delete dynamic buffer
|
||||
glDeleteVertexArrays(1, &m_dynamicBuffer.vao);
|
||||
glDeleteBuffers(1, &m_dynamicBuffer.vbo);
|
||||
|
||||
m_vboMemory -= m_dynamicBuffer.size;
|
||||
|
||||
m_currentTextures.clear();
|
||||
m_texturesEnabled.clear();
|
||||
m_textureStageParams.clear();
|
||||
|
||||
for (auto buffer : m_buffers)
|
||||
delete buffer;
|
||||
|
||||
|
@ -365,10 +258,6 @@ void CGL33Device::ConfigChanged(const DeviceConfig& newConfig)
|
|||
void CGL33Device::BeginScene()
|
||||
{
|
||||
Clear();
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, glm::value_ptr(m_projectionMat));
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, glm::value_ptr(m_viewMat));
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, glm::value_ptr(m_worldMat));
|
||||
}
|
||||
|
||||
void CGL33Device::EndScene()
|
||||
|
@ -409,57 +298,6 @@ CShadowRenderer* CGL33Device::GetShadowRenderer()
|
|||
return m_shadowRenderer.get();
|
||||
}
|
||||
|
||||
void CGL33Device::Restore()
|
||||
{
|
||||
glUseProgram(m_normalProgram);
|
||||
}
|
||||
|
||||
void CGL33Device::SetTransform(TransformType type, const glm::mat4 &matrix)
|
||||
{
|
||||
if (type == TRANSFORM_WORLD)
|
||||
{
|
||||
m_worldMat = matrix;
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, glm::value_ptr(m_worldMat));
|
||||
|
||||
m_modelviewMat = m_viewMat * m_worldMat;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
// normal transform
|
||||
glm::mat4 normalMat = glm::inverse(normalMat);
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.normalMatrix, 1, GL_TRUE, glm::value_ptr(normalMat));
|
||||
}
|
||||
else if (type == TRANSFORM_VIEW)
|
||||
{
|
||||
glm::mat4 scale = glm::mat4(1.0f);
|
||||
scale[2][2] = -1.0f;
|
||||
m_viewMat = scale * matrix;
|
||||
|
||||
m_modelviewMat = m_viewMat * m_worldMat;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, glm::value_ptr(m_viewMat));
|
||||
|
||||
if (m_uniforms.cameraPosition >= 0)
|
||||
{
|
||||
glm::vec3 cameraPosition = { 0, 0, 0 };
|
||||
cameraPosition = glm::vec3(glm::inverse(m_viewMat) * glm::vec4(cameraPosition, 1.0f));
|
||||
glUniform3fv(m_uniforms.cameraPosition, 1, glm::value_ptr(cameraPosition));
|
||||
}
|
||||
}
|
||||
else if (type == TRANSFORM_PROJECTION)
|
||||
{
|
||||
m_projectionMat = matrix;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, glm::value_ptr(m_projectionMat));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
/** If image is invalid, returns invalid texture.
|
||||
Otherwise, returns pointer to new Texture struct.
|
||||
This struct must not be deleted in other way than through DeleteTexture() */
|
||||
|
@ -494,7 +332,8 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p
|
|||
|
||||
glGenTextures(1, &result.id);
|
||||
|
||||
BindTexture(m_freeTexture, result.id);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, result.id);
|
||||
|
||||
// Set texture parameters
|
||||
GLint minF = GL_NEAREST, magF = GL_NEAREST;
|
||||
|
@ -570,7 +409,8 @@ Texture CGL33Device::CreateDepthTexture(int width, int height, int depth)
|
|||
|
||||
glGenTextures(1, &result.id);
|
||||
|
||||
BindTexture(m_freeTexture, result.id);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, result.id);
|
||||
|
||||
GLuint format = GL_DEPTH_COMPONENT;
|
||||
|
||||
|
@ -606,7 +446,8 @@ void CGL33Device::UpdateTexture(const Texture& texture, const glm::ivec2& offset
|
|||
{
|
||||
if (texture.id == 0) return;
|
||||
|
||||
BindTexture(m_freeTexture, texture.id);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
|
||||
PreparedTextureData texData = PrepareTextureData(data, format);
|
||||
|
||||
|
@ -623,13 +464,6 @@ void CGL33Device::UpdateTexture(const Texture& texture, const glm::ivec2& offset
|
|||
|
||||
void CGL33Device::DestroyTexture(const Texture &texture)
|
||||
{
|
||||
// Unbind the texture if in use anywhere
|
||||
for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
|
||||
{
|
||||
if (m_currentTextures[index] == texture)
|
||||
SetTexture(index, Texture()); // set to invalid texture
|
||||
}
|
||||
|
||||
auto it = m_allTextures.find(texture);
|
||||
if (it != m_allTextures.end())
|
||||
{
|
||||
|
@ -641,8 +475,11 @@ void CGL33Device::DestroyTexture(const Texture &texture)
|
|||
void CGL33Device::DestroyAllTextures()
|
||||
{
|
||||
// Unbind all texture stages
|
||||
for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
|
||||
SetTexture(index, Texture());
|
||||
for (int index = 0; index < 32; ++index)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + index);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
for (auto it = m_allTextures.begin(); it != m_allTextures.end(); ++it)
|
||||
glDeleteTextures(1, &(*it).id);
|
||||
|
@ -650,270 +487,31 @@ void CGL33Device::DestroyAllTextures()
|
|||
m_allTextures.clear();
|
||||
}
|
||||
|
||||
int CGL33Device::GetMaxTextureStageCount()
|
||||
{
|
||||
return m_currentTextures.size();
|
||||
}
|
||||
|
||||
/**
|
||||
If \a texture is invalid, unbinds the given texture.
|
||||
If valid, binds the texture and enables the given texture stage.
|
||||
The setting is remembered, even if texturing is disabled at the moment. */
|
||||
void CGL33Device::SetTexture(int index, const Texture &texture)
|
||||
{
|
||||
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
|
||||
|
||||
if (m_currentTextures[index].id == texture.id)
|
||||
return;
|
||||
|
||||
BindTexture(index, texture.id);
|
||||
|
||||
m_currentTextures[index] = texture; // remember the new value
|
||||
|
||||
UpdateTextureState(index);
|
||||
}
|
||||
|
||||
void CGL33Device::SetTexture(int index, unsigned int textureId)
|
||||
{
|
||||
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
|
||||
|
||||
if (m_currentTextures[index].id == textureId)
|
||||
return; // nothing to do
|
||||
|
||||
BindTexture(index, textureId);
|
||||
|
||||
m_currentTextures[index].id = textureId;
|
||||
|
||||
UpdateTextureState(index);
|
||||
}
|
||||
|
||||
void CGL33Device::SetTextureEnabled(int index, bool enabled)
|
||||
{
|
||||
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
|
||||
|
||||
if (m_texturesEnabled[index] == enabled)
|
||||
return;
|
||||
|
||||
m_texturesEnabled[index] = enabled;
|
||||
|
||||
UpdateTextureState(index);
|
||||
}
|
||||
|
||||
void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color)
|
||||
{
|
||||
return;
|
||||
|
||||
unsigned int size = vertexCount * sizeof(Vertex);
|
||||
|
||||
DynamicBuffer& buffer = m_dynamicBuffer;
|
||||
|
||||
BindVAO(buffer.vao);
|
||||
BindVBO(buffer.vbo);
|
||||
|
||||
unsigned int offset = UploadVertexData(buffer, vertices, size);
|
||||
|
||||
// Vertex coordinate
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, coord)));
|
||||
|
||||
// Normal
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, normal)));
|
||||
|
||||
// Color
|
||||
glDisableVertexAttribArray(2);
|
||||
glVertexAttrib4fv(2, color.Array());
|
||||
|
||||
// Texture coordinate 0
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, texCoord)));
|
||||
|
||||
// Texture coordinate 1
|
||||
glDisableVertexAttribArray(4);
|
||||
glVertexAttrib2f(4, 0.0f, 0.0f);
|
||||
|
||||
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
|
||||
|
||||
}
|
||||
|
||||
void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount)
|
||||
{
|
||||
return;
|
||||
|
||||
unsigned int size = vertexCount * sizeof(VertexCol);
|
||||
|
||||
DynamicBuffer& buffer = m_dynamicBuffer;
|
||||
|
||||
BindVAO(buffer.vao);
|
||||
BindVBO(buffer.vbo);
|
||||
|
||||
unsigned int offset = UploadVertexData(buffer, vertices, size);
|
||||
|
||||
// Vertex coordinate
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexCol),
|
||||
reinterpret_cast<void*>(offset + offsetof(VertexCol, coord)));
|
||||
|
||||
// Normal
|
||||
glDisableVertexAttribArray(1);
|
||||
glVertexAttrib3f(1, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Color
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(VertexCol),
|
||||
reinterpret_cast<void*>(offset + offsetof(VertexCol, color)));
|
||||
|
||||
// Texture coordinate 0
|
||||
glDisableVertexAttribArray(3);
|
||||
glVertexAttrib2f(3, 0.0f, 0.0f);
|
||||
|
||||
// Texture coordinate 1
|
||||
glDisableVertexAttribArray(4);
|
||||
glVertexAttrib2f(4, 0.0f, 0.0f);
|
||||
|
||||
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
|
||||
|
||||
}
|
||||
|
||||
void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount)
|
||||
{
|
||||
return;
|
||||
|
||||
unsigned int size = vertexCount * sizeof(Vertex3D);
|
||||
|
||||
DynamicBuffer& buffer = m_dynamicBuffer;
|
||||
|
||||
BindVAO(buffer.vao);
|
||||
BindVBO(buffer.vbo);
|
||||
|
||||
unsigned int offset = UploadVertexData(buffer, vertices, size);
|
||||
|
||||
// Vertex coordinate
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex3D, position)));
|
||||
|
||||
// Normal
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex3D, normal)));
|
||||
|
||||
// Color
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex3D),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex3D, color)));
|
||||
|
||||
// Texture coordinate 0
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex3D),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex3D, uv)));
|
||||
|
||||
// Texture coordinate 1
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex3D),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex3D, uv2)));
|
||||
|
||||
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
|
||||
|
||||
}
|
||||
|
||||
void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
|
||||
int first[], int count[], int drawCount, Color color)
|
||||
{
|
||||
return;
|
||||
|
||||
int vertexCount = 0;
|
||||
|
||||
for (int i = 0; i < drawCount; i++)
|
||||
{
|
||||
int currentCount = first[i] + count[i];
|
||||
|
||||
if (currentCount > vertexCount)
|
||||
vertexCount = currentCount;
|
||||
}
|
||||
|
||||
unsigned int size = vertexCount * sizeof(Vertex);
|
||||
|
||||
DynamicBuffer& buffer = m_dynamicBuffer;
|
||||
|
||||
BindVAO(buffer.vao);
|
||||
BindVBO(buffer.vbo);
|
||||
|
||||
unsigned int offset = UploadVertexData(buffer, vertices, size);
|
||||
|
||||
// Vertex coordinate
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, coord)));
|
||||
|
||||
// Normal
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, normal)));
|
||||
|
||||
// Color
|
||||
glDisableVertexAttribArray(2);
|
||||
glVertexAttrib4fv(2, color.Array());
|
||||
|
||||
// Texture coordinate 0
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<void*>(offset + offsetof(Vertex, texCoord)));
|
||||
|
||||
// Texture coordinate 1
|
||||
glDisableVertexAttribArray(4);
|
||||
glVertexAttrib2f(4, 0.0f, 0.0f);
|
||||
|
||||
glMultiDrawArrays(TranslateGfxPrimitive(type), first, count, drawCount);
|
||||
|
||||
}
|
||||
|
||||
void CGL33Device::DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
|
||||
int first[], int count[], int drawCount)
|
||||
{
|
||||
return;
|
||||
|
||||
int vertexCount = 0;
|
||||
|
||||
for (int i = 0; i < drawCount; i++)
|
||||
{
|
||||
int currentCount = first[i] + count[i];
|
||||
|
||||
if (currentCount > vertexCount)
|
||||
vertexCount = currentCount;
|
||||
}
|
||||
|
||||
unsigned int size = vertexCount * sizeof(VertexCol);
|
||||
|
||||
DynamicBuffer& buffer = m_dynamicBuffer;
|
||||
|
||||
BindVAO(buffer.vao);
|
||||
BindVBO(buffer.vbo);
|
||||
|
||||
unsigned int offset = UploadVertexData(buffer, vertices, size);
|
||||
|
||||
// Vertex coordinate
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexCol),
|
||||
reinterpret_cast<void*>(offset + offsetof(VertexCol, coord)));
|
||||
|
||||
// Normal
|
||||
glDisableVertexAttribArray(1);
|
||||
glVertexAttrib3f(1, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Color
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(VertexCol),
|
||||
reinterpret_cast<void*>(offset + offsetof(VertexCol, color)));
|
||||
|
||||
// Texture coordinate 0
|
||||
glDisableVertexAttribArray(3);
|
||||
glVertexAttrib2f(3, 0.0f, 0.0f);
|
||||
|
||||
// Texture coordinate 1
|
||||
glDisableVertexAttribArray(4);
|
||||
glVertexAttrib2f(4, 0.0f, 0.0f);
|
||||
|
||||
glMultiDrawArrays(TranslateGfxPrimitive(type), first, count, drawCount);
|
||||
|
||||
}
|
||||
|
||||
CVertexBuffer* CGL33Device::CreateVertexBuffer(PrimitiveType primitiveType, const Vertex3D* vertices, int vertexCount)
|
||||
|
@ -944,17 +542,13 @@ void CGL33Device::SetViewport(int x, int y, int width, int height)
|
|||
|
||||
void CGL33Device::SetRenderState(RenderState state, bool enabled)
|
||||
{
|
||||
return;
|
||||
|
||||
if (state == RENDER_STATE_DEPTH_WRITE)
|
||||
{
|
||||
glDepthMask(enabled ? GL_TRUE : GL_FALSE);
|
||||
return;
|
||||
}
|
||||
else if (state == RENDER_STATE_ALPHA_TEST)
|
||||
{
|
||||
glUniform1i(m_uniforms.alphaTestEnabled, enabled ? 1 : 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GLenum flag = 0;
|
||||
|
||||
|
@ -977,16 +571,6 @@ void CGL33Device::SetColorMask(bool red, bool green, bool blue, bool alpha)
|
|||
glColorMask(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
void CGL33Device::SetAlphaTestFunc(CompFunc func, float refValue)
|
||||
{
|
||||
glUniform1f(m_uniforms.alphaReference, refValue);
|
||||
}
|
||||
|
||||
void CGL33Device::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend)
|
||||
{
|
||||
glBlendFunc(TranslateGfxBlendFunc(srcBlend), TranslateGfxBlendFunc(dstBlend));
|
||||
}
|
||||
|
||||
void CGL33Device::SetClearColor(const Color &color)
|
||||
{
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
|
@ -996,7 +580,8 @@ void CGL33Device::CopyFramebufferToTexture(Texture& texture, int xOffset, int yO
|
|||
{
|
||||
if (texture.id == 0) return;
|
||||
|
||||
BindTexture(m_freeTexture, texture.id);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, x, y, width, height);
|
||||
}
|
||||
|
@ -1044,68 +629,6 @@ void CGL33Device::DeleteFramebuffer(std::string name)
|
|||
}
|
||||
}
|
||||
|
||||
inline void CGL33Device::UpdateTextureState(int index)
|
||||
{
|
||||
bool enabled = m_texturesEnabled[index] && (m_currentTextures[index].id != 0);
|
||||
glUniform1i(m_uniforms.textureEnabled[index], enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
inline void CGL33Device::BindVBO(GLuint vbo)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
m_currentVBO = vbo;
|
||||
}
|
||||
|
||||
inline void CGL33Device::BindVAO(GLuint vao)
|
||||
{
|
||||
glBindVertexArray(vao);
|
||||
m_currentVAO = vao;
|
||||
}
|
||||
|
||||
inline void CGL33Device::BindTexture(int index, GLuint texture)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + index);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
unsigned int CGL33Device::UploadVertexData(DynamicBuffer& buffer, const void* data, unsigned int size)
|
||||
{
|
||||
unsigned int nextOffset = buffer.offset + size;
|
||||
|
||||
// buffer limit exceeded
|
||||
// invalidate buffer for the next round of buffer streaming
|
||||
if (nextOffset > buffer.size)
|
||||
{
|
||||
glBufferData(GL_ARRAY_BUFFER, buffer.size, nullptr, GL_STREAM_DRAW);
|
||||
|
||||
buffer.offset = 0;
|
||||
nextOffset = size;
|
||||
}
|
||||
|
||||
unsigned int currentOffset = buffer.offset;
|
||||
|
||||
// map buffer for unsynchronized copying
|
||||
void* ptr = glMapBufferRange(GL_ARRAY_BUFFER, currentOffset, size,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
|
||||
if (ptr != nullptr)
|
||||
{
|
||||
memcpy(ptr, data, size);
|
||||
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
}
|
||||
// mapping failed, we must upload data with glBufferSubData
|
||||
else
|
||||
{
|
||||
GetLogger()->Debug("Buffer mapping failed (offset %d, size %d)\n", currentOffset, size);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, currentOffset, size, data);
|
||||
}
|
||||
|
||||
buffer.offset = nextOffset;
|
||||
|
||||
return currentOffset;
|
||||
}
|
||||
|
||||
bool CGL33Device::IsAnisotropySupported()
|
||||
{
|
||||
return m_capabilities.anisotropySupported;
|
||||
|
|
|
@ -119,10 +119,6 @@ public:
|
|||
CParticleRenderer* GetParticleRenderer() override;
|
||||
CShadowRenderer* GetShadowRenderer() override;
|
||||
|
||||
void Restore() override;
|
||||
|
||||
void SetTransform(TransformType type, const glm::mat4 &matrix) 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;
|
||||
|
@ -130,11 +126,6 @@ public:
|
|||
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;
|
||||
|
||||
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 VertexCol *vertices , int vertexCount) override;
|
||||
|
@ -156,10 +147,6 @@ public:
|
|||
|
||||
void SetColorMask(bool red, bool green, bool blue, bool alpha) override;
|
||||
|
||||
void SetAlphaTestFunc(CompFunc func, float refValue) override;
|
||||
|
||||
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override;
|
||||
|
||||
void SetClearColor(const Color &color) override;
|
||||
|
||||
void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override;
|
||||
|
@ -183,58 +170,16 @@ public:
|
|||
|
||||
bool IsFramebufferSupported() override;
|
||||
|
||||
private:
|
||||
//! Updates texture state
|
||||
inline void UpdateTextureState(int index);
|
||||
|
||||
//! Binds VBO
|
||||
inline void BindVBO(GLuint vbo);
|
||||
//! Binds VAO
|
||||
inline void BindVAO(GLuint vao);
|
||||
//! Binds texture
|
||||
inline void BindTexture(int index, GLuint texture);
|
||||
|
||||
//! Uploads data to dynamic buffer and returns offset to it
|
||||
unsigned int UploadVertexData(DynamicBuffer& buffer, const void* data, unsigned int size);
|
||||
|
||||
private:
|
||||
//! Current config
|
||||
DeviceConfig m_config;
|
||||
|
||||
//! Current world matrix
|
||||
glm::mat4 m_worldMat = glm::mat4(1.0f);
|
||||
//! Current view matrix
|
||||
glm::mat4 m_viewMat = glm::mat4(1.0f);
|
||||
//! OpenGL modelview matrix = world matrix * view matrix
|
||||
glm::mat4 m_modelviewMat = glm::mat4(1.0f);
|
||||
//! Current projection matrix
|
||||
glm::mat4 m_projectionMat = glm::mat4(1.0f);
|
||||
//! Combined world-view-projection matrix
|
||||
glm::mat4 m_combinedMatrix = glm::mat4(1.0f);
|
||||
//! true means combined matrix is outdated
|
||||
bool m_combinedMatrixOutdated = false;
|
||||
|
||||
//! 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;
|
||||
//! Free texture unit
|
||||
const int m_freeTexture = 3;
|
||||
|
||||
//! Detected capabilities
|
||||
//! Set of vertex buffers
|
||||
std::unordered_set<CVertexBuffer*> m_buffers;
|
||||
//! Last ID of VBO object
|
||||
unsigned int m_lastVboId = 0;
|
||||
//! Currently bound VBO
|
||||
GLuint m_currentVBO = 0;
|
||||
//! Currently bound VAO
|
||||
GLuint m_currentVAO = 0;
|
||||
|
||||
//! Total memory allocated in VBOs
|
||||
unsigned long m_vboMemory = 0;
|
||||
|
@ -242,14 +187,6 @@ private:
|
|||
//! Map of framebuffers
|
||||
std::map<std::string, std::unique_ptr<CFramebuffer>> m_framebuffers;
|
||||
|
||||
//! Shader program for normal rendering
|
||||
GLuint m_normalProgram = 0;
|
||||
|
||||
DynamicBuffer m_dynamicBuffer;
|
||||
|
||||
//! Uniform locations for all modes
|
||||
UniformLocations m_uniforms;
|
||||
|
||||
//! Interface renderer
|
||||
std::unique_ptr<CGL33UIRenderer> m_uiRenderer;
|
||||
//! Terrain renderer
|
||||
|
|
|
@ -199,8 +199,6 @@ void CGL33ObjectRenderer::CGL33ObjectRenderer::End()
|
|||
m_secondaryTexture = 0;
|
||||
m_shadowMap = 0;
|
||||
|
||||
m_device->Restore();
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,6 @@ void CGL33ParticleRenderer::End()
|
|||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CGL33ParticleRenderer::SetProjectionMatrix(const glm::mat4& matrix)
|
||||
|
|
|
@ -233,6 +233,7 @@ bool CGL33UIRenderer::EndPrimitive()
|
|||
glUseProgram(m_program);
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_uniformBuffer);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
UpdateUniforms();
|
||||
|
||||
|
@ -243,8 +244,6 @@ bool CGL33UIRenderer::EndPrimitive()
|
|||
m_mapped = false;
|
||||
m_backup = false;
|
||||
|
||||
m_device->Restore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -402,8 +401,6 @@ void CGL33TerrainRenderer::End()
|
|||
m_primaryTexture = 0;
|
||||
m_secondaryTexture = 0;
|
||||
m_shadowMap = 0;
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CGL33TerrainRenderer::SetProjectionMatrix(const glm::mat4& matrix)
|
||||
|
@ -598,8 +595,6 @@ void CGL33ShadowRenderer::End()
|
|||
glPolygonOffset(0.0f, 0.0f);
|
||||
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
m_device->Restore();
|
||||
}
|
||||
|
||||
void CGL33ShadowRenderer::SetProjectionMatrix(const glm::mat4& matrix)
|
||||
|
|
|
@ -1,63 +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 330 core
|
||||
|
||||
uniform sampler2D uni_PrimaryTexture;
|
||||
uniform sampler2D uni_SecondaryTexture;
|
||||
|
||||
uniform bool uni_PrimaryTextureEnabled;
|
||||
uniform bool uni_SecondaryTextureEnabled;
|
||||
|
||||
uniform bool uni_AlphaTestEnabled;
|
||||
uniform float uni_AlphaReference;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Color;
|
||||
vec2 TexCoord0;
|
||||
vec2 TexCoord1;
|
||||
vec3 Normal;
|
||||
} data;
|
||||
|
||||
out vec4 out_FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = data.Color;
|
||||
|
||||
if (uni_PrimaryTextureEnabled)
|
||||
{
|
||||
color = color * texture(uni_PrimaryTexture, data.TexCoord0);
|
||||
}
|
||||
|
||||
if (uni_SecondaryTextureEnabled)
|
||||
{
|
||||
color = color * texture(uni_SecondaryTexture, data.TexCoord1);
|
||||
}
|
||||
|
||||
if (uni_AlphaTestEnabled)
|
||||
{
|
||||
if(color.a < uni_AlphaReference)
|
||||
discard;
|
||||
}
|
||||
|
||||
out_FragColor = color;
|
||||
}
|
|
@ -1,53 +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 330 core
|
||||
|
||||
uniform mat4 uni_ProjectionMatrix;
|
||||
uniform mat4 uni_ViewMatrix;
|
||||
uniform mat4 uni_ModelMatrix;
|
||||
uniform mat4 uni_NormalMatrix;
|
||||
uniform vec3 uni_CameraPosition;
|
||||
|
||||
layout(location = 0) in vec4 in_VertexCoord;
|
||||
layout(location = 1) in vec3 in_Normal;
|
||||
layout(location = 2) in vec4 in_Color;
|
||||
layout(location = 3) in vec2 in_TexCoord0;
|
||||
layout(location = 4) in vec2 in_TexCoord1;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Color;
|
||||
vec2 TexCoord0;
|
||||
vec2 TexCoord1;
|
||||
vec3 Normal;
|
||||
} data;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = uni_ModelMatrix * in_VertexCoord;
|
||||
vec4 eyeSpace = uni_ViewMatrix * position;
|
||||
gl_Position = uni_ProjectionMatrix * eyeSpace;
|
||||
|
||||
data.Color = in_Color;
|
||||
data.TexCoord0 = in_TexCoord0;
|
||||
data.TexCoord1 = in_TexCoord1;
|
||||
data.Normal = normalize((uni_NormalMatrix * vec4(in_Normal, 0.0f)).xyz);
|
||||
}
|
Loading…
Reference in New Issue