mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-08 21:31:46 +08:00
ref: dx2: d3d transformation state. Drawing brushes!
This commit is contained in:
@@ -314,7 +314,22 @@ static void R_EntityRemoveDecals( struct model_s *mod )
|
||||
|
||||
void GL_Bind( int tmu, unsigned int texnum )
|
||||
{
|
||||
;
|
||||
const dx_texture_t *texture;
|
||||
|
||||
// missed or invalid texture?
|
||||
if( texnum <= 0 || texnum >= MAX_TEXTURES )
|
||||
{
|
||||
if( texnum != 0 )
|
||||
gEngfuncs.Con_DPrintf( S_ERROR "%s: invalid texturenum %d\n", __func__, texnum );
|
||||
texnum = tr.defaultTexture;
|
||||
}
|
||||
|
||||
texture = R_GetTexture( texnum );
|
||||
|
||||
//if( dxc.currentTexture == texture->d3dHandle )
|
||||
// return;
|
||||
|
||||
dxc.currentTexture = texture->d3dHandle;
|
||||
}
|
||||
|
||||
static void GL_LoadTextureMatrix( const float *glmatrix )
|
||||
|
||||
@@ -205,8 +205,8 @@ static qboolean D3D_InitDevice( void )
|
||||
viewport.dwY = 0;
|
||||
viewport.dwWidth = desc.dwWidth;
|
||||
viewport.dwHeight = desc.dwHeight;
|
||||
viewport.dvScaleX = 1;
|
||||
viewport.dvScaleY = 1;
|
||||
viewport.dvScaleX = 0.5 * viewport.dwWidth;
|
||||
viewport.dvScaleY = 0.5f * viewport.dwHeight;
|
||||
viewport.dvMaxX = 1;
|
||||
viewport.dvMaxY = 1;
|
||||
viewport.dvMinZ = 0;
|
||||
@@ -214,6 +214,33 @@ static qboolean D3D_InitDevice( void )
|
||||
DXCheck(IDirect3DViewport_SetViewport(dxc.viewport, &viewport));
|
||||
|
||||
DXCheck(IDirect3DDevice_CreateMatrix(dxc.pd3dd, &dxc.mtxWorld));
|
||||
DXCheck(IDirect3DDevice_CreateMatrix(dxc.pd3dd, &dxc.mtxProjection));
|
||||
|
||||
//set transform state
|
||||
{
|
||||
d3dEBContext_t ebc = { 0 };
|
||||
if (!D3D_StartExecuteBuffer(&ebc))
|
||||
return;
|
||||
void *cur = ebc.data;
|
||||
|
||||
D3D_PutInstruction(&cur, D3DOP_STATETRANSFORM, sizeof(D3DSTATE), 2);
|
||||
D3D_PutTransformState(&cur, D3DTRANSFORMSTATE_WORLD, dxc.mtxWorld);
|
||||
D3D_PutTransformState(&cur, D3DTRANSFORMSTATE_PROJECTION, dxc.mtxProjection);
|
||||
D3D_PutInstruction(&cur, D3DOP_EXIT, 0, 0);
|
||||
|
||||
ebc.vertCount = 0;
|
||||
ebc.insOffset = 0;
|
||||
ebc.insLength = ((char *)cur - (char *)ebc.data);
|
||||
|
||||
if (!D3D_EndExecuteBuffer(&ebc))
|
||||
return;
|
||||
|
||||
DXCheck(IDirect3DDevice_BeginScene(dxc.pd3dd));
|
||||
DXCheck(IDirect3DDevice_Execute(dxc.pd3dd, ebc.pd3deb, dxc.viewport, D3DEXECUTE_CLIPPED));
|
||||
DXCheck(IDirect3DDevice_EndScene(dxc.pd3dd));
|
||||
|
||||
D3D_ReleaseExecuteBuffer(&ebc);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,8 @@ struct dx_context_s
|
||||
|
||||
int renderMode;
|
||||
vec4_t currentColor;
|
||||
|
||||
D3DTEXTUREHANDLE currentTexture;
|
||||
D3DTEXTUREHANDLE lastBoundTexture;
|
||||
};
|
||||
typedef struct dx_context_s dx_context_t;
|
||||
|
||||
@@ -234,6 +235,7 @@ extern dx_globals_t tr;
|
||||
extern dx_context_t dxc;
|
||||
|
||||
extern ref_api_t gEngfuncs;
|
||||
extern ref_globals_t *gpGlobals;
|
||||
extern ref_client_t *gp_cl;
|
||||
|
||||
|
||||
@@ -303,6 +305,7 @@ void R_ClearScene( void );
|
||||
int WorldToScreen( const vec3_t world, vec3_t screen );
|
||||
void ScreenToWorld( const float *screen, float *world );
|
||||
void R_LoadIdentity( void );
|
||||
void R_SetupD3D( qboolean set_state );
|
||||
|
||||
// r_draw.c
|
||||
void R_Set2DMode( qboolean enable );
|
||||
|
||||
@@ -142,6 +142,12 @@ void R_BeginFrame( qboolean clearScene )
|
||||
gEngfuncs.CL_ExtraUpdate();
|
||||
}
|
||||
|
||||
static void R_DrawEntitiesOnList( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void R_RenderScene( void )
|
||||
{
|
||||
model_t *worldmodel = gp_cl->models[1];
|
||||
@@ -162,7 +168,9 @@ void R_RenderScene( void )
|
||||
R_SetupFrustum();
|
||||
#if 0
|
||||
R_SetupFrame();
|
||||
R_SetupGL(true);
|
||||
#endif
|
||||
R_SetupD3D(true);
|
||||
#if 0
|
||||
R_Clear(~0);
|
||||
#endif
|
||||
R_MarkLeaves();
|
||||
@@ -178,11 +186,11 @@ void R_RenderScene( void )
|
||||
// R_CheckFog();
|
||||
|
||||
gEngfuncs.CL_ExtraUpdate(); // don't let sound get messed up if going slow
|
||||
#if 0
|
||||
|
||||
R_DrawEntitiesOnList();
|
||||
|
||||
R_DrawWaterSurfaces();
|
||||
#endif
|
||||
// R_DrawWaterSurfaces();
|
||||
|
||||
}
|
||||
|
||||
void R_EndFrame( void )
|
||||
@@ -307,3 +315,66 @@ void ScreenToWorld( const float *screen, float *world )
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void R_SetupD3D( qboolean set_state )
|
||||
{
|
||||
R_SetupModelviewMatrix(RI.worldviewMatrix);
|
||||
R_SetupProjectionMatrix(RI.projectionMatrix);
|
||||
|
||||
Matrix4x4_Concat(RI.worldviewProjectionMatrix, RI.projectionMatrix, RI.worldviewMatrix);
|
||||
|
||||
if (!set_state) return;
|
||||
|
||||
D3DVIEWPORT viewport = { 0 };
|
||||
viewport.dwSize = sizeof(viewport);
|
||||
|
||||
if (FBitSet(RI.params, RP_ENVVIEW) == 0)
|
||||
{
|
||||
int x, x2, y, y2;
|
||||
|
||||
// set up viewport (main, playersetup)
|
||||
x = floor(RI.viewport[0] * gpGlobals->width / gpGlobals->width);
|
||||
x2 = ceil((RI.viewport[0] + RI.viewport[2]) * gpGlobals->width / gpGlobals->width);
|
||||
y = floor(gpGlobals->height - RI.viewport[1] * gpGlobals->height / gpGlobals->height);
|
||||
y2 = ceil(gpGlobals->height - (RI.viewport[1] + RI.viewport[3]) * gpGlobals->height / gpGlobals->height);
|
||||
|
||||
if (tr.rotation & 1)
|
||||
{
|
||||
viewport.dwX = y2;
|
||||
viewport.dwY = x;
|
||||
viewport.dwWidth = y - y2;
|
||||
viewport.dwHeight = x2 - x;
|
||||
}
|
||||
else
|
||||
{
|
||||
viewport.dwX = x;
|
||||
viewport.dwY = y2;
|
||||
viewport.dwWidth = x2 - x;
|
||||
viewport.dwHeight = y - y2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// envpass, mirrorpass
|
||||
viewport.dwX = RI.viewport[0];
|
||||
viewport.dwY = RI.viewport[1];
|
||||
viewport.dwWidth = RI.viewport[2];
|
||||
viewport.dwHeight = RI.viewport[3];
|
||||
}
|
||||
|
||||
viewport.dvScaleX = 0.5f * viewport.dwWidth;
|
||||
viewport.dvScaleY = 0.5f * viewport.dwHeight;
|
||||
viewport.dvMaxX = 1;//calc for partial views
|
||||
viewport.dvMaxY = 1;
|
||||
viewport.dvMinZ = 0;
|
||||
viewport.dvMaxZ = 1;
|
||||
DXCheck(IDirect3DViewport_SetViewport(dxc.viewport, &viewport));
|
||||
|
||||
{
|
||||
float dest[16];
|
||||
Matrix4x4_ToArrayFloatGL(RI.projectionMatrix, dest);
|
||||
DXCheck(IDirect3DDevice_SetMatrix(dxc.pd3dd, dxc.mtxProjection, (D3DMATRIX *)&dest));
|
||||
Matrix4x4_ToArrayFloatGL(RI.worldviewMatrix, dest);
|
||||
DXCheck(IDirect3DDevice_SetMatrix(dxc.pd3dd, dxc.mtxWorld, (D3DMATRIX *)&dest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,9 +222,6 @@ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale )
|
||||
D3D_PutInstruction(&cur, D3DOP_TRIANGLE, sizeof(D3DTRIANGLE), 0);
|
||||
}
|
||||
|
||||
D3D_PutInstruction(&cur, D3DOP_STATETRANSFORM, sizeof(D3DSTATE), 1);
|
||||
D3D_PutTransformState(&cur, D3DTRANSFORMSTATE_WORLD, dxc.mtxWorld);
|
||||
|
||||
D3D_PutInstruction(&cur, D3DOP_STATERENDER, sizeof(D3DSTATE), 4);
|
||||
D3D_PutRenderState(&cur, D3DRENDERSTATE_TEXTUREHANDLE, dxc.currentTexture);
|
||||
D3D_PutRenderState(&cur, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_DECAL);
|
||||
@@ -253,6 +250,7 @@ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale )
|
||||
DXCheck(IDirect3DDevice_EndScene(dxc.pd3dd));
|
||||
|
||||
D3D_ReleaseExecuteBuffer( &ebc );
|
||||
//
|
||||
|
||||
//if( FBitSet( p->flags, SURF_DRAWTILED ))
|
||||
// GL_SetupFogColorForSurfaces();
|
||||
@@ -268,7 +266,9 @@ static void R_RenderBrushPoly( msurface_t *fa, int cull_type )
|
||||
return; // already handled
|
||||
|
||||
t = R_TextureAnimation( fa );
|
||||
GL_Bind( XASH_TEXTURE0, t->gl_texturenum );
|
||||
|
||||
GL_Bind( XASH_TEXTURE0, t->gl_texturenum );
|
||||
|
||||
DrawGLPoly( fa->polys, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
@@ -289,7 +289,6 @@ static void R_DrawTextureChains( void )
|
||||
RI.currententity = CL_GetEntityByIndex( 0 );
|
||||
RI.currentmodel = RI.currententity->model;
|
||||
|
||||
|
||||
for( i = 0; i < WORLDMODEL->numtextures; i++ )
|
||||
{
|
||||
t = WORLDMODEL->textures[i];
|
||||
|
||||
@@ -10,7 +10,7 @@ def configure(conf):
|
||||
|
||||
def build(bld):
|
||||
bld.shlib(
|
||||
source = ['r_context.c', 'r_image.c', 'r_d3d.c', 'r_main.c', 'r_draw.c', 'r_surf.c'],
|
||||
source = ['r_context.c', 'r_image.c', 'r_d3d.c', 'r_main.c', 'r_draw.c', 'r_surf.c', 'r_frustum.c'],
|
||||
target = 'ref_dx2',
|
||||
defines = 'REF_DLL',
|
||||
use = 'engine_includes sdk_includes werror public USER32 DDRAW',
|
||||
|
||||
Reference in New Issue
Block a user