Skip to content

Commit

Permalink
xrRender: Add various OpenGL implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Nov 23, 2015
1 parent e809f75 commit eca94e6
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 58 deletions.
28 changes: 20 additions & 8 deletions src/Layers/xrRender/DetailManager_VS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "xrEngine/Environment.h"
#endif
#include "Layers/xrRenderDX10/dx10BufferUtils.h"
#include "Layers/xrRenderGL/glBufferUtils.h"

const int quant = 16384;
const int c_hdr = 10;
Expand Down Expand Up @@ -60,7 +61,7 @@ void CDetailManager::hw_Load_Geom()
u32 vSize = sizeof(vertHW);
Msg("* [DETAILS] %d v(%d), %d p",dwVerts,vSize,dwIndices/3);

#if !defined(USE_DX10) && !defined(USE_DX11)
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
// Determine POOL & USAGE
u32 dwUsage = D3DUSAGE_WRITEONLY;

Expand All @@ -76,7 +77,7 @@ void CDetailManager::hw_Load_Geom()
// Fill VB
{
vertHW* pV;
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
vertHW* pVOriginal;
pVOriginal = xr_alloc<vertHW>(dwVerts);
pV = pVOriginal;
Expand All @@ -103,7 +104,10 @@ void CDetailManager::hw_Load_Geom()
}
}
}
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)
glBufferUtils::CreateVertexBuffer(&hw_VB, pVOriginal, dwVerts*vSize);
xr_free(pVOriginal);
#elif defined(USE_DX10) || defined(USE_DX11)
R_CHK(dx10BufferUtils::CreateVertexBuffer(&hw_VB, pVOriginal, dwVerts*vSize));
HW.stats_manager.increment_stats_vb ( hw_VB);
xr_free(pVOriginal);
Expand All @@ -115,7 +119,7 @@ void CDetailManager::hw_Load_Geom()
// Fill IB
{
u16* pI;
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
u16* pIOriginal;
pIOriginal = xr_alloc<u16>(dwIndices);
pI = pIOriginal;
Expand All @@ -133,7 +137,10 @@ void CDetailManager::hw_Load_Geom()
offset = u16(offset+u16(D.number_vertices));
}
}
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)
glBufferUtils::CreateIndexBuffer(&hw_IB, pIOriginal, dwIndices * 2);
xr_free(pIOriginal);
#elif defined(USE_DX10) || defined(USE_DX11)
R_CHK(dx10BufferUtils::CreateIndexBuffer(&hw_IB, pIOriginal, dwIndices*2));
HW.stats_manager.increment_stats_ib (hw_IB);
xr_free(pIOriginal);
Expand All @@ -150,13 +157,18 @@ void CDetailManager::hw_Unload()
{
// Destroy VS/VB/IB
hw_Geom.destroy ();
HW.stats_manager.decrement_stats_vb ( hw_VB);
HW.stats_manager.decrement_stats_ib ( hw_IB);
#ifdef USE_OGL
GLuint buffers[] = { hw_IB, hw_VB };
glDeleteBuffers(2, buffers);
#else
HW.stats_manager.decrement_stats_vb(hw_VB);
HW.stats_manager.decrement_stats_ib(hw_IB);
_RELEASE (hw_IB);
_RELEASE (hw_VB);
#endif // USE_OGL
}

#if !defined(USE_DX10) && !defined(USE_DX11)
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
void CDetailManager::hw_Load_Shaders()
{
// Create shader to access constant storage
Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRender/FSkinned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void CSkeletonX_PM::Load(const char* N, IReader *data, u32 dwFlags)
void* _verts_ = data->pointer ();
inherited1::Load (N,data,dwFlags|VLOAD_NOVERTICES);
GlobalEnv.Render->shader_option_skinning(-1);
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
_DuplicateIndices(N, data);
#endif // USE_DX10
vBase = 0;
Expand All @@ -388,14 +388,14 @@ void CSkeletonX_ST::Load(const char* N, IReader *data, u32 dwFlags)
void* _verts_ = data->pointer ();
inherited1::Load (N,data,dwFlags|VLOAD_NOVERTICES);
GlobalEnv.Render->shader_option_skinning(-1);
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
_DuplicateIndices(N, data);
#endif // USE_DX10
vBase = 0;
_Load_hw (*this,_verts_);
}

#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)

void CSkeletonX_ext::_Load_hw (Fvisual& V, void * _verts_)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/FVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Fvisual::Fvisual() : dxRender_Visual()

Fvisual::~Fvisual()
{
#ifndef USE_OGL
HW.stats_manager.decrement_stats_vb (p_rm_Vertices);
HW.stats_manager.decrement_stats_ib (p_rm_Indices);
#endif // !USE_OGL
xr_delete (m_fast);
}

Expand Down
24 changes: 16 additions & 8 deletions src/Layers/xrRender/ModelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,22 @@ void CModelPool::memory_stats ( u32& vb_mem_video, u32& vb_mem_system, u32& ib_

if( vis_ptr == NULL )
continue;
#if !defined(USE_DX10) && !defined(USE_DX11)
#if defined(USE_OGL)
GLint IB_size;
GLint VB_size;

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vis_ptr->m_fast->p_rm_Indices);
CHK_GL(glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &IB_size));

