Skip to content

Commit

Permalink
Merge branch 'master' into for-0.55.0/sync
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 8, 2024
2 parents 51efd46 + 36ec97b commit 6779ec8
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/engine/qcommon/q_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

#include "q_shared.h"

#define DotProduct4(x, y) (( x )[ 0 ] * ( y )[ 0 ] + ( x )[ 1 ] * ( y )[ 1 ] + ( x )[ 2 ] * ( y )[ 2 ] + ( x )[ 3 ] * ( y )[ 3 ] )
#define VectorMultiply( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] * ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] * ( b )[ 1 ],( c )[ 2 ] = ( a )[ 2 ] * ( b )[ 2 ] )

const vec3_t vec3_origin = { 0, 0, 0 };

const vec3_t axisDefault[ 3 ] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
Expand Down
130 changes: 111 additions & 19 deletions src/engine/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,30 +381,122 @@ inline float DotProduct( const vec3_t x, const vec3_t y )
return x[ 0 ] * y[ 0 ] + x[ 1 ] * y[ 1 ] + x[ 2 ] * y[ 2 ];
}

#define VectorSubtract( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] - ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] - ( b )[ 1 ],( c )[ 2 ] = ( a )[ 2 ] - ( b )[ 2 ] )
#define VectorAdd( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] + ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] + ( b )[ 1 ],( c )[ 2 ] = ( a )[ 2 ] + ( b )[ 2 ] )
#define VectorMultiply( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] * ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] * ( b )[ 1 ],( c )[ 2 ] = ( a )[ 2 ] * ( b )[ 2 ] )
#define VectorCopy( a,b ) ( ( b )[ 0 ] = ( a )[ 0 ],( b )[ 1 ] = ( a )[ 1 ],( b )[ 2 ] = ( a )[ 2 ] )
#define VectorScale( v, s, o ) ( ( o )[ 0 ] = ( v )[ 0 ] * ( s ),( o )[ 1 ] = ( v )[ 1 ] * ( s ),( o )[ 2 ] = ( v )[ 2 ] * ( s ) )
template<typename A, typename B, typename C>
void VectorSubtract( const A &a, const B &b, C &&c )
{
c[ 0 ] = a[ 0 ] - b[ 0 ];
c[ 1 ] = a[ 1 ] - b[ 1 ];
c[ 2 ] = a[ 2 ] - b[ 2 ];
}

template<typename A, typename B, typename C>
void VectorAdd( const A &a, const B &b, C &&c )
{
c[ 0 ] = a[ 0 ] + b[ 0 ];
c[ 1 ] = a[ 1 ] + b[ 1 ];
c[ 2 ] = a[ 2 ] + b[ 2 ];
}

template<typename A, typename B>
void VectorCopy( const A &a, B &&b )
{
b[ 0 ] = a[ 0 ];
b[ 1 ] = a[ 1 ];
b[ 2 ] = a[ 2 ];
}

template<typename V, typename S, typename O>
void VectorScale( const V &v, S s, O &&o )
{
o[ 0 ] = v[ 0 ] * s;
o[ 1 ] = v[ 1 ] * s;
o[ 2 ] = v[ 2 ] * s;
}

/** Stands for MultiplyAdd: adding a vector "b" scaled by "s" to "v" and writing it to "o" */
#define VectorMA( v, s, b, o ) ( ( o )[ 0 ] = ( v )[ 0 ] + ( b )[ 0 ] * ( s ),( o )[ 1 ] = ( v )[ 1 ] + ( b )[ 1 ] * ( s ),( o )[ 2 ] = ( v )[ 2 ] + ( b )[ 2 ] * ( s ) )
#define VectorLerpTrem( f, s, e, r ) (( r )[ 0 ] = ( s )[ 0 ] + ( f ) * (( e )[ 0 ] - ( s )[ 0 ] ), \
( r )[ 1 ] = ( s )[ 1 ] + ( f ) * (( e )[ 1 ] - ( s )[ 1 ] ), \
( r )[ 2 ] = ( s )[ 2 ] + ( f ) * (( e )[ 2 ] - ( s )[ 2 ] ))
template<typename V, typename S, typename B, typename O>
void VectorMA( const V &v, S s, const B &b, O &&o )
{
o[ 0 ] = v[ 0 ] + b[ 0 ] * s;
o[ 1 ] = v[ 1 ] + b[ 1 ] * s;
o[ 2 ] = v[ 2 ] + b[ 2 ] * s;
}

