mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-04-24 02:32:18 +00:00
Moved generic ImGui drawing to idGuiModel::EmitImGui
This commit is contained in:
parent
f9a1c5ff36
commit
50eb5b4537
7 changed files with 110 additions and 77 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2013-2020 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -30,6 +31,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "precompiled.h"
|
||||
|
||||
#include "RenderCommon.h"
|
||||
#include "../../libs/imgui/imgui.h"
|
||||
|
||||
const float idGuiModel::STEREO_DEPTH_NEAR = 0.0f;
|
||||
const float idGuiModel::STEREO_DEPTH_MID = 0.5f;
|
||||
|
@ -331,6 +333,76 @@ void idGuiModel::EmitFullScreen()
|
|||
R_AddDrawViewCmd( viewDef, true );
|
||||
}
|
||||
|
||||
// RB begin
|
||||
/*
|
||||
================
|
||||
idGuiModel::ImGui_RenderDrawLists
|
||||
================
|
||||
*/
|
||||
void idGuiModel::EmitImGui( ImDrawData* drawData )
|
||||
{
|
||||
// NOTE: this implementation does not support scissor clipping for the indivudal draw commands
|
||||
// but it is sufficient for things like com_showFPS
|
||||
|
||||
const float sysWidth = renderSystem->GetWidth();
|
||||
const float sysHeight = renderSystem->GetHeight();
|
||||
|
||||
idVec2 scaleToVirtual( ( float )renderSystem->GetVirtualWidth() / sysWidth, ( float )renderSystem->GetVirtualHeight() / sysHeight );
|
||||
|
||||
for( int a = 0; a < drawData->CmdListsCount; a++ )
|
||||
{
|
||||
const ImDrawList* cmd_list = drawData->CmdLists[a];
|
||||
const ImDrawIdx* indexBufferOffset = &cmd_list->IdxBuffer.front();
|
||||
|
||||
int numVerts = cmd_list->VtxBuffer.size();
|
||||
|
||||
for( int b = 0; b < cmd_list->CmdBuffer.size(); b++ )
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[b];
|
||||
|
||||
int numIndexes = pcmd->ElemCount;
|
||||
|
||||
// TODO support more than just the imGui Font texture
|
||||
// but we can live with the current solution because ImGui is only meant to draw a few bars and timers
|
||||
|
||||
//glBindTexture( GL_TEXTURE_2D, ( GLuint )( intptr_t )pcmd->TextureId )
|
||||
|
||||
//const idMaterial* material = declManager->FindMaterial( texture name of pcmd->TextureId );
|
||||
|
||||
idDrawVert* verts = renderSystem->AllocTris( numVerts, indexBufferOffset, numIndexes, tr.imgGuiMaterial, STEREO_DEPTH_TYPE_NONE );
|
||||
if( verts == NULL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pcmd->UserCallback )
|
||||
{
|
||||
pcmd->UserCallback( cmd_list, pcmd );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int j = 0; j < numVerts; j++ )
|
||||
{
|
||||
const ImDrawVert* imVert = &cmd_list->VtxBuffer[j];
|
||||
|
||||
ALIGNTYPE16 idDrawVert tempVert;
|
||||
|
||||
//tempVert.xyz = idVec3( imVert->pos.x, imVert->pos.y, 0.0f );
|
||||
tempVert.xyz.ToVec2() = idVec2( imVert->pos.x, imVert->pos.y ).Scale( scaleToVirtual );
|
||||
tempVert.xyz.z = 0.0f;
|
||||
tempVert.SetTexCoord( imVert->uv.x, imVert->uv.y );
|
||||
tempVert.SetColor( imVert->col );
|
||||
|
||||
WriteDrawVerts16( &verts[j], &tempVert, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
indexBufferOffset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
// RB end
|
||||
|
||||
/*
|
||||
=============
|
||||
AdvanceSurf
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2013-2020 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -37,6 +38,11 @@ struct guiModelSurface_t
|
|||
|
||||
class idRenderMatrix;
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
struct ImDrawData;
|
||||
}
|
||||
|
||||
class idGuiModel
|
||||
{
|
||||
public:
|
||||
|
@ -53,6 +59,9 @@ public:
|
|||
void EmitToCurrentView( float modelMatrix[16], bool depthHack );
|
||||
void EmitFullScreen();
|
||||
|
||||
// RB
|
||||
void EmitImGui( ImDrawData* drawData );
|
||||
|
||||
// the returned pointer will be in write-combined memory, so only make contiguous
|
||||
// 32 bit writes and never read from it.
|
||||
idDrawVert* AllocTris( int numVerts, const triIndex_t* indexes, int numIndexes, const idMaterial* material,
|
||||
|
|
|
@ -2185,16 +2185,19 @@ IMGUI RENDERING
|
|||
|
||||
==============================================================================================
|
||||
*/
|
||||
#include "../../libs/imgui/imgui.h"
|
||||
#if !IMGUI_BFGUI
|
||||
|
||||
int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||
int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||
int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
|
||||
unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0;
|
||||
#include "../../libs/imgui/imgui.h"
|
||||
|
||||
int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||
int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||
int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
|
||||
unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0;
|
||||
#endif
|
||||
|
||||
void idRenderBackend::ImGui_Init()
|
||||
{
|
||||
#if 1
|
||||
#if !IMGUI_BFGUI
|
||||
const GLchar* vertex_shader =
|
||||
"#version 330\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
|
@ -2260,6 +2263,7 @@ void idRenderBackend::ImGui_Init()
|
|||
|
||||
void idRenderBackend::ImGui_Shutdown()
|
||||
{
|
||||
#if !IMGUI_BFGUI
|
||||
if( g_VaoHandle )
|
||||
{
|
||||
glDeleteVertexArrays( 1, &g_VaoHandle );
|
||||
|
@ -2286,13 +2290,19 @@ void idRenderBackend::ImGui_Shutdown()
|
|||
g_ShaderHandle = 0;
|
||||
|
||||
//ImGui::GetIO().Fonts->TexID = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
|
||||
void idRenderBackend::ImGui_RenderDrawLists( ImDrawData* draw_data )
|
||||
{
|
||||
#if IMGUI_BFGUI
|
||||
|
||||
tr.guiModel->EmitImGui( draw_data );
|
||||
|
||||
#else
|
||||
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
||||
GLint last_program, last_texture, polygon_mode[2];
|
||||
glGetIntegerv( GL_CURRENT_PROGRAM, &last_program );
|
||||
|
@ -2387,4 +2397,6 @@ void idRenderBackend::ImGui_RenderDrawLists( ImDrawData* draw_data )
|
|||
glBindTexture( GL_TEXTURE_2D, last_texture );
|
||||
|
||||
renderProgManager.Unbind();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -39,7 +39,9 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "Font.h"
|
||||
#include "Framebuffer.h"
|
||||
|
||||
|
||||
// RB: define this to use the id Tech 4.5 UI interface for ImGui instead of OpenGL or Vulkan
|
||||
// this allows to have the com_showFPS stats in screenshots
|
||||
#define IMGUI_BFGUI 1
|
||||
|
||||
// maximum texture units
|
||||
const int MAX_PROG_TEXTURE_PARMS = 16;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2013-2016 Robert Beckebans
|
||||
Copyright (C) 2013-2020 Robert Beckebans
|
||||
Copyright (C) 2014-2016 Kot in Action Creative Artel
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
@ -657,8 +657,7 @@ void idRenderSystemLocal::SwapCommandBuffers_FinishRendering(
|
|||
// After coming back from an autoswap, we won't have anything to render
|
||||
//if( frameData && frameData->cmdHead->next != NULL )
|
||||
{
|
||||
#if !defined( USE_VULKAN )
|
||||
// RB: FIXME move this elsewhere
|
||||
#if !defined( USE_VULKAN ) && !defined( IMGUI_BFGUI )
|
||||
ImGuiHook::Render();
|
||||
#endif
|
||||
|
||||
|
@ -804,7 +803,7 @@ const emptyCommand_t* idRenderSystemLocal::SwapCommandBuffers_FinishCommandBuffe
|
|||
|
||||
// RB: general GUI system path to treat ImGui surfaces in the renderer frontend like SWF
|
||||
// this calls io.RenderDrawListsFn
|
||||
#if defined( USE_VULKAN )
|
||||
#if defined( USE_VULKAN ) || IMGUI_BFGUI
|
||||
ImGuiHook::Render();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2812,8 +2812,6 @@ IMGUI RENDERING
|
|||
|
||||
==============================================================================================
|
||||
*/
|
||||
#include "../../libs/imgui/imgui.h"
|
||||
|
||||
void idRenderBackend::ImGui_Init()
|
||||
{
|
||||
// not needed
|
||||
|
@ -2825,68 +2823,7 @@ void idRenderBackend::ImGui_Shutdown()
|
|||
}
|
||||
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
|
||||
// TODO move this out of the renderer backend for Vulkan because it is called in the renderer frontend
|
||||
// NOTE: this implementation does not support scissor clipping for the indivudal draw commands
|
||||
// but it is sufficient for things like com_showFPS
|
||||
void idRenderBackend::ImGui_RenderDrawLists( ImDrawData* draw_data )
|
||||
{
|
||||
|
||||
const float sysWidth = renderSystem->GetWidth();
|
||||
const float sysHeight = renderSystem->GetHeight();
|
||||
|
||||
idVec2 scaleToVirtual( ( float )renderSystem->GetVirtualWidth() / sysWidth, ( float )renderSystem->GetVirtualHeight() / sysHeight );
|
||||
|
||||
for( int a = 0; a < draw_data->CmdListsCount; a++ )
|
||||
{
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[a];
|
||||
const ImDrawIdx* indexBufferOffset = &cmd_list->IdxBuffer.front();
|
||||
|
||||
int numVerts = cmd_list->VtxBuffer.size();
|
||||
|
||||
for( int b = 0; b < cmd_list->CmdBuffer.size(); b++ )
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[b];
|
||||
|
||||
int numIndexes = pcmd->ElemCount;
|
||||
|
||||
|
||||
// TODO support more than just the imGui Font texture
|
||||
// but we can live with the current solution because ImGui is only meant to draw a few bars and timers
|
||||
|
||||
//glBindTexture( GL_TEXTURE_2D, ( GLuint )( intptr_t )pcmd->TextureId )
|
||||
|
||||
//const idMaterial* material = declManager->FindMaterial( texture name of pcmd->TextureId );
|
||||
|
||||
idDrawVert* verts = renderSystem->AllocTris( numVerts, indexBufferOffset, numIndexes, tr.imgGuiMaterial, STEREO_DEPTH_TYPE_NONE );
|
||||
if( verts == NULL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pcmd->UserCallback )
|
||||
{
|
||||
pcmd->UserCallback( cmd_list, pcmd );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int j = 0; j < numVerts; j++ )
|
||||
{
|
||||
const ImDrawVert* imVert = &cmd_list->VtxBuffer[j];
|
||||
|
||||
ALIGNTYPE16 idDrawVert tempVert;
|
||||
|
||||
//tempVert.xyz = idVec3( imVert->pos.x, imVert->pos.y, 0.0f );
|
||||
tempVert.xyz.ToVec2() = idVec2( imVert->pos.x, imVert->pos.y ).Scale( scaleToVirtual );
|
||||
tempVert.xyz.z = 0.0f;
|
||||
tempVert.SetTexCoord( imVert->uv.x, imVert->uv.y );
|
||||
tempVert.SetColor( imVert->col );
|
||||
|
||||
WriteDrawVerts16( &verts[j], &tempVert, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
indexBufferOffset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
tr.guiModel->EmitImGui( draw_data );
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "precompiled.h"
|
||||
|
||||
#include "DeviceContext.h"
|
||||
|
||||
#include "../../libs/imgui/imgui.h"
|
||||
#include "../renderer/GuiModel.h"
|
||||
|
||||
extern idCVar in_useJoystick;
|
||||
|
|
Loading…
Reference in a new issue