ib_mem_video += IB_size;
ib_mem_system += IB_size;

glBindBuffer(GL_ARRAY_BUFFER, vis_ptr->m_fast->p_rm_Vertices);
CHK_GL(glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &VB_size));

vb_mem_video += VB_size;
vb_mem_system += VB_size;
#elif !defined(USE_DX10) && !defined(USE_DX11)
D3DINDEXBUFFER_DESC IB_desc;
D3DVERTEXBUFFER_DESC VB_desc;

Expand Down Expand Up @@ -497,14 +512,7 @@ void CModelPool::memory_stats ( u32& vb_mem_video, u32& vb_mem_system, u32& ib_

vb_mem_video += IB_desc.ByteWidth;
vb_mem_system += IB_desc.ByteWidth;

#endif






}
}

Expand Down
52 changes: 49 additions & 3 deletions src/Layers/xrRender/R_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,42 @@
CBackend RCache;

// Create Quad-IB
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)

// Igor: is used to test bug with rain, particles corruption
void CBackend::RestoreQuadIBData()
{
}

void CBackend::CreateQuadIB()
{
const u32 dwTriCount = 4 * 1024;
const u32 dwIdxCount = dwTriCount * 2 * 3;
u16 IndexBuffer[dwIdxCount];
u16 *Indices = IndexBuffer;
GLenum dwUsage = GL_STATIC_DRAW;

int Cnt = 0;
int ICnt = 0;
for (int i = 0; i<dwTriCount; i++)
{
Indices[ICnt++] = u16(Cnt + 0);
Indices[ICnt++] = u16(Cnt + 1);
Indices[ICnt++] = u16(Cnt + 2);

Indices[ICnt++] = u16(Cnt + 3);
Indices[ICnt++] = u16(Cnt + 2);
Indices[ICnt++] = u16(Cnt + 1);

Cnt += 4;
}

glGenBuffers(1, &QuadIB);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIB);
CHK_GL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, dwIdxCount * 2, Indices, dwUsage));
}

#elif defined(USE_DX10) || defined(USE_DX11)

// Igor: is used to test bug with rain, particles corruption
void CBackend::RestoreQuadIBData()
Expand Down Expand Up @@ -126,6 +161,10 @@ void CBackend::OnDeviceCreate ()
#if defined(USE_DX10) || defined(USE_DX11)
//CreateConstantBuffers();
#endif // USE_DX10
#ifdef USE_OGL
// Create the program pipeline used for rendering with shaders
glGenProgramPipelines(1, &pp);
#endif // USE_OGL

CreateQuadIB ();

Expand All @@ -144,12 +183,19 @@ void CBackend::OnDeviceDestroy()
Vertex.Destroy ();

// Quad
HW.stats_manager.decrement_stats_ib (QuadIB);
_RELEASE (QuadIB);
#ifdef USE_OGL
glDeleteBuffers(1, &QuadIB);
#else
HW.stats_manager.decrement_stats_ib(QuadIB);
_RELEASE(QuadIB);
#endif

#if defined(USE_DX10) || defined(USE_DX11)
//DestroyConstantBuffers();
#endif // USE_DX10
#ifdef USE_OGL
glDeleteProgramPipelines(1, &pp);
#endif // USE_OGL
}

#if defined(USE_DX10) || defined(USE_DX11)
Expand Down
8 changes: 5 additions & 3 deletions src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ class ECORE_API CBackend
#if defined(USE_DX10) || defined(USE_DX11)
IC void get_ConstantDirect (shared_str& n, u32 DataSize, void** pVData, void** pGData, void** pPData);
#else //USE_DX10
#ifndef USE_OGL
IC R_constant_array& get_ConstantCache_Vertex () { return constants.a_vertex; }
IC R_constant_array& get_ConstantCache_Pixel () { return constants.a_pixel; }
#endif // USE_OGL
#endif // USE_DX10