template<typename A>
void VectorClear( A &&a )
{
a[ 0 ] = 0;
a[ 1 ] = 0;
a[ 2 ] = 0;
}

template<typename A, typename B>
void VectorNegate( const A &a, B &&b )
{
b[ 0 ] = -a[ 0 ];
b[ 1 ] = -a[ 1 ];
b[ 2 ] = -a[ 2 ];
}

template<typename V, typename X, typename Y, typename Z>
void VectorSet( V &&v, X x, Y y, Z z )
{
v[ 0 ] = x;
v[ 1 ] = y;
v[ 2 ] = z;
}

template<typename A, typename B>
void Vector2Copy( const A &a, B &&b )
{
b[ 0 ] = a[ 0 ];
b[ 1 ] = a[ 1 ];
}

template<typename V, typename X, typename Y>
void Vector2Set( V &&v, X x, Y y )
{
v[ 0 ] = x;
v[ 1 ] = y;
}

template<typename A, typename B, typename C>
void Vector2Subtract( const A &a, const B &b, C &&c )
{
c[ 0 ] = a[ 0 ] - b[ 0 ];
c[ 1 ] = a[ 1 ] - b[ 1 ];
}

#define VectorClear( a ) ( ( a )[ 0 ] = ( a )[ 1 ] = ( a )[ 2 ] = 0 )
#define VectorNegate( a,b ) ( ( b )[ 0 ] = -( a )[ 0 ],( b )[ 1 ] = -( a )[ 1 ],( b )[ 2 ] = -( a )[ 2 ] )
#define VectorSet( v, x, y, z ) ( ( v )[ 0 ] = ( x ), ( v )[ 1 ] = ( y ), ( v )[ 2 ] = ( z ) )
template<typename V, typename X, typename Y, typename Z, typename W>
void Vector4Set( V &&v, X x, Y y, Z z, W w )
{
v[ 0 ] = x;
v[ 1 ] = y;
v[ 2 ] = z;
v[ 3 ] = w;
}

#define Vector2Set( v, x, y ) ( ( v )[ 0 ] = ( x ),( v )[ 1 ] = ( y ) )
#define Vector2Copy( a,b ) ( ( b )[ 0 ] = ( a )[ 0 ],( b )[ 1 ] = ( a )[ 1 ] )
#define Vector2Subtract( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] - ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] - ( b )[ 1 ] )
template<typename A, typename B>
void Vector4Copy( const A &a, B &&b )
{
b[ 0 ] = a[ 0 ];
b[ 1 ] = a[ 1 ];
b[ 2 ] = a[ 2 ];
b[ 3 ] = a[ 3 ];
}

#define Vector4Set( v, x, y, z, n ) ( ( v )[ 0 ] = ( x ),( v )[ 1 ] = ( y ),( v )[ 2 ] = ( z ),( v )[ 3 ] = ( n ) )
#define Vector4Copy( a,b ) ( ( b )[ 0 ] = ( a )[ 0 ],( b )[ 1 ] = ( a )[ 1 ],( b )[ 2 ] = ( a )[ 2 ],( b )[ 3 ] = ( a )[ 3 ] )
#define DotProduct4(x, y) (( x )[ 0 ] * ( y )[ 0 ] + ( x )[ 1 ] * ( y )[ 1 ] + ( x )[ 2 ] * ( y )[ 2 ] + ( x )[ 3 ] * ( y )[ 3 ] )
// good for floats only
template<typename V>
void SnapVector( V &&v )
{
v[ 0 ] = roundf( v[ 0 ] );
v[ 1 ] = roundf( v[ 1 ] );
v[ 2 ] = roundf( v[ 2 ] );
}

