mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-18 23:00:01 +01:00
vk: stub just enough triapi to render more beam types
it is still drawn incorrectly, but at least something is visible, and we can iterate from here
This commit is contained in:
parent
ee4def1141
commit
a118e12e01
@ -7,6 +7,7 @@
|
||||
#include "vk_sprite.h"
|
||||
#include "vk_scene.h"
|
||||
#include "vk_math.h"
|
||||
#include "vk_triapi.h"
|
||||
|
||||
#include "xash3d_types.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
@ -400,9 +401,6 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
|
||||
static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments )
|
||||
{
|
||||
PRINT_NOT_IMPLEMENTED();
|
||||
|
||||
/* FIXME VK
|
||||
int i, noiseIndex, noiseStep;
|
||||
float div, length, fraction, factor, vLast, vStep;
|
||||
vec3_t last1, last2, point, screen, screenLast, tmp, normal;
|
||||
@ -481,7 +479,6 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale,
|
||||
VectorCopy( screen, screenLast );
|
||||
noiseIndex += noiseStep;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments )
|
||||
@ -741,9 +738,6 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime )
|
||||
|
||||
static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitude, float freq, float speed, int segments )
|
||||
{
|
||||
PRINT_NOT_IMPLEMENTED();
|
||||
|
||||
/* FIXME VK
|
||||
int i, j, noiseIndex, noiseStep;
|
||||
float div, length, fraction, factor, vLast, vStep;
|
||||
vec3_t last1, last2, point, screen, screenLast;
|
||||
@ -787,6 +781,7 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud
|
||||
VectorAdd( center, last1, tmp ); // maxs
|
||||
VectorSubtract( center, last1, screen ); // mins
|
||||
|
||||
/* FIXME VK
|
||||
if( !WORLDMODEL )
|
||||
return;
|
||||
|
||||
@ -795,6 +790,7 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud
|
||||
{
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
VectorSet( yaxis, xaxis[1], -xaxis[0], 0.0f );
|
||||
VectorNormalize( yaxis );
|
||||
@ -855,7 +851,6 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud
|
||||
FracNoise( rgNoise, NOISE_DIVISIONS );
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1115,15 +1110,24 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
{
|
||||
case TE_BEAMTORUS:
|
||||
// FIXME VK GL_Cull( GL_NONE );
|
||||
TriBegin( TRI_TRIANGLE_STRIP );
|
||||
TriColor4f( color[0], color[1], color[2], color[3] );
|
||||
R_DrawTorus( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments );
|
||||
TriEnd();
|
||||
break;
|
||||
case TE_BEAMDISK:
|
||||
// FIXME VK GL_Cull( GL_NONE );
|
||||
TriBegin( TRI_TRIANGLE_STRIP );
|
||||
TriColor4f( color[0], color[1], color[2], color[3] );
|
||||
R_DrawDisk( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments );
|
||||
TriEnd();
|
||||
break;
|
||||
case TE_BEAMCYLINDER:
|
||||
// FIXME VK GL_Cull( GL_NONE );
|
||||
TriBegin( TRI_TRIANGLE_STRIP );
|
||||
TriColor4f( color[0], color[1], color[2], color[3] );
|
||||
R_DrawCylinder( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments );
|
||||
TriEnd();
|
||||
break;
|
||||
case TE_BEAMPOINTS:
|
||||
case TE_BEAMHOSE:
|
||||
@ -1131,11 +1135,16 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
break;
|
||||
case TE_BEAMFOLLOW:
|
||||
// FIXME VK TriBegin( TRI_QUADS );
|
||||
R_DrawBeamFollow( pbeam, frametime );
|
||||
//TriColor4f( color[0], color[1], color[2], color[3] );
|
||||
//R_DrawBeamFollow( pbeam, frametime );
|
||||
//TriEnd();
|
||||
break;
|
||||
case TE_BEAMRING:
|
||||
// FIXME VK GL_Cull( GL_NONE );
|
||||
TriBegin( TRI_TRIANGLE_STRIP );
|
||||
TriColor4f( color[0], color[1], color[2], color[3] );
|
||||
R_DrawRing( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments );
|
||||
TriEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
|
168
ref/vk/vk_triapi.c
Normal file
168
ref/vk/vk_triapi.c
Normal file
@ -0,0 +1,168 @@
|
||||
#include "vk_triapi.h"
|
||||
#include "vk_geometry.h"
|
||||
#include "vk_render.h"
|
||||
|
||||
#include "vk_textures.h" // FIXME temp
|
||||
|
||||
#include "xash3d_mathlib.h"
|
||||
|
||||
#define MAX_TRIAPI_VERTICES 1024
|
||||
#define MAX_TRIAPI_INDICES 1024
|
||||
|
||||
static struct {
|
||||
vk_vertex_t vertices[MAX_TRIAPI_VERTICES];
|
||||
uint16_t indices[MAX_TRIAPI_INDICES];
|
||||
|
||||
int num_vertices;
|
||||
int mode;
|
||||
} g_triapi = {0};
|
||||
|
||||
void TriBegin( int mode ) {
|
||||
ASSERT(!g_triapi.mode);
|
||||
|
||||
switch(mode) {
|
||||
case TRI_TRIANGLES: break;
|
||||
case TRI_TRIANGLE_STRIP: break;
|
||||
default:
|
||||
gEngine.Con_Printf(S_ERROR "TriBegin: unsupported mode %d\n", mode);
|
||||
return;
|
||||
}
|
||||
|
||||
g_triapi.mode = mode + 1;
|
||||
g_triapi.num_vertices = 0;
|
||||
|
||||
vk_vertex_t *const ve = g_triapi.vertices + 0;
|
||||
memset(ve, 0, sizeof *ve);
|
||||
Vector4Set(ve->color, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
/* static int genTrianglesIndices(void) { */
|
||||
/* return 0; */
|
||||
/* } */
|
||||
|
||||
static int genTriangleStripIndices(void) {
|
||||
int num_indices = 0;
|
||||
uint16_t *const dst_idx = g_triapi.indices;
|
||||
for (int i = 2; i < g_triapi.num_vertices; ++i) {
|
||||
if( i & 1 )
|
||||
{
|
||||
// draw triangle [n-1 n-2 n]
|
||||
dst_idx[num_indices++] = i - 1;
|
||||
dst_idx[num_indices++] = i - 2;
|
||||
dst_idx[num_indices++] = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
// draw triangle [n-2 n-1 n]
|
||||
dst_idx[num_indices++] = i - 2;
|
||||
dst_idx[num_indices++] = i - 1;
|
||||
dst_idx[num_indices++] = i;
|
||||
}
|
||||
}
|
||||
return num_indices;
|
||||
}
|
||||
|
||||
static void emitDynamicGeometry(int num_indices) {
|
||||
if (!num_indices)
|
||||
return;
|
||||
|
||||
r_geometry_buffer_lock_t buffer;
|
||||
if (!R_GeometryBufferAllocAndLock( &buffer, g_triapi.num_vertices, num_indices, LifetimeSingleFrame )) {
|
||||
gEngine.Con_Printf(S_ERROR "Cannot allocate geometry for tri api\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(buffer.vertices.ptr, g_triapi.vertices, sizeof(vk_vertex_t) * g_triapi.num_vertices);
|
||||
memcpy(buffer.indices.ptr, g_triapi.indices, sizeof(uint16_t) * num_indices);
|
||||
|
||||
R_GeometryBufferUnlock( &buffer );
|
||||
|
||||
{
|
||||
// FIXME pass these properly
|
||||
const int texture = tglob.whiteTexture;
|
||||
const vec4_t color = {1, 1, 1, 1};
|
||||
const vk_render_type_e render_type = kVkRenderType_A_1_R;
|
||||
const char* name = "FIXME triapi";
|
||||
|
||||
const vk_render_geometry_t geometry = {
|
||||
.texture = texture,
|
||||
.material = kXVkMaterialEmissive,
|
||||
|
||||
.max_vertex = g_triapi.num_vertices,
|
||||
.vertex_offset = buffer.vertices.unit_offset,
|
||||
|
||||
.element_count = num_indices,
|
||||
.index_offset = buffer.indices.unit_offset,
|
||||
|
||||
.emissive = { color[0], color[1], color[2] },
|
||||
};
|
||||
|
||||
VK_RenderModelDynamicBegin( render_type, color, name );
|
||||
VK_RenderModelDynamicAddGeometry( &geometry );
|
||||
VK_RenderModelDynamicCommit();
|
||||
}
|
||||
}
|
||||
|
||||
void TriEnd( void ) {
|
||||
if (!g_triapi.mode)
|
||||
return;
|
||||
|
||||
if (!g_triapi.num_vertices)
|
||||
return;
|
||||
|
||||
int num_indices = 0;
|
||||
switch(g_triapi.mode - 1) {
|
||||
/* case TRI_TRIANGLES: */
|
||||
/* num_indices = genTrianglesIndices(); */
|
||||
/* break; */
|
||||
case TRI_TRIANGLE_STRIP:
|
||||
num_indices = genTriangleStripIndices();
|
||||
break;
|
||||
default:
|
||||
gEngine.Con_Printf(S_ERROR "TriEnd: unsupported mode %d\n", g_triapi.mode - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
emitDynamicGeometry(num_indices);
|
||||
|
||||
g_triapi.num_vertices = 0;
|
||||
g_triapi.mode = 0;
|
||||
}
|
||||
|
||||
void TriTexCoord2f( float u, float v ) {
|
||||
vk_vertex_t *const ve = g_triapi.vertices + g_triapi.num_vertices;
|
||||
Vector2Set(ve->gl_tc, u, v);
|
||||
}
|
||||
|
||||
void TriVertex3fv( const float *v ) {
|
||||
TriVertex3f(v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
void TriVertex3f( float x, float y, float z ) {
|
||||
if (g_triapi.num_vertices == MAX_TRIAPI_VERTICES - 1) {
|
||||
gEngine.Con_Printf(S_ERROR "vk TriApi: trying to emit more than %d vertices in one batch\n", MAX_TRIAPI_VERTICES);
|
||||
return;
|
||||
}
|
||||
|
||||
vk_vertex_t *const ve = g_triapi.vertices + g_triapi.num_vertices;
|
||||
VectorSet(ve->pos, x, y, z);
|
||||
|
||||
// Emit vertex preserving previous vertex values
|
||||
++g_triapi.num_vertices;
|
||||
g_triapi.vertices[g_triapi.num_vertices] = g_triapi.vertices[g_triapi.num_vertices-1];
|
||||
}
|
||||
|
||||
static int clampi32(int v, int min, int max) {
|
||||
if (v < min) return min;
|
||||
if (v > max) return max;
|
||||
return v;
|
||||
}
|
||||
|
||||
void TriColor4ub_( byte r, byte g, byte b, byte a ) {
|
||||
Vector4Set(g_triapi.vertices[g_triapi.num_vertices].color, r, g, b, a);
|
||||
}
|
||||
|
||||
void TriColor4f( float r, float g, float b, float a ) {
|
||||
TriColor4ub_(clampi32(r*255.f, 0, 255),clampi32(g*255.f, 0, 255),clampi32(b*255.f, 0, 255),clampi32(a*255.f, 0, 255));
|
||||
}
|
||||
|
15
ref/vk/vk_triapi.h
Normal file
15
ref/vk/vk_triapi.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "xash3d_types.h"
|
||||
|
||||
void TriBegin( int mode );
|
||||
|
||||
void TriTexCoord2f( float u, float v );
|
||||
void TriColor4f( float r, float g, float b, float a );
|
||||
//void TriColor4ub( byte r, byte g, byte b, byte a );
|
||||
|
||||
// Emits next vertex
|
||||
void TriVertex3fv( const float *v );
|
||||
void TriVertex3f( float x, float y, float z );
|
||||
|
||||
void TriEnd( void );
|
Loading…
x
Reference in New Issue
Block a user