# ==============================================================================
# GLAD OpenGL Loader Libraries for Choreonoid
# ==============================================================================
#
# This directory contains OpenGL loader sources generated by GLAD and a custom
# loader for Choreonoid.
#
# ## File Generation (GLAD 2.0.8)
#
#   # Compatibility Profile (OpenGL 4.6)
#   # This includes all Core Profile functions plus fixed-function pipeline.
#   glad --api gl:compatibility=4.6 --out-path ./glad c
#
# ## File Placement
#
#   After generation, place files as follows:
#
#   src/OpenGL/
#   ├── CMakeLists.txt          (this file)
#   ├── gl.c                    <- glad/src/gl.c
#   ├── gl.h                    <- glad/include/glad/gl.h
#   ├── gl_used.c               (custom loader for Choreonoid)
#   └── KHR/
#       └── khrplatform.h       <- glad/include/KHR/khrplatform.h
#
#   include/cnoid/
#   └── gl.h                    (wrapper: #include "../src/OpenGL/gl.h")
#
# ## Modifications to Generated Files
#
#   gl.c:
#     #include <glad/gl.h>  ->  #include "gl.h"
#
#   gl.h:
#     #include <KHR/khrplatform.h>  ->  #include "KHR/khrplatform.h"
#     Add declaration: GLAD_API_CALL int cnoidLoadGL(GLADloadfunc load);
#
# ## Custom Loader (gl_used.c)
#
#   The GLAD-generated gladLoadGL() loads all ~3000 OpenGL function pointers.
#   gl_used.c provides cnoidLoadGL() which loads only the ~125 functions
#   actually used by Choreonoid, significantly reducing initialization overhead.
#
# ## Library Usage
#
#   - CnoidOpenGL: For plugins using OpenGL (both Core and Compatibility Profile)
#   - Use cnoidLoadGL() instead of gladLoadGL() for efficient function loading
#
# ==============================================================================

# Compatibility Profile (OpenGL 4.6)
# gl.c: GLAD-generated file containing function pointer variables
# gl_used.c: Custom loader that loads only the functions used by Choreonoid
choreonoid_add_library(CnoidOpenGL SHARED gl.c gl_used.c HEADERS gl.h)
target_compile_definitions(CnoidOpenGL PRIVATE GLAD_API_CALL_EXPORT GLAD_API_CALL_EXPORT_BUILD)
target_compile_definitions(CnoidOpenGL INTERFACE GLAD_API_CALL_EXPORT)
