Skip to content
Permalink
Browse files

Fix the static build of the vulkan renderer for linux.

TODO: Fix the dynamic library builds of the vulkan renderer on all platforms supported by Tremulous.
TODO: Fix the transition too/from full screen to be more smooth.
TODO: Get at least all of the features in renderer2 to work in the vulkan renderer.
  • Loading branch information...
dGr8LookinSparky committed Mar 29, 2019
1 parent 0236133 commit d361a9d1a74e7bfb36486b189a348c40357a589e
@@ -238,8 +238,9 @@ ifndef USE_LOCAL_HEADERS
USE_LOCAL_HEADERS=$(USE_INTERNAL_LIBS)
endif

## TODO: Fix the dynamic library builds of the vulkan renderer
ifndef USE_RENDERER_DLOPEN
USE_RENDERER_DLOPEN=1
USE_RENDERER_DLOPEN=0
endif

ifndef USE_YACC
@@ -1885,8 +1885,11 @@ void Hunk_FreeTempMemory( void *buf )
}

hunkHeader_t* hdr = ( (hunkHeader_t *)buf ) - 1;
if ( hdr->magic != HUNK_MAGIC )
Com_Error(ERR_FATAL, "Hunk_FreeTempMemory: bad magic");
if( hdr->magic == HUNK_FREE_MAGIC ) {
Com_Error(ERR_FATAL, "Hunk_FreeTempMemory: hunk was previously freed");
} else if ( hdr->magic != HUNK_MAGIC ) {
Com_Error(ERR_FATAL, "Hunk_FreeTempMemory: bad magic");
}

hdr->magic = HUNK_FREE_MAGIC;

