mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Feat] (Diligent): wire viewport/scissor state into state draws
DrawFromState now uses MG_State viewport (with full-target fallback when the viewport is uninitialized) and applies the scissor test rect when enabled. The state-driven test sets an explicit glViewport and passes again.
This commit is contained in:
@@ -396,9 +396,32 @@ void main()
|
||||
::Diligent::ITextureView* rtvs[] = {m_pColorRTV};
|
||||
m_pContext->SetRenderTargets(1, rtvs, nullptr, ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
|
||||
|
||||
::Diligent::Viewport viewport{0, 0, static_cast<Float>(m_width), static_cast<Float>(m_height), 0.0f, 1.0f};
|
||||
auto glViewport = MG_State::pGLContext->GetViewport();
|
||||
if (glViewport.z() <= 0 || glViewport.w() <= 0) {
|
||||
glViewport = IntVec4(0, 0, static_cast<Int32>(m_width), static_cast<Int32>(m_height));
|
||||
}
|
||||
::Diligent::Viewport viewport{
|
||||
static_cast<Float>(glViewport.x()),
|
||||
static_cast<Float>(glViewport.y()),
|
||||
static_cast<Float>(glViewport.z()),
|
||||
static_cast<Float>(glViewport.w()),
|
||||
0.0f, 1.0f};
|
||||
m_pContext->SetViewports(1, &viewport, m_width, m_height);
|
||||
|
||||
if (MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::ScissorTest)) {
|
||||
const auto scissor = MG_State::pGLContext->GetScissorBox();
|
||||
::Diligent::Rect rect{
|
||||
scissor.x(),
|
||||
scissor.y(),
|
||||
scissor.x() + scissor.z(),
|
||||
scissor.y() + scissor.w()};
|
||||
m_pContext->SetScissorRects(1, &rect, m_width, m_height);
|
||||
} else {
|
||||
::Diligent::Rect rect{0, 0, static_cast<::Diligent::Int32>(m_width),
|
||||
static_cast<::Diligent::Int32>(m_height)};
|
||||
m_pContext->SetScissorRects(1, &rect, m_width, m_height);
|
||||
}
|
||||
|
||||
::Diligent::IBuffer* pVBs[] = {m_pVertexBuffer};
|
||||
m_pContext->SetVertexBuffers(0, 1, pVBs, nullptr,
|
||||
::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Impl/GLImpl/Program/GL_Program.h>
|
||||
#include <MG_Impl/GLImpl/RenderState/GL_RenderState.h>
|
||||
#include <MG_Impl/GLImpl/VertexArray/GL_VertexArray.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#include <Init.h>
|
||||
@@ -94,6 +95,7 @@ void main() { Color = vec4(1.0, 0.0, 0.0, 1.0); }
|
||||
AttachShader(program, fs);
|
||||
LinkProgram(program);
|
||||
UseProgram(program);
|
||||
Viewport(0, 0, 256, 256);
|
||||
|
||||
// Upload a triangle into a real GL buffer and describe it through a VAO.
|
||||
const float vertices[] = {
|
||||
|
||||
Reference in New Issue
Block a user