//================================================================
// E3D library
//
// - Interactive rendering
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Jan-07 21:46:09
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================
#ifndef _E3D_Draw_h
#define _E3D_Draw_h

#include <Image/GL/EpGL.h>

#include <E3D/GL/E3GL.h>
#include <E3D/GL/Material.h>

extern EBool  E3dGL_DoubleBufferOK, E3dGL_ZBufferOK;


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


//--------------------------------
// GL/SplineDraw.c
//--------------------------------
extern const unsigned int  E3d_FilledPoint_bits[];


//--------------------------------
// GL/FrameBuffer.c
//--------------------------------
extern GLenum              EpGL_CheckFramebufferStatus(const char* PPrefix, const EBool PReportSuccess, const EBool PReportIncompleteDimensions, const EBool PPrint);


//--------------------------------
// GL/Scene.c
//--------------------------------
extern E3dGLCoordinate  E3dp_XYZAxis[][3];

extern void    E3dGL_Init(void);
extern EBool   EpGL_SupportsGL12(void);


//--------------------------------
// GL/Renderers.c
//--------------------------------
extern void    E3dGL_GLRenderersRegister(void);
extern void    E3dGL_GLRenderersUnregister(void);


static inline void E3dGL_TexturesDisable(void)
{
#ifndef EGLES
	EpglDisable(GL_TEXTURE_1D);
	EpglDisable(GL_TEXTURE_2D);
	EpglDisable(GL_TEXTURE_3D);

	EpGPUInfo*  LGPUInfo = &Ep_GPUInfo;
	if(LGPUInfo->Texture_Cubemap) EpglDisable(GL_TEXTURE_CUBE_MAP);

	#ifdef GL_TEXTURE_RECTANGLE
	EpglDisable(GL_TEXTURE_RECTANGLE);
	#endif
#endif // EGLES
}


//--------------------------------
// GL/Window.c
//--------------------------------
extern void  E3dGL_CheckGlobals(void);

extern void  _E3dOpenGLRenderer_GUI(ECoreObject* PObject, XeInfoPanel* PPanel, void* PDrawer, const int PAction);
extern void  _E3dGLSolid_GUI(ECoreObject* PObject, XeInfoPanel* PPanel, void* PDrawer, const int PAction);
extern void  _E3dGLShadedSolid_GUI(ECoreObject* PObject, XeInfoPanel* PPanel, void* PDrawer, const int PAction);

static inline GLenum E3dBlendFactor_ToGL(const int PFactor)
{
	switch(PFactor)
	{
		case E3dBlendZERO:                 return(GL_ZERO);
		case E3dBlendONE:                  return(GL_ONE);
		case E3dBlendSRC_ALPHA:            return(GL_SRC_ALPHA);
		case E3dBlendONE_MINUS_SRC_ALPHA:  return(GL_ONE_MINUS_SRC_ALPHA);
		default:  return(GL_ZERO);
	}
}



#ifdef EGLES
	#define E3dGL_SetColorRGBAf_s(p)             glUniform4f(LGLShader->Param_FgU_Color,  (p).R, (p).G, (p).B, (p).A)
	#define E3dGL_SetColorRGBAf_p(p)             glUniform4f(LGLShader->Param_FgU_Color,  (p)->R, (p)->G, (p)->B, (p)->A)
	#define E3dGL_SetColorRGBAf_a(p)             glUniform4fv(LGLShader->Param_FgU_Color, 1,  p)
	#define E3dGL_SetColorRGBAf(pR, pG, pB, pA)  glUniform4f(LGLShader->Param_FgU_Color,  pR, pG, pB, pA)
	#define E3dGL_SetColorRGBAp8(c)              glUniform4ui(LGLShader->Param_FgU_Color,  EcM_R_RGBAp8(c), EcM_G_RGBAp8(c), EcM_B_RGBAp8(c), EcM_A_RGBAp8(c))
#else
	#define E3dGL_SetColorRGBAf_s(p)             EcM_glColorRGBAf_s(p)
	#define E3dGL_SetColorRGBAf_p(p)             EcM_glColorRGBAf_p(p)
	#define E3dGL_SetColorRGBAf_a(p)             EcM_glColorRGBAf_a(p)
	#define E3dGL_SetColorRGBAf(pR, pG, pB, pA)  EpglColor4f(pR, pG, pB, pA)
	#define E3dGL_SetColorRGBAp8(c)              EpglColor4ub(EcM_R_RGBAp8(c), EcM_G_RGBAp8(c), EcM_B_RGBAp8(c), EcM_A_RGBAp8(c))
#endif


extern void  E3dGL_CameraPickMatrix(const E3dCoordinate PX, const E3dCoordinate PY,  const E3dCoordinate PSizeX, const E3dCoordinate PSizeY,  const GLint PViewPort[4]);

// Post effects
//
extern const int  E3dGL_BloomFilterType;

extern E3dGLCoreShader*  E3dGL_ConstColorDrawPrep(E3dGPUContext* PGPUContext,  const EcRGBAf32Color* PColor);

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

#endif	// _E3D_Draw_h
