mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 21:28:32 +09:00
- Add CreateTestTexture(): creates an RGBA8 texture, SRV and default sampler, and attaches the sampler to the SRV. - State PSOs now bind a static pixel-shader variable 'g_Texture' to the test texture and commit shader resources before drawing. - Add DrawsTexturedFromMobileGLState test using a real GL program with sampler2D and interleaved position+UV attributes. - All 4 Diligent local tests pass on Turnip Adreno 750.
86 lines
3.6 KiB
C++
86 lines
3.6 KiB
C++
// MobileGL - MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h
|
|
// Copyright (c) 2026 MobileGL-Dev
|
|
// Licensed under the GNU Lesser General Public License v3.0:
|
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <Includes.h>
|
|
|
|
// X11 (pulled in by Includes.h through Vulkan-Headers) defines True/False as
|
|
// macros, which collide with Diligent's Bool constants in BasicTypes.h.
|
|
#if defined(True)
|
|
#undef True
|
|
#endif
|
|
#if defined(False)
|
|
#undef False
|
|
#endif
|
|
|
|
#include <RefCntAutoPtr.hpp>
|
|
|
|
namespace Diligent {
|
|
struct IRenderDevice;
|
|
struct IDeviceContext;
|
|
struct ITexture;
|
|
struct ITextureView;
|
|
struct IPipelineState;
|
|
struct IBuffer;
|
|
struct ISampler;
|
|
struct IShaderResourceBinding;
|
|
}
|
|
|
|
namespace MobileGL::MG_Backend::DiligentBackend {
|
|
// Minimal real Diligent renderer used to prove the GL 3.2 basic path:
|
|
// clear an offscreen color target, draw a hardcoded triangle, and read
|
|
// pixels back. This is the first concrete rendering layer on top of the
|
|
// Diligent device; it will be expanded into the full MobileGL backend.
|
|
class DiligentRenderer {
|
|
public:
|
|
DiligentRenderer(::Diligent::IRenderDevice* device, ::Diligent::IDeviceContext* context);
|
|
~DiligentRenderer();
|
|
|
|
Bool Initialize(Uint32 width, Uint32 height);
|
|
void Clear(Float r, Float g, Float b, Float a);
|
|
void ClearDepth(Float depth);
|
|
void DrawTriangle();
|
|
void DrawVertices(const Float* vertices, Uint32 vertexCount);
|
|
// Creates a simple 2D RGBA8 texture from CPU data and makes it available
|
|
// to state PSOs under the shader variable name "g_Texture".
|
|
Bool CreateTestTexture(const void* data, Uint32 width, Uint32 height);
|
|
// Draws using the live MG_State GL context: current program, VAO and
|
|
// bound buffers. This is the front-end emulation entry point.
|
|
void DrawFromState(GLenum mode, GLint first, GLsizei count, GLenum type, const void* indices);
|
|
void ReadPixels(Uint32 x, Uint32 y, Uint32 width, Uint32 height, void* pixels);
|
|
void Present();
|
|
|
|
::Diligent::IRenderDevice* GetDevice() const { return m_pDevice; }
|
|
::Diligent::IDeviceContext* GetContext() const { return m_pContext; }
|
|
|
|
private:
|
|
Bool CreateOffscreenTargets();
|
|
Bool CreatePipeline();
|
|
Bool CreateVertexBuffer();
|
|
Bool CreatePipelineFromState(GLenum mode);
|
|
Bool UploadVertexDataFromState(GLenum mode, GLint first, GLsizei count, GLenum type, const void* indices);
|
|
|
|
::Diligent::IRenderDevice* m_pDevice = nullptr;
|
|
::Diligent::IDeviceContext* m_pContext = nullptr;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITexture> m_pColorTarget;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITextureView> m_pColorRTV;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITexture> m_pDepthTarget;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITextureView> m_pDepthDSV;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITexture> m_pTestTexture;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ITextureView> m_pTestSRV;
|
|
::Diligent::RefCntAutoPtr<::Diligent::ISampler> m_pTestSampler;
|
|
::Diligent::RefCntAutoPtr<::Diligent::IShaderResourceBinding> m_pStateSRB;
|
|
::Diligent::RefCntAutoPtr<::Diligent::IPipelineState> m_pPSO;
|
|
::Diligent::RefCntAutoPtr<::Diligent::IBuffer> m_pVertexBuffer;
|
|
Uint32 m_width = 256;
|
|
Uint32 m_height = 256;
|
|
Uint32 m_lastDrawVertexCount = 0;
|
|
Bool m_initialized = false;
|
|
};
|
|
} // namespace MobileGL::MG_Backend::DiligentBackend
|