#define SnapVector( v ) do { ( v )[ 0 ] = ( floor( ( v )[ 0 ] + 0.5f ) ); ( v )[ 1 ] = ( floor( ( v )[ 1 ] + 0.5f ) ); ( v )[ 2 ] = ( floor( ( v )[ 2 ] + 0.5f ) ); } while ( 0 )
#define VectorLerpTrem( f, s, e, r ) (( r )[ 0 ] = ( s )[ 0 ] + ( f ) * (( e )[ 0 ] - ( s )[ 0 ] ), \
( r )[ 1 ] = ( s )[ 1 ] + ( f ) * (( e )[ 1 ] - ( s )[ 1 ] ), \
( r )[ 2 ] = ( s )[ 2 ] + ( f ) * (( e )[ 2 ] - ( s )[ 2 ] ))

float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
void ZeroBounds( vec3_t mins, vec3_t maxs );
Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_arb_uniform_buffer_object;
cvar_t *r_arb_texture_gather;
cvar_t *r_arb_gpu_shader5;
Cvar::Cvar<bool> r_arb_depth_clamp("r_arb_depth_clamp", "Use GL_ARB_depth_clamp if available", Cvar::NONE, true);

cvar_t *r_checkGLErrors;
cvar_t *r_logFile;
Expand Down Expand Up @@ -1089,6 +1090,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_arb_uniform_buffer_object = Cvar_Get( "r_arb_uniform_buffer_object", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_texture_gather = Cvar_Get( "r_arb_texture_gather", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_gpu_shader5 = Cvar_Get( "r_arb_gpu_shader5", "1", CVAR_CHEAT | CVAR_LATCH );
Cvar::Latch(r_arb_depth_clamp);

r_picMip = Cvar_Get( "r_picMip", "0", CVAR_LATCH | CVAR_ARCHIVE );
r_imageMaxDimension = Cvar_Get( "r_imageMaxDimension", "0", CVAR_LATCH | CVAR_ARCHIVE );
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2901,6 +2901,7 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
extern cvar_t *r_arb_uniform_buffer_object;
extern cvar_t *r_arb_texture_gather;
extern cvar_t *r_arb_gpu_shader5;
extern Cvar::Cvar<bool> r_arb_depth_clamp;

extern cvar_t *r_nobind; // turns off binding to appropriate textures
extern cvar_t *r_singleShader; // make most world faces use default shader
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct glconfig2_t
bool uniformBufferObjectAvailable;
bool mapBufferRangeAvailable;
bool syncAvailable;
bool depthClampAvailable;

bool dynamicLight;
bool staticLight;
Expand Down
10 changes: 8 additions & 2 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,10 @@ static void Render_generic2D( shaderStage_t *pStage )
BindAnimatedImage( &pStage->bundle[ TB_COLORMAP ] );
gl_generic2DShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] );

glEnable( GL_DEPTH_CLAMP );
if ( glConfig2.depthClampAvailable )
{
glEnable( GL_DEPTH_CLAMP );
}

if ( hasDepthFade )
{
Expand All @@ -676,7 +679,10 @@ static void Render_generic2D( shaderStage_t *pStage )

Tess_DrawElements();

glDisable( GL_DEPTH_CLAMP );
if ( glConfig2.depthClampAvailable )
{
glDisable( GL_DEPTH_CLAMP );
}

GL_CheckErrors();
}
Expand Down
3 changes: 3 additions & 0 deletions src/engine/sys/sdl_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,9 @@ static void GLimp_InitExtensions()
// made required in OpenGL 3.2
glConfig2.syncAvailable = LOAD_EXTENSION_WITH_TEST( ExtFlag_CORE, ARB_sync, r_arb_sync->value );

// made required in OpenGL 3.2
glConfig2.depthClampAvailable = LOAD_EXTENSION_WITH_TEST( ExtFlag_CORE, ARB_depth_clamp, r_arb_depth_clamp.Get() );

GL_CheckErrors();
}

Expand Down
28 changes: 14 additions & 14 deletions src/shared/client/cg_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int trap_CM_MarkFragments( int numPoints, const vec3_t *points, const vec3_t pro
std::vector<std::array<float, 3>> mypoints(numPoints);
std::array<float, 3> myproj;
memcpy((float*)mypoints.data(), points, sizeof(float) * 3 * numPoints);
VectorCopy(projection, myproj.data());
VectorCopy(projection, myproj);

std::vector<std::array<float, 3>> mypointBuffer;
std::vector<markFragment_t> myfragmentBuffer;
Expand Down Expand Up @@ -292,8 +292,8 @@ bool trap_R_inPVVS( const vec3_t p1, const vec3_t p2 )
{
bool res;
std::array<float, 3> myp1, myp2;
VectorCopy(p1, myp1.data());
VectorCopy(p2, myp2.data());
VectorCopy(p1, myp1);
VectorCopy(p2, myp2);
VM::SendMsg<Render::InPVVSMsg>(myp1, myp2, res);
return res;
}
Expand Down Expand Up @@ -396,14 +396,14 @@ void trap_R_ResetMatrixTransform()
void trap_R_AddLightToScene( const vec3_t org, float radius, float intensity, float r, float g, float b, qhandle_t hShader, int flags )
{
std::array<float, 3> myorg;
VectorCopy(org, myorg.data());
VectorCopy(org, myorg);
cmdBuffer.SendMsg<Render::AddLightToSceneMsg>(myorg, radius, intensity, r, g, b, hShader, flags);
}

void trap_R_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b )
{
std::array<float, 3> myorg;
VectorCopy(org, myorg.data());
VectorCopy(org, myorg);
cmdBuffer.SendMsg<Render::AddAdditiveLightToSceneMsg>(myorg, intensity, r, g, b);
}

Expand Down Expand Up @@ -446,8 +446,8 @@ void trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs )
{
std::array<float, 3> mymins, mymaxs;
VM::SendMsg<Render::ModelBoundsMsg>(model, mymins, mymaxs);
VectorCopy(mymins.data(), mins);
VectorCopy(mymaxs.data(), maxs);
VectorCopy(mymins, mins);
VectorCopy(mymaxs, maxs);
}

int trap_R_LerpTag( orientation_t *tag, const refEntity_t *refent, const char *tagName, int startIndex )
Expand All @@ -466,8 +466,8 @@ bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 )
{
bool res;
std::array<float, 3> myp1, myp2;
VectorCopy(p1, myp1.data());
VectorCopy(p2, myp2.data());
VectorCopy(p1, myp1);
VectorCopy(p2, myp2);
VM::SendMsg<Render::InPVSMsg>(myp1, myp2, res);
return res;
}
Expand All @@ -487,11 +487,11 @@ int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLigh
{
int result;
std::array<float, 3> mypoint, myambient, mydirected, mydir;
VectorCopy(point, mypoint.data());
VectorCopy(point, mypoint);
VM::SendMsg<Render::LightForPointMsg>(mypoint, myambient, mydirected, mydir, result);
VectorCopy(myambient.data(), ambientLight);
VectorCopy(mydirected.data(), directedLight);
VectorCopy(mydir.data(), lightDir);
VectorCopy(myambient, ambientLight);
VectorCopy(mydirected, directedLight);
VectorCopy(mydir, lightDir);
return result;
}

Expand Down Expand Up @@ -578,7 +578,7 @@ qhandle_t trap_RegisterVisTest()
void trap_AddVisTestToScene( qhandle_t hTest, const vec3_t pos, float depthAdjust, float area )
{
std::array<float, 3> mypos;
VectorCopy(pos, mypos.data());
VectorCopy(pos, mypos);
cmdBuffer.SendMsg<Render::AddVisTestToSceneMsg>(hTest, mypos, depthAdjust, area);
}

Expand Down

0 comments on commit 6779ec8

Please sign in to comment.