@@ -34,11 +34,12 @@ asked for again.
*/
qhandle_t RE_RegisterModel( const char *name )
{
ri.Printf( PRINT_ALL, "RegisterModel: %s. \n", name);

bool orgNameFailed = false;
bool orgNameFailed = false;
model_t* mod;
int orgLoader = -1;

ri.Printf( PRINT_ALL, "RegisterModel: %s. \n", name);

if ( !name || !name[0] ) {
ri.Printf( PRINT_WARNING, "RE_RegisterModel: NULL name\n" );
return 0;
@@ -54,13 +55,11 @@ qhandle_t RE_RegisterModel( const char *name )
//
qhandle_t hModel;

for ( hModel = 1; hModel < tr.numModels; hModel++ )
{
if ( 0 == strcmp( tr.models[hModel]->name, name ) )
{
if( tr.models[hModel]->type == MOD_BAD )
{
ri.Printf( PRINT_WARNING, "tr.models[%d]->type = MOD_BAD \n", hModel);
for ( hModel = 1; hModel < tr.numModels; hModel++ ) {
mod = tr.models[hModel];
if ( !strcmp( mod->name, name ) ) {
if( mod->type == MOD_BAD ) {
ri.Printf( PRINT_WARNING, "tr.models[%d]->type = MOD_BAD \n", hModel);
return 0;
}
return hModel;
@@ -69,8 +68,6 @@ qhandle_t RE_RegisterModel( const char *name )


// allocate a new model_t
model_t* mod;

ri.Printf( PRINT_ALL, "Allocate Memory for %s. \n", name);
if ( ( mod = R_AllocModel() ) == NULL ) {
ri.Printf( PRINT_WARNING, "RE_RegisterModel: R_AllocModel() failed for '%s'\n", name);
@@ -401,13 +401,13 @@ static void BuildSingleLargeBuffer(char* buffers[], const int nShaderFiles, cons

textEnd += strlen(buffers[n]) + 1;

ri.FS_FreeFile( buffers[n] );
ri.FS_FreeFile( (void *)buffers[n] );
}
}
}


static void Shader_DoSimpleCheck(char* name, char* p)
static bool Shader_DoSimpleCheck(char* name, char* p)
{
char* pBuf = p;

@@ -434,20 +434,19 @@ static void Shader_DoSimpleCheck(char* name, char* p)
}
ri.Printf(PRINT_WARNING, ".\n");
ri.FS_FreeFile(pBuf);
pBuf = NULL;
break;
return false;
}

if(!SkipBracedSection(&p, 1))
{
ri.Printf(PRINT_WARNING, "WARNING: Ignoring shader file %s. Shader \"%s\" on line %d missing closing brace.\n",
name, shaderName, shaderLine);
ri.FS_FreeFile(pBuf);
pBuf = NULL;
break;
return false;
}
}

return true;
}


@@ -520,7 +519,7 @@ void ScanAndLoadShaderFiles( void )
int numShaderFiles = 0, i;

for(i = 0; i < MAX_SHADER_FILES; i++) {
*(buffers.c[i]) = 0;
buffers.c[i] = 0;
}

// scan for shader files
@@ -552,7 +551,9 @@ void ScanAndLoadShaderFiles( void )

// Do a simple check on the shader structure in that file
// to make sure one bad shader file cannot fuck up all other shaders.
Shader_DoSimpleCheck(filename, buffers.c[i]);
if(!Shader_DoSimpleCheck(filename, buffers.c[i])) {
buffers.c[i] = NULL;
}

if (buffers.c[i])
sum += summand;
@@ -1353,9 +1353,6 @@ static void R_LoadSubmodels( lump_t *l )
model->bmodel = out;
Com_sprintf( model->name, sizeof( model->name ), "*%d", i );

if ( ++tr.numModels == MAX_MOD_KNOWN ) {
ri.Printf(PRINT_WARNING, "R_AllocModel: MAX_MOD_KNOWN.\n");
}
ri.Printf( PRINT_ALL, "Allocate Memory for %s model. \n", model->name);

for (j=0 ; j<3 ; j++) {
@@ -123,12 +123,102 @@ void RE_SetColor( const float *rgba )
}




/*
=============
R_ClipRegion
=============
*/
static bool R_ClipRegion ( float *x, float *y, float *w, float *h,
float *s1, float *t1, float *s2, float *t2 ) {
float left, top, right, bottom;
float _s1, _t1, _s2, _t2;
float clipLeft, clipTop, clipRight, clipBottom;

if (tr.clipRegion[2] <= tr.clipRegion[0] ||
tr.clipRegion[3] <= tr.clipRegion[1] ) {
return false;
}

left = *x;
top = *y;
right = *x + *w;
bottom = *y + *h;

_s1 = *s1;
_t1 = *t1;
_s2 = *s2;
_t2 = *t2;

clipLeft = tr.clipRegion[0];
clipTop = tr.clipRegion[1];
clipRight = tr.clipRegion[2];
clipBottom = tr.clipRegion[3];

// Completely clipped away
if ( right <= clipLeft || left >= clipRight ||
bottom <= clipTop || top >= clipBottom ) {
return true;
}

// Clip left edge
if ( left < clipLeft ) {
float f = ( clipLeft - left ) / ( right - left );
*s1 = ( f * ( _s2 - _s1 ) ) + _s1;
*x = clipLeft;
*w -= ( clipLeft - left );
}

// Clip right edge
if ( right > clipRight ) {
float f = ( clipRight - right ) / ( left - right );
*s2 = ( f * ( _s1 - _s2 ) ) + _s2;
*w = clipRight - *x;
}

// Clip top edge
if ( top < clipTop ) {
float f = ( clipTop - top ) / ( bottom - top );
*t1 = ( f * ( _t2 - _t1 ) ) + _t1;
*y = clipTop;
*h -= ( clipTop - top );
}

// Clip bottom edge
if ( bottom > clipBottom ) {
float f = ( clipBottom - bottom ) / ( top - bottom );
*t2 = ( f * ( _t1 - _t2 ) ) + _t2;
*h = clipBottom - *y;
}

return false;
}


/*
=============
RE_SetClipRegion
=============
*/
void RE_SetClipRegion( const float *region ) {
if ( region == NULL ) {
Com_Memset( tr.clipRegion, 0, sizeof( vec4_t ) );
} else {
Vector4Copy( region, tr.clipRegion );
}
}


void RE_StretchPic ( float x, float y, float w, float h,
float s1, float t1, float s2, float t2, qhandle_t hShader )
{
if (!tr.registered) {
return;
}
if (!tr.registered) {
return;
}
if (R_ClipRegion(&x, &y, &w, &h, &s1, &t1, &s2, &t2)) {
return;
}
stretchPicCommand_t* cmd = (stretchPicCommand_t*) R_GetCommandBuffer(sizeof(stretchPicCommand_t));
if ( !cmd ) {
return;
@@ -146,7 +236,7 @@ void RE_StretchPic ( float x, float y, float w, float h,
}


void RE_BeginFrame( void )
void RE_BeginFrame( stereoFrame_t stereoFrame )
{

if ( !tr.registered ) {
@@ -66,6 +66,8 @@ typedef struct {
frontEndCounters_t pc;
int frontEndMsec; // not in pc due to clearing issue

vec4_t clipRegion; // 2D clipping region

//
// put large tables at the end, so most elements will be
// within the +/32K indexed range on risc processors
@@ -267,6 +267,7 @@ refexport_t* GetRefAPI(int apiVersion, refimport_t *rimp)

re.RenderScene = RE_RenderScene;
re.SetColor = RE_SetColor;
re.SetClipRegion = RE_SetClipRegion;
re.DrawStretchPic = RE_StretchPic;
re.DrawStretchRaw = RE_StretchRaw;
re.UploadCinematic = RE_UploadCinematic;
File renamed without changes.
@@ -777,7 +777,7 @@ typedef struct {



float R_NoiseGet4f( float x, float y, float z, float t );
float R_NoiseGet4f( float x, float y, float z, double t );
void R_NoiseInit( void );

void R_RenderView( viewParms_t *parms );
@@ -1145,6 +1145,7 @@ void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, flo
void RE_RenderScene( const refdef_t *fd );

void RE_SetColor( const float *rgba );
void RE_SetClipRegion( const float *region );
void RE_StretchPic ( float x, float y, float w, float h,
float s1, float t1, float s2, float t2, qhandle_t hShader );
void RE_EndFrame( int *frontEndMsec, int *backEndMsec );
@@ -35,6 +35,7 @@ model_t *R_AllocModel( void ) {
model_t *mod;

if ( tr.numModels == MAX_MOD_KNOWN ) {
ri.Printf(PRINT_WARNING, "R_AllocModel: MAX_MOD_KNOWN.\n");
return NULL;
}

@@ -53,7 +53,7 @@ void R_NoiseInit( void )
}
}

float R_NoiseGet4f( float x, float y, float z, float t )
float R_NoiseGet4f( float x, float y, float z, double t )
{
int i;
int ix, iy, iz, it;
@@ -57,17 +57,16 @@ static cvar_t* r_displayIndex;
/*
SDL_WINDOW_FULLSCREEN, for "real" fullscreen with a videomode change;
SDL_WINDOW_FULLSCREEN_DESKTOP for "fake" fullscreen that takes the size of the desktop.
static VkBool32 isWindowFullscreen (void)
*/
static bool isWindowFullscreen (void)
{
return (SDL_GetWindowFlags(window_sdl) & SDL_WINDOW_FULLSCREEN) != 0;
}

static VkBool32 isDesktopFullscreen (void)
static bool isDesktopFullscreen (void)
{
return (SDL_GetWindowFlags(window_sdl) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
}
*/


static void VKimp_DetectAvailableModes(void)
@@ -262,6 +261,37 @@ static int VKimp_SetMode(int mode, bool fullscreen)
}


/*
* vk_checkFullScreen
*/
void vk_checkFullScreen(void) {
if( r_fullscreen->modified ) {
int fullscreen;
bool needToToggle;
bool sdlToggled = false;

// Find out the current state
fullscreen = isWindowFullscreen() ? 1 : 0;

if( r_fullscreen->integer && ri.Cvar_VariableIntegerValue( "in_nograb" ) ) {
ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n");
ri.Cvar_Set( "r_fullscreen", "0" );
r_fullscreen->modified = false;
}

// Is the state we want different from the current state?
needToToggle = !!r_fullscreen->integer != fullscreen;

if( needToToggle ) {
// TODO: Make transitioning too/from full screen more smooth
ri.Cmd_ExecuteText(EXEC_APPEND, "vid_restart\n");
}

r_fullscreen->modified = false;
}
}



/*
* This routine is responsible for initializing the OS specific portions of Vulkan
@@ -639,6 +639,7 @@ void vk_end_frame(void)
VkResult result = qvkQueuePresentKHR(vk.queue, &present_info);
if(result == VK_SUCCESS)
{
vk_checkFullScreen( );
return;
}
else if( (result == VK_ERROR_OUT_OF_DATE_KHR) || (result == VK_ERROR_SURFACE_LOST_KHR))
@@ -1,6 +1,8 @@
#ifndef VK_FRAME_H_
#define VK_FRAME_H_

void vk_checkFullScreen(void);

void vk_begin_frame(void);
void vk_end_frame(void);

@@ -749,7 +749,7 @@ image_t* R_FindImageFile(const char *name, VkBool32 mipmap, VkBool32 allowPicmip



void RE_UploadCinematic (int w, int h, int cols, int rows, const unsigned char *data, int client, VkBool32 dirty)
void RE_UploadCinematic (int w, int h, int cols, int rows, const unsigned char *data, int client, bool dirty)
{

image_t* prtImage = tr.scratchImage[client];
Oops, something went wrong.

0 comments on commit d361a9d

Please sign in to comment.
You can’t perform that action at this time.