// API
Expand Down Expand Up @@ -364,7 +366,7 @@ class ECORE_API CBackend
ICF void set_ca (R_constant* C, u32 e, const Fmatrix& A) { if (C) constants.seta(C,e,A); }
ICF void set_ca (R_constant* C, u32 e, const Fvector4& A) { if (C) constants.seta(C,e,A); }
ICF void set_ca (R_constant* C, u32 e, float x, float y, float z, float w) { if (C) constants.seta(C,e,x,y,z,w); }
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
ICF void set_c (R_constant* C, float A) { if (C) constants.set(C,A); }
ICF void set_c (R_constant* C, int A) { if (C) constants.set(C,A); }
#endif // USE_DX10
Expand All @@ -377,7 +379,7 @@ class ECORE_API CBackend
ICF void set_ca (LPCSTR n, u32 e, const Fmatrix& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
ICF void set_ca (LPCSTR n, u32 e, const Fvector4& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
ICF void set_ca (LPCSTR n, u32 e, float x, float y, float z, float w) { if(ctable) set_ca (&*ctable->get(n),e,x,y,z,w);}
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
ICF void set_c (LPCSTR n, float A) { if(ctable) set_c (&*ctable->get(n),A); }
ICF void set_c (LPCSTR n, int A) { if(ctable) set_c (&*ctable->get(n),A); }
#endif // USE_DX10
Expand All @@ -389,7 +391,7 @@ class ECORE_API CBackend
ICF void set_ca (shared_str& n, u32 e, const Fmatrix& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
ICF void set_ca (shared_str& n, u32 e, const Fvector4& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
ICF void set_ca (shared_str& n, u32 e, float x, float y, float z, float w) { if(ctable) set_ca (&*ctable->get(n),e,x,y,z,w);}
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
ICF void set_c (shared_str& n, float A) { if(ctable) set_c (&*ctable->get(n),A); }
ICF void set_c (shared_str& n, int A) { if(ctable) set_c (&*ctable->get(n),A); }
#endif // USE_DX10
Expand Down
8 changes: 4 additions & 4 deletions src/Layers/xrRender/R_Backend_DBG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void CBackend::dbg_DIP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV

void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pIdx, int pcnt)
{
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
#else // USE_DX10
Expand All @@ -31,7 +31,7 @@ void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pI
}
void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int pcnt)
{
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
#else // USE_DX10
Expand Down Expand Up @@ -127,7 +127,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
0.3536f,-0.1464f,-0.9239f, 0.3827f,0.0000f,-0.9239f, 0.3536f,0.1464f,-0.9239f,
0.2706f,0.2706f,-0.9239f, 0.1464f,0.3536f,-0.9239f, 0.0000f,0.0000f,-1.0000f
};
#if !defined(USE_DX10) && !defined(USE_DX11)
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
u16 gFaces[224*3] =
{
0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,7, 0,7,8, 0,8,9, 0,9,10,
Expand Down Expand Up @@ -167,7 +167,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)

set_xform_world (T);

#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
//dbg_Draw(D3DPT_TRIANGLELIST,verts,vcnt,gFaces,224);
Expand Down
20 changes: 15 additions & 5 deletions src/Layers/xrRender/R_Backend_Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void CBackend::OnFrameEnd ()
if (!g_dedicated_server)
#endif
{
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)
Invalidate ();
#elif defined(USE_DX10) || defined(USE_DX11)
HW.pContext->ClearState();
Invalidate ();
#else // USE_DX10
Expand Down Expand Up @@ -146,7 +148,7 @@ DX10_ONLY(gs = NULL);

void CBackend::set_ClipPlanes (u32 _enable, Fplane* _planes /*=NULL */, u32 count/* =0*/)
{
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
// TODO: DX10: Implement in the corresponding vertex shaders
// Use this to set up location, were shader setup code will get data
//VERIFY(!"CBackend::set_ClipPlanes not implemented!");
Expand Down Expand Up @@ -184,7 +186,7 @@ void CBackend::set_ClipPlanes (u32 _enable, Fmatrix* _xform /*=NULL */, u32 fma
{
if (0==HW.Caps.geometry.dwClipPlanes) return;
if (!_enable) {
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
// TODO: DX10: Implement in the corresponding vertex shaders
// Use this to set up location, were shader setup code will get data
//VERIFY(!"CBackend::set_ClipPlanes not implemented!");
Expand Down Expand Up @@ -371,7 +373,11 @@ void CBackend::set_Textures (STextureList* _T)
continue;

textures_ps[_last_ps] = 0;
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)
CHK_GL(glActiveTexture(GL_TEXTURE0 + _last_ps));
CHK_GL(glBindTexture(GL_TEXTURE_2D, 0));
CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
#elif defined(USE_DX10) || defined(USE_DX11)
// TODO: DX10: Optimise: set all resources at once
ID3DShaderResourceView *pRes = 0;
//HW.pDevice->PSSetShaderResources(_last_ps, 1, &pRes);
Expand All @@ -387,7 +393,11 @@ void CBackend::set_Textures (STextureList* _T)
continue;

textures_vs[_last_vs] = 0;
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_OGL)
CHK_GL(glActiveTexture(GL_TEXTURE0 + CTexture::rstVertex + _last_vs));
CHK_GL(glBindTexture(GL_TEXTURE_2D, 0));
CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
#elif defined(USE_DX10) || defined(USE_DX11)
// TODO: DX10: Optimise: set all resources at once
ID3DShaderResourceView *pRes = 0;
//HW.pDevice->VSSetShaderResources(_last_vs, 1, &pRes);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void CResourceManager::_DumpMemoryUsage ()
void CResourceManager::Evict()
{
// TODO: DX10: check if we really need this method
#if !defined(USE_DX10) && !defined(USE_DX11)
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
CHK_DX (HW.pDevice->EvictManagedResources());
#endif // USE_DX10
}
Expand Down
Loading

0 comments on commit eca94e6

Please sign in to comment.