//================================================================
// E3D
//
// Base for PointSet, Face, Mesh, etc.
//
// AUTHOR:  Gabor Nagy
// DATE:    2025-Dec-08 00:57:28
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================
#ifndef _E3D_VertexGeometry_h
#define _E3D_VertexGeometry_h

#ifndef _E3D_Geometry_h
#include <E3D/Geometry.h>
#endif

#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif

#ifndef E3dTextureMapperDEF
#define E3dTextureMapperDEF  1
typedef struct E3dTextureMapper_S   E3dTextureMapper;
typedef struct E3dTextureMapper_S*  E3dTextureMapperPtr;
EList_t(E3dTextureMapperPtr);
EListA_t(E3dTextureMapperPtr);
#endif

typedef struct
{
	EListA_s(, uint8_t,  VertexArray);             // GPU vertex array, used for drawing PointSet points, Mesh Vertices, Edges etc.
	EIndex               VertexArrayStride;

// If there are selected Vertices, these arrays will be non-NULL, so we can draw selected Vertices differently (e.g. bigger and with a different color)
	unsigned int*  UnselectedVertexIndices;EIndex  NUnselectedVertices;
	unsigned int*  SelectedVertexIndices;EIndex  NSelectedVertices;

	EList_s(, EResource,  VertexAttributes);       // Custom Vertex attributes available to GPU shaders

// For visualizing VertexAttributes
	EListA_s(, E3dVertexAttributeVisualization, VertexAttributeVisualization);

	E3dGLCoordinate*  TextureMappersFrameVertices;EIndex  NTextureMappersFrameVertices;    // For drawing a frame around a Mesh etc. in a Texture view.
} E3dVertexGeometryGPUData;

// Common base for PointSet, Mesh and Face
//
#define E3dVertexGeometryCore\
	E3dGeometryCore;\
	EListA_s(, E3dVertex, Vertices);\
	EResourceList  VertexAttributes;  /* Vertex attributes. This EResource array specifies the layout of each Vertex in this Mesh. It's completely flexible, including support for custom elements. */\
	E3dVertexSize  VertexSize;\
	EList_s(, E3dTextureMapperPtr, TextureMappers);     /* Textura Mappers. This must match the number of ST sets on the VertexGeometry (PointSet, Face, Mesh etc.).    */\
\
	float          VectorDrawScale;                     /* For drawing normals, tangents etc.     */\
	float          OverlayOpacity;                      /* For drawing VertexAttributes as colors */\
\
	E3dVertexGeometryGPUData*  VertexGeometryGPUData    /* GPU data (vertex buffer etc.). This struct is dynamically allocated, so headless apps can use a binary-compatible libE3D without having to know about GPUs */ 


typedef struct
{
	E3dVertexGeometryCore;
} E3dVertexGeometry;

extern E3dVertexGeometry*  E3dVertexGeometry_CastTo(EObject* PObject);

extern void    E3dVertexGeometry_VerticesFree(E3dVertexGeometry* PVertexGeometry);

extern void    E3dVertexGeometry_TextureMappersCopy(const E3dVertexGeometry* PSrcVertexGeometry, E3dVertexGeometry* PDstVertexGeometry);

extern void    E3dVertexGeometryGPUData_FreeContents(E3dVertexGeometryGPUData* PGPUData);

extern int     E3dVertexGeometry_VertexAttributeClear(E3dVertexGeometry* PVertexGeometry, const EResource* PAttr);


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
}	// Close scope of 'extern "C"' declaration
#endif

#endif	// _E3D_VertexGeometry_h
