start splitting into functional blocks; add vk funcs

This commit is contained in:
Ivan Avdeev 2021-01-09 13:21:58 -08:00
parent ae6ec2e61d
commit 3e800fa989
11 changed files with 191 additions and 53 deletions

View File

@ -384,7 +384,11 @@ static ref_api_t gEngfuncs =
pfnDrawNormalTriangles,
pfnDrawTransparentTriangles,
&clgame.drawFuncs
&clgame.drawFuncs,
VK_GetInstanceExtensions,
VK_GetVkGetInstanceProcAddr,
VK_CreateSurface,
};
static void R_UnloadProgs( void )

View File

@ -124,6 +124,13 @@ void *SW_LockBuffer( void );
void SW_UnlockBuffer( void );
qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b );
//
// Vulkan
//
int VK_GetInstanceExtensions( const char ***pNames );
void *VK_GetVkGetInstanceProcAddr( void );
void *VK_CreateSurface( void *vkInstance );
//
// in_evdev.c

View File

@ -14,6 +14,7 @@ GNU General Public License for more details.
*/
#if !XASH_DEDICATED
#include <SDL.h>
#include <SDL_vulkan.h>
#include "common.h"
#include "client.h"
#include "mod_local.h"
@ -964,6 +965,43 @@ int GL_GetAttribute( int attr, int *val )
#define EGL_LIB NULL
#endif
int VK_GetInstanceExtensions( const char ***pNames )
{
int pCount = 0;
if (!SDL_Vulkan_GetInstanceExtensions(host.hWnd, (unsigned int*)&pCount, NULL))
{
Con_Reportf( S_ERROR "Couldn't get Vulkan extensions: %s\n", SDL_GetError());
return -1;
}
*pNames = Mem_Malloc(host.mempool, pCount * sizeof(const char*));
if (!SDL_Vulkan_GetInstanceExtensions(host.hWnd, (unsigned int*)&pCount, *pNames))
{
Con_Reportf( S_ERROR "Couldn't get Vulkan extensions: %s\n", SDL_GetError());
return -1;
}
return pCount;
}
void *VK_GetVkGetInstanceProcAddr( void )
{
return SDL_Vulkan_GetVkGetInstanceProcAddr();
}
void *VK_CreateSurface( void *vkInstance )
{
VkSurfaceKHR surface;
if (!SDL_Vulkan_CreateSurface(host.hWnd, vkInstance, &surface))
{
Con_Reportf( S_ERROR "Couldn't create Vulkan surface: %s\n", SDL_GetError());
return NULL;
}
return (void*)surface;
}
/*
==================
R_Init_Video

View File

@ -432,6 +432,11 @@ typedef struct ref_api_s
void (*pfnDrawNormalTriangles)( void );
void (*pfnDrawTransparentTriangles)( void );
render_interface_t *drawFuncs;
// Vulkan
int (*VK_GetInstanceExtensions)( const char ***pNames );
void *(*VK_GetVkGetInstanceProcAddr)( void );
void *(*VK_CreateSurface)( void *vkInstance );
} ref_api_t;
struct mip_s;

View File

@ -2,8 +2,17 @@
#include "const.h"
#include "cvardef.h"
#include "ref_api.h"
#include "crtlib.h"
#define ASSERT(x) if(!( x )) gEngine.Host_Error( "assert " #x " failed at %s:%i\n", __FILE__, __LINE__ )
#define Mem_Malloc( pool, size ) gEngine._Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
#define Mem_Calloc( pool, size ) gEngine._Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
#define Mem_Realloc( pool, ptr, size ) gEngine._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
#define Mem_Free( mem ) gEngine._Mem_Free( mem, __FILE__, __LINE__ )
#define Mem_AllocPool( name ) gEngine._Mem_AllocPool( name, __FILE__, __LINE__ )
#define Mem_FreePool( pool ) gEngine._Mem_FreePool( pool, __FILE__, __LINE__ )
#define Mem_EmptyPool( pool ) gEngine._Mem_EmptyPool( pool, __FILE__, __LINE__ )
extern ref_api_t gEngine;
extern ref_globals_t *gpGlobals;

49
ref_vk/vk_core.c Normal file
View File

@ -0,0 +1,49 @@
#include "vk_common.h"
#include "vk_textures.h"
#include "xash3d_types.h"
#include "cvardef.h"
#include "const.h" // required for ref_api.h
#include "ref_api.h"
#include "crtlib.h"
#include "com_strings.h"
qboolean R_VkInit( void )
{
if( !gEngine.R_Init_Video( REF_VULKAN )) // request Vulkan surface
{
gEngine.Con_Printf( S_ERROR "Cannot initialize Vulkan video" );
return false;
}
// TODO VkInstance create ...
{
const char **instance_exts = NULL;
const int num_instance_exts = gEngine.VK_GetInstanceExtensions(&instance_exts);
if (num_instance_exts < 0)
{
gEngine.Con_Printf( S_ERROR "Cannot get Vulkan instance extensions" );
return false;
}
gEngine.Con_Reportf("Vulkan instance extensions: %d\n", num_instance_exts);
for (int i = 0; i < num_instance_exts; ++i)
{
gEngine.Con_Reportf("\t%d: %s\n", i, instance_exts[i]);
}
Mem_Free(instance_exts);
}
initTextures();
return true;
}
void R_VkShutdown( void )
{
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
// TODO destroy everything
}

4
ref_vk/vk_core.h Normal file
View File

@ -0,0 +1,4 @@
#include "xash3d_types.h"
qboolean R_VkInit( void );
void R_VkShutdown( void );

58
ref_vk/vk_renderstate.c Normal file
View File

@ -0,0 +1,58 @@
#include "cvardef.h"
#include "const.h"
#include "ref_api.h"
#include "com_strings.h"
extern ref_api_t gEngine;
extern ref_globals_t *gpGlobals;
typedef struct { uint8_t r, g, b, a; } color_rgba8_t;
typedef struct render_state_s {
color_rgba8_t tri_color;
qboolean fog_allowed;
qboolean mode_2d;
int blending_mode; // kRenderNormal, ...
} render_state_t;
render_state_t render_state = {0};
static const char *renderModeName(int mode)
{
switch(mode)
{
case kRenderNormal: return "kRenderNormal";
case kRenderTransColor: return "kRenderTransColor";
case kRenderTransTexture: return "kRenderTransTexture";
case kRenderGlow: return "kRenderGlow";
case kRenderTransAlpha: return "kRenderTransAlpha";
case kRenderTransAdd: return "kRenderTransAdd";
default: return "INVALID";
}
}
void GL_SetRenderMode( int renderMode )
{
//gEngine.Con_Printf(S_WARN "VK FIXME: %s(%s(%d))\n", __FUNCTION__, renderModeName(renderMode), renderMode);
render_state.blending_mode = renderMode;
}
void TriColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a )
{
//gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d, %d, %d, %d)\n", __FUNCTION__, (int)r, (int)g, (int)b, (int)a);
render_state.tri_color = (color_rgba8_t){r, g, b, a};
}
void R_AllowFog( qboolean allow )
{
//gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d)\n", __FUNCTION__, allow);
render_state.fog_allowed = allow;
}
void R_Set2DMode( qboolean enable )
{
//gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d)\n", __FUNCTION__, enable);
render_state.mode_2d = enable;
}

8
ref_vk/vk_renderstate.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include "xash3d_types.h"
void GL_SetRenderMode( int renderMode );
void TriColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
void R_AllowFog( qboolean allow );
void R_Set2DMode( qboolean enable );

View File

@ -1,4 +1,7 @@
#include "vk_core.h"
#include "vk_common.h"
#include "vk_textures.h"
#include "vk_renderstate.h"
#include "xash3d_types.h"
#include "cvardef.h"
@ -8,39 +11,12 @@
#include "com_strings.h"
#include <memory.h>
#include <stdio.h>
ref_api_t gEngine = {0};
ref_globals_t *gpGlobals = NULL;
qboolean R_VkInit( void )
{
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
// TODO VkInstance create ...
if( !gEngine.R_Init_Video( REF_VULKAN )) // request Vulkan surface
{
// ...
return false;
}
initTextures();
return true;
}
void R_VkShutdown( void )
{
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
// TODO destroy everything
}
const char *R_GetConfigName( void )
{
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
return "vk";
}
@ -63,7 +39,7 @@ void GL_ClearExtensions( void )
void R_BeginFrame( qboolean clearScene )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d)\n", __FUNCTION__, clearScene);
}
void R_RenderScene( void )
{
@ -94,14 +70,6 @@ void R_ClearScreen( void )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void R_AllowFog( qboolean allow )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void GL_SetRenderMode( int renderMode )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
qboolean R_AddEntity( struct cl_entity_s *clent, int type )
{
@ -146,17 +114,14 @@ void R_SetupSky( const char *skyname )
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
}
void R_Set2DMode( qboolean enable )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
gEngine.Con_Printf(S_WARN "VK FIXME: %s(%f, %f, %f, %f, %f, %f, %f, %f, %d(%s))\n", __FUNCTION__,
x, y, w, h, s1, t1, s2, t2, texnum, findTexture(texnum)->name);
}
void R_DrawTileClear( int texnum, int x, int y, int w, int h )
{
@ -260,8 +225,8 @@ void Mod_LoadMapSprite( struct model_s *mod, const void *buffer, size_t size, qb
}
qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buffer )
{
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
return false;
gEngine.Con_Printf("VK FIXME: %s(%p(%s), %d, %p)\n", __FUNCTION__, mod, mod->name, create, buffer);
return true;//false;
}
void Mod_StudioLoadTextures( model_t *mod, void *data )
{
@ -304,7 +269,6 @@ static const char *getParmName(int parm)
case PARM_TEX_TEXNUM: return "PARM_TEX_TEXNUM";
case PARM_TEX_FLAGS: return "PARM_TEX_FLAGS";
case PARM_TEX_DEPTH: return "PARM_TEX_DEPTH";
//reserved
case PARM_TEX_GLFORMAT: return "PARM_TEX_GLFORMAT";
case PARM_TEX_ENCODE: return "PARM_TEX_ENCODE";
case PARM_TEX_MIPCOUNT: return "PARM_TEX_MIPCOUNT";
@ -515,10 +479,6 @@ void TriColor4f( float r, float g, float b, float a )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void TriColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void TriTexCoord2f( float u, float v )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);

View File

@ -234,8 +234,6 @@ int VK_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
rgbdata_t *pic;
uint picFlags = 0;
gEngine.Con_Printf("VK FIXME: %s(\"%s\", %p, %zu, %x)\n", __FUNCTION__, name, buf, size, flags);
if( !Common_CheckTexName( name ))
return 0;
@ -305,8 +303,6 @@ int VK_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags
{
vk_texture_t *tex;
gEngine.Con_Printf("VK FIXME: %s(\"%s\", %p, %x, %d)\n", __FUNCTION__, name, pic, flags, update);
if( !Common_CheckTexName( name ))
return 0;