Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/backend/gl/Device.cpp
Show All 14 Lines | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "Device.h" | #include "Device.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/hash.h" | |||||
#include "lib/ogl.h" | #include "lib/ogl.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "renderer/backend/gl/DeviceCommandContext.h" | #include "renderer/backend/gl/DeviceCommandContext.h" | ||||
#include "renderer/backend/gl/Texture.h" | #include "renderer/backend/gl/Texture.h" | ||||
#include "scriptinterface/JSON.h" | #include "scriptinterface/JSON.h" | ||||
#include "scriptinterface/Object.h" | #include "scriptinterface/Object.h" | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | #endif | ||||
if (arb) | if (arb) | ||||
{ | { | ||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
glEnable(GL_VERTEX_PROGRAM_ARB); | glEnable(GL_VERTEX_PROGRAM_ARB); | ||||
glEnable(GL_FRAGMENT_PROGRAM_ARB); | glEnable(GL_FRAGMENT_PROGRAM_ARB); | ||||
#endif | #endif | ||||
} | } | ||||
device->m_Backbuffer = CFramebuffer::CreateBackbuffer(device.get()); | #if CONFIG2_GLES | ||||
device->m_UseFramebufferInvalidating = ogl_HaveExtension("GL_EXT_discard_framebuffer"); | |||||
#else | |||||
device->m_UseFramebufferInvalidating = !arb && ogl_HaveExtension("GL_ARB_invalidate_subdata"); | |||||
#endif | |||||
Capabilities& capabilities = device->m_Capabilities; | Capabilities& capabilities = device->m_Capabilities; | ||||
capabilities.ARBShaders = !ogl_HaveExtensions(0, "GL_ARB_vertex_program", "GL_ARB_fragment_program", nullptr); | capabilities.ARBShaders = !ogl_HaveExtensions(0, "GL_ARB_vertex_program", "GL_ARB_fragment_program", nullptr); | ||||
if (capabilities.ARBShaders) | if (capabilities.ARBShaders) | ||||
capabilities.ARBShadersShadow = ogl_HaveExtension("GL_ARB_fragment_program_shadow"); | capabilities.ARBShadersShadow = ogl_HaveExtension("GL_ARB_fragment_program_shadow"); | ||||
capabilities.computeShaders = ogl_HaveVersion(4, 3) || ogl_HaveExtension("GL_ARB_compute_shader"); | capabilities.computeShaders = ogl_HaveVersion(4, 3) || ogl_HaveExtension("GL_ARB_compute_shader"); | ||||
#if CONFIG2_GLES | #if CONFIG2_GLES | ||||
// Some GLES implementations have GL_EXT_texture_compression_dxt1 | // Some GLES implementations have GL_EXT_texture_compression_dxt1 | ||||
▲ Show 20 Lines • Show All 506 Lines • ▼ Show 20 Lines | std::unique_ptr<ITexture> CDevice::CreateTexture2D( | ||||
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) | const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) | ||||
{ | { | ||||
return CreateTexture(name, CTexture::Type::TEXTURE_2D, usage, | return CreateTexture(name, CTexture::Type::TEXTURE_2D, usage, | ||||
format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); | format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); | ||||
} | } | ||||
std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer( | std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer( | ||||
const char* name, ITexture* colorAttachment, | const char* name, ITexture* colorAttachment, | ||||
ITexture* depthStencilAttachment) | const AttachmentLoadOp colorAttachmentLoadOp, | ||||
{ | const AttachmentStoreOp colorAttachmentStoreOp, | ||||
return CreateFramebuffer(name, colorAttachment, depthStencilAttachment, CColor(0.0f, 0.0f, 0.0f, 0.0f)); | const CColor& clearColor, ITexture* depthStencilAttachment, | ||||
} | const AttachmentLoadOp depthStencilAttachmentLoadOp, | ||||
const AttachmentStoreOp depthStencilAttachmentStoreOp) | |||||
std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer( | |||||
const char* name, ITexture* colorAttachment, | |||||
ITexture* depthStencilAttachment, const CColor& clearColor) | |||||
{ | { | ||||
return CFramebuffer::Create( | return CFramebuffer::Create( | ||||
this, name, colorAttachment->As<CTexture>(), depthStencilAttachment->As<CTexture>(), clearColor); | this, name, colorAttachment->As<CTexture>(), | ||||
colorAttachmentLoadOp, colorAttachmentStoreOp, | |||||
clearColor, depthStencilAttachment->As<CTexture>(), | |||||
depthStencilAttachmentLoadOp, depthStencilAttachmentStoreOp); | |||||
} | } | ||||
std::unique_ptr<IBuffer> CDevice::CreateBuffer( | std::unique_ptr<IBuffer> CDevice::CreateBuffer( | ||||
const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) | const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) | ||||
{ | { | ||||
return CBuffer::Create(this, name, type, size, dynamic); | return CBuffer::Create(this, name, type, size, dynamic); | ||||
} | } | ||||
std::unique_ptr<IShaderProgram> CDevice::CreateShaderProgram( | std::unique_ptr<IShaderProgram> CDevice::CreateShaderProgram( | ||||
const CStr& name, const CShaderDefines& defines) | const CStr& name, const CShaderDefines& defines) | ||||
{ | { | ||||
return CShaderProgram::Create(this, name, defines); | return CShaderProgram::Create(this, name, defines); | ||||
} | } | ||||
bool CDevice::AcquireNextBackbuffer() | bool CDevice::AcquireNextBackbuffer() | ||||
{ | { | ||||
ENSURE(!m_BackbufferAcquired); | ENSURE(!m_BackbufferAcquired); | ||||
m_BackbufferAcquired = true; | m_BackbufferAcquired = true; | ||||
return true; | return true; | ||||
} | } | ||||
size_t CDevice::BackbufferKeyHash::operator()(const BackbufferKey& key) const | |||||
{ | |||||
size_t seed = 0; | |||||
hash_combine(seed, std::get<0>(key)); | |||||
hash_combine(seed, std::get<1>(key)); | |||||
hash_combine(seed, std::get<2>(key)); | |||||
hash_combine(seed, std::get<3>(key)); | |||||
return seed; | |||||
} | |||||
IFramebuffer* CDevice::GetCurrentBackbuffer( | |||||
const AttachmentLoadOp colorAttachmentLoadOp, | |||||
const AttachmentStoreOp colorAttachmentStoreOp, | |||||
const AttachmentLoadOp depthStencilAttachmentLoadOp, | |||||
const AttachmentStoreOp depthStencilAttachmentStoreOp) | |||||
{ | |||||
const BackbufferKey key{ | |||||
colorAttachmentLoadOp, colorAttachmentStoreOp, | |||||
depthStencilAttachmentLoadOp, depthStencilAttachmentStoreOp}; | |||||
auto it = m_Backbuffers.find(key); | |||||
if (it == m_Backbuffers.end()) | |||||
{ | |||||
it = m_Backbuffers.emplace(key, CFramebuffer::CreateBackbuffer( | |||||
this, colorAttachmentLoadOp, colorAttachmentStoreOp, | |||||
depthStencilAttachmentLoadOp, depthStencilAttachmentStoreOp)).first; | |||||
} | |||||
return it->second.get(); | |||||
} | |||||
void CDevice::Present() | void CDevice::Present() | ||||
{ | { | ||||
ENSURE(m_BackbufferAcquired); | ENSURE(m_BackbufferAcquired); | ||||
m_BackbufferAcquired = false; | m_BackbufferAcquired = false; | ||||
if (m_Window) | if (m_Window) | ||||
{ | { | ||||
PROFILE3("swap buffers"); | PROFILE3("swap buffers"